### Chain Methods for Readable Rayforce-Py Queries Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/query-guide/overview.md Illustrates the best practice of chaining multiple methods in Rayforce-Py for creating readable and maintainable queries. This example chains `.select()` and two `.where()` clauses before execution. ```python >>> result = ( table.select("id", "name", "salary") .where(Column("age") >= 30) .where(Column("dept") == "eng") .execute() ) ``` -------------------------------- ### Install Rayforce-Py using pip Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/get-started/overview.md This command shows the recommended way to install the Rayforce-Py library using pip. It also lists alternative installation commands using aliases for the package. ```bash python -m pip install rayforce-py # OR use available aliases: python -m pip install rayforce python -m pip install rayforcedb ``` -------------------------------- ### Execute Rayforce-Py Queries Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/query-guide/overview.md Demonstrates how to build and execute queries using the Rayforce-Py API. Queries are lazy by default and require a `.execute()` call to retrieve results. This example shows a basic selection and filtering operation. ```python >>> query = table.select("id", "name").where(Column("age") >= 35) >>> result = query.execute() ``` -------------------------------- ### RayforceDB Command-Line Interface Example Source: https://github.com/rayforcedb/rayforce-py/blob/master/README.md Illustrates the usage of the RayforceDB command-line interface (CLI) after installation. The CLI provides a way to interact with the Rayforce runtime directly from the terminal, showing version information and basic arithmetic operations. ```clojure ~ $ rayforce Launching Rayforce... RayforceDB: 0.1 Dec 6 2025 Documentation: https://rayforcedb.com/ Github: https://github.com/RayforceDB/rayforce ↪ (+ 1 2) 3 ``` -------------------------------- ### Install Rayforce-Py from Source Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/get-started/overview.md This section provides instructions for installing Rayforce-Py by cloning the GitHub repository and building it from source. It includes commands for cloning, navigating to the directory, and running the 'make app' command to build the project and its dependencies. ```bash ~ $ git clone https://github.com/RayforceDB/rayforce-py.git ~ $ cd rayforce-py ~/rayforce-py $ make app # 1. Pulls the latest Rayforce from GitHub # 2. Builds the Rayforce and it's plugins # 3. Moves binaries around so they become available to the library ~/rayforce-py $ python -c "import rayforce; print(rayforce.version)" 0.1.3 ``` -------------------------------- ### Python ORM Query Example with RayforceDB Source: https://github.com/rayforcedb/rayforce-py/blob/master/README.md Demonstrates how to define a table from a dictionary, perform complex aggregations and filtering using a chainable query syntax, and execute the query against RayforceDB. This example showcases select, where, and by clauses for data manipulation. ```python from datetime import time from rayforce import Table, Vector, Symbol, Time, F64 from rayforce.types.table import Column quotes = Table.from_dict({ "symbol": Vector(items=["AAPL", "AAPL", "AAPL", "GOOG", "GOOG", "GOOG"], ray_type=Symbol), "time": Vector( items=[ time.fromisoformat("09:00:00.095"), time.fromisoformat("09:00:00.105"), time.fromisoformat("09:00:00.295"), time.fromisoformat("09:00:00.145"), time.fromisoformat("09:00:00.155"), time.fromisoformat("09:00:00.345"), ], ray_type=Time, ), "bid": Vector(items=[100.0, 101.0, 102.0, 200.0, 201.0, 202.0], ray_type=F64), "ask": Vector(items=[110.0, 111.0, 112.0, 210.0, 211.0, 212.0], ray_type=F64), }) result = ( quotes .select( max_bid=Column("bid").max(), min_bid=Column("bid").min(), avg_ask=Column("ask").mean(), records_count=Column("time").count(), first_time=Column("time").first(), ) .where((Column("bid") >= 110) & (Column("ask") > 100)) .by("symbol") .execute() ) print(result) ``` -------------------------------- ### Complex Conditions in Rayforce-Py Queries Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/query-guide/overview.md Shows how to construct complex conditions in Rayforce-Py queries using boolean operators like '&' (AND). This example filters results based on both age and salary criteria. ```python >>> result = table.select("id", "name", "salary").where( (Column("age") >= 30) & (Column("salary") > 100000) ).execute() ``` -------------------------------- ### Perform Left Join on Multiple Columns using Rayforce-Py Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/query-guide/joins.md This code example shows how to perform a left join on multiple columns in Rayforce-Py. By providing a list of column names to the `on` parameter, you can specify multiple keys for the join operation. The `rayforce` library is required. ```python >>> result = trades.left_join(quotes, on=["col1", "col2"]).execute() ``` -------------------------------- ### Create Table from Dictionary in Python Source: https://context7.com/rayforcedb/rayforce-py/llms.txt Demonstrates how to create a RayforceDB table from a Python dictionary. It emphasizes the use of strongly-typed Vectors for columns, ensuring type safety and performance. The example also shows how to access table structures and specific rows or columns. ```python from datetime import time from rayforce import Table, Vector, Symbol, Time, F64 # Create a financial quotes table with typed columns quotes = Table.from_dict({ "symbol": Vector(items=["AAPL", "AAPL", "AAPL", "GOOG", "GOOG", "GOOG"], ray_type=Symbol), "time": Vector( items=[ time.fromisoformat("09:00:00.095"), time.fromisoformat("09:00:00.105"), time.fromisoformat("09:00:00.295"), time.fromisoformat("09:00:00.145"), time.fromisoformat("09:00:00.155"), time.fromisoformat("09:00:00.345"), ], ray_type=Time, ), "bid": Vector(items=[100.0, 101.0, 102.0, 200.0, 201.0, 202.0], ray_type=F64), "ask": Vector(items=[110.0, 111.0, 112.0, 210.0, 211.0, 212.0], ray_type=F64), }) # Access table structure print(quotes.columns()) # Vector['symbol', 'time', 'bid', 'ask'] print(quotes.at_column("bid")) # Vector[100.0, 101.0, 102.0, 200.0, 201.0, 202.0] print(quotes.at_row(0)) # Dict{'symbol': 'AAPL', 'time': 09:00:00.095, ...} ``` -------------------------------- ### Computed Columns in Rayforce-Py Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/query-guide/overview.md Demonstrates the creation of computed columns in Rayforce-Py queries. This allows deriving new data fields on the fly, such as a 'total' price, without altering the original table. ```python >>> result = table.select( "id", "price", "quantity", total=Column("price") * Column("quantity"), ).execute() ``` -------------------------------- ### Install Rayforce-Py Python Package Source: https://github.com/rayforcedb/rayforce-py/blob/master/README.md Provides instructions on how to install the rayforce-py package using pip. This command installs the Python ORM library, enabling interaction with RayforceDB from Python applications. ```bash pip install rayforce-py ``` -------------------------------- ### Inplace Table Update in Rayforce-Py Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/FAQ.md Demonstrates an 'inplace' operation where a table object is modified directly in memory. This involves creating a table, updating a specific column based on a condition, and executing the operation. The example uses `Table.from_dict()`, `Vector`, `Symbol`, `I64`, `Column`, and `execute()`. ```python from rayforce import Table, Vector, Symbol, I64, Column # Create an in-memory table table = Table.from_dict({ "id": Vector(items=["001", "002", "003"], ray_type=Symbol), "name": Vector(items=["alice", "bob", "charlie"], ray_type=Symbol), "age": Vector(items=[29, 34, 41], ray_type=I64), }) # Inplace operation - works directly on the table object result = table.update(age=100).where(Column("id") == "001").execute() result.values()[2][0].value # age updated to 100 ``` -------------------------------- ### Initialize and Access GUID from Various Types - Python Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/data-types/guid.md Demonstrates how to initialize the GUID type from Python's uuid.UUID, string, and bytes. It also shows how to access the underlying UUID value using the .value property. No external dependencies beyond the standard `uuid` library are required. ```python >>> from uuid import uuid4 >>> from rayforce import GUID >>> guid = GUID(uuid4()) # from uuid.UUID value >>> guid GUID(UUID('724f8738-2482-4bb8-aa62-f0e682a58a91')) >>> guid = GUID("724f8738-2482-4bb8-aa62-f0e682a58a91") # from Python string >>> guid GUID(UUID('724f8738-2482-4bb8-aa62-f0e682a58a91')) >>> guid = GUID(uuid4().bytes) # from bytes >>> guid GUID(UUID('6c099338-840d-4f50-beb5-ab39267e87ab')) >>> guid.value UUID('6c099338-840d-4f50-beb5-ab39267e87ab') ``` -------------------------------- ### Load Table from CSV in Python Source: https://context7.com/rayforcedb/rayforce-py/llms.txt Illustrates loading data into a RayforceDB table directly from a CSV file. This method supports automatic type inference and allows for explicit definition of column types, ensuring data integrity during import. The example includes a sample CSV format. ```python from rayforce import Table, Symbol, F64, I64, Timestamp # Define column types for CSV import column_types = [Symbol, Timestamp, F64, I64] # Load CSV with specified types trades = Table.from_csv( column_types=column_types, path="/data/market_trades.csv" ) # CSV format example: # symbol,timestamp,price,volume # AAPL,2024-01-15T09:30:00,150.25,1000 # GOOG,2024-01-15T09:30:01,2800.50,500 ``` -------------------------------- ### Install Rayforce-Py with Polars Integration Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/plugins/polars.md Install the rayforce-py package with optional Polars integration using pip. This command fetches and installs the necessary dependencies for using Polars DataFrames with Rayforce-Py. ```bash pip install rayforce-py[polars] ``` -------------------------------- ### Initialize KDBEngine in Python Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/plugins/kdb.md Initializes a KDBEngine instance to establish a connection with a KDB database. It requires the host and port of the KDB instance and manages a pool of connections. ```python from rayforce.plugins.raykx import KDBEngine engine = KDBEngine(host="localhost", port=5050) print(engine) ``` -------------------------------- ### Create and Print Rayforce Py Table Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/data-types/table/overview.md Demonstrates how to create a structured data table using the `Table` type in Rayforce Py. It shows the initialization of columns and values using Vectors, conversion to a Table from a dictionary, and printing the table to display its contents. This process requires the `Table`, `I64`, `Symbol`, and `Vector` classes from the `rayforce` library. ```python >>> from rayforce import Table, I64, Symbol, Vector >>> columns = ["id", "name", "age", "salary"] >>> values = [ Vector([1, 2, 3, 4, 5], ray_type=I64), # id column Vector(["Alice", "Bob", "Charlie", "Diana", "Eve"], ray_type=Symbol), # name column Vector([25, 30, 35, 28, 32], ray_type=I64), # age column Vector([50000, 60000, 70000, 55000, 65000], ray_type=I64), # salary column ] >>> employee_table = Table.from_dict(dict(zip(columns, values))) >>> employee_table Table(columns=['id', 'name', 'age', 'salary']) >>> print(employee_table) ┌────┬─────────┬─────┬─────────────────┐ │ id │ name │ age │ salary │ ├────┼─────────┼─────┼─────────────────┤ │ 1 │ Alice │ 25 │ 50000 │ │ 2 │ Bob │ 30 │ 60000 │ │ 3 │ Charlie │ 35 │ 70000 │ │ 4 │ Diana │ 28 │ 55000 │ │ 5 │ Eve │ 32 │ 65000 │ ├────┴─────────┴─────┴─────────────────┤ │ 5 rows (5 shown) 4 columns (4 shown) │ └──────────────────────────────────────┘ ``` -------------------------------- ### Running Rayforce-Py Benchmarks (Bash) Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/get-started/benchmarks.md Commands to execute the benchmark suite for Rayforce-Py. Includes default settings and custom configuration for runs and warmup periods. Ensure sufficient runs for statistical significance. ```bash # Default (15 runs, 5 warmup) make benchmarkdb # Custom configuration make benchmarkdb ARGS="--runs 20 --warmup 5" ``` -------------------------------- ### Install Rayforce-Py with Pandas Support Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/plugins/pandas.md Install the pandas integration for Rayforce-Py as an optional dependency. This command adds the necessary packages to enable DataFrame conversion. ```bash pip install rayforce-py[pandas] ``` -------------------------------- ### Initialize and Render Performance Charts (JavaScript) Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/get-started/benchmarks.md This snippet initializes ECharts instances for performance visualization. It sets up chart configurations including titles, tooltips, legends, axes, and series data. The code also includes event listeners for window resizing and DOM mutation to dynamically update or re-render charts, ensuring responsiveness and theme consistency. ```javascript var chartInstances = {}; function initAllCharts() { // Q6: Group by id3, max(v1) - min(v2) var q6Chart = echarts.init(document.getElementById('q6-chart'), null, { renderer: 'svg', width: document.getElementById('q6-chart').offsetWidth, height: document.getElementById('q6-chart').offsetHeight }); q6Chart.setOption({ title: { text: 'Q6: Group by id3, max(v1) - min(v2)', left: 'center', textStyle: { fontSize: 16, fontWeight: 'bold', color: theme.textColor } }, tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: function(params) { return params[0].name + '
' + params[0].seriesName + ': ' + params[0].value + ' μs'; }, textStyle: { color: theme.textColor }, backgroundColor: theme.isDark ? 'rgba(26, 26, 26, 0.9)' : 'rgba(255, 255, 255, 0.9)', borderColor: theme.gridLineColor }, legend: { top: 30, data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], textStyle: { color: theme.textColor } }, grid: { left: '3%', right: '4%', bottom: '3%', top: 80, containLabel: true }, xAxis: { type: 'category', data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], axisLabel: { rotate: 0, color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } } }, yAxis: { type: 'value', name: 'Time (μs)', nameLocation: 'middle', nameGap: 50, nameTextStyle: { color: theme.textColor }, axisLabel: { color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } }, splitLine: { lineStyle: { color: theme.gridLineColor } } }, series: [{ name: 'Time (μs)', type: 'bar', data: [ { value: 967, itemStyle: { color: '#E9A320' } }, { value: 971, itemStyle: { color: '#1B365D' } }, { value: 3339, itemStyle: { color: '#718096' } }, { value: 4802, itemStyle: { color: '#718096' } } ], label: { show: true, position: 'top', color: theme.textColor } }] }); chartInstances['q6-chart'] = q6Chart; // Resize handler window.addEventListener('resize', function() { Object.values(chartInstances).forEach(function(chart) { chart.resize(); }); }); } // Initialize on DOM ready document.addEventListener('DOMContentLoaded', function() { // Wait for theme to be applied - use requestAnimationFrame to ensure DOM is ready requestAnimationFrame(function() { setTimeout(initAllCharts, 200); }); }); // Watch for theme changes var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === 'attributes' && mutation.attributeName === 'data-md-color-scheme') { // Reinitialize all charts with new theme Object.keys(chartInstances).forEach(function(chartId) { chartInstances[chartId].dispose(); }); chartInstances = {}; setTimeout(initAllCharts, 50); } }); }); document.addEventListener('DOMContentLoaded', function() { observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-md-color-scheme'] }); }); ``` -------------------------------- ### Save and Fetch Table Data in Python Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/data-types/table/save-and-fetch.md This Python snippet demonstrates how to save a table to a Rayforce environment variable and then fetch it. It shows saving a table, retrieving it by name, inspecting its columns, fetching its values, and executing select statements. ```python >>> table: Table >>> table.save("mytable") >>> Table.from_name("mytable") TableReference['mytable'] # This is unfeched prepared state, and table has to be selected from database >>> Table.from_name("mytable").columns() Vector([Symbol('symbol'), Symbol('time'), Symbol('bid'), Symbol('ask')]) >>> Table.from_name("mytable").values() List([Vector ...]) # collapsed in documentation for convenience >>> Table.from_name("mytable").select("*").execute() Table[Symbol('symbol'), Symbol('time'), Symbol('bid'), Symbol('ask')] >>> Table.from_name("test").select("time").execute() Table[Symbol('time')] ``` -------------------------------- ### IPC Engine and Remote Connections Source: https://context7.com/rayforcedb/rayforce-py/llms.txt Shows how to establish and manage connections to remote RayforceDB instances using the IPCEngine. Covers executing queries both as strings and query objects, error handling, and connection pool monitoring. ```python from rayforce import IPCEngine, IPCConnection, IPCError, Table, Column # Create IPC engine for remote host engine = IPCEngine(host="localhost", port=5000) # Acquire connection from pool try: with engine.acquire() as conn: # Execute string query result = conn.execute("select sum[price] by symbol from trades") # Execute query objects query = ( Table.from_name("trades") .select( total_volume=Column("volume").sum(), avg_price=Column("price").mean() ) .by("symbol") ) result = conn.execute(query) except IPCError as e: print(f"IPC connection failed: {e}") # Manual connection management conn = engine.acquire() result = conn.execute("select * from quotes") conn.close() # Monitor connection pool print(engine) # IPCEngine(host=localhost, port=5000, pool_size: 2) # Clean up all connections engine.dispose_connections() ``` -------------------------------- ### Create and Initialize Rayforce Python Vector Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/data-types/vector.md Demonstrates how to create Vector objects with specified Ray types and either a length or initial items. Vectors ensure all elements are of the same type, otherwise a List is used. ```python >>> from rayforce import Vector, I64, Symbol >>> int_vector = Vector(ray_type=I64, length=3) >>> int_vector Vector(5) # 5 represents a type code of I64 >>> symbol_vector = Vector(ray_type=Symbol, items=["apple", "banana", "cherry"]) >>> symbol_vector Vector(5) # 6 represents a type code of Symbol >>> timestamp_vector = Vector( ray_type=Timestamp, items=[ "2025-05-10T14:30:45+00:00", "2025-05-10T14:30:45+00:00", "2025-05-10T14:30:45+00:00", ] ) ``` -------------------------------- ### Filtered Aggregations in Rayforce-Py Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/query-guide/overview.md Explains how to perform filtered aggregations in Rayforce-Py using the `.by()` clause combined with `.where()` on columns. This enables calculating conditional statistics, like the sum of high earners per department. ```python >>> result = ( table .select( total=Column("salary").sum(), high_earners=Column("salary").where(Column("salary") > 100000).sum(), ) .by("dept") .execute() ) ``` -------------------------------- ### Python: Basic Filtering with Comparison Operators Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/query-guide/select.md Demonstrates how to filter a table based on standard comparison operators applied to a column. This requires selecting columns first, then applying a where clause with a column comparison, and finally executing the query. Supports operators like ==, !=, >, >=, <, <=. ```python >>> result = table.select("id", "name", "age").where(Column("age") >= 35).execute() ``` -------------------------------- ### Configure ECharts Bar Chart for Performance Data (JavaScript) Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/get-started/benchmarks.md This JavaScript code configures an ECharts bar chart to visualize performance data. It includes setup for tooltips, legends, axes, and series, with data points representing execution times in microseconds for different libraries. ```javascript var q3Chart = echarts.init(document.getElementById('q3-chart')); q3Chart.setOption({ tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: function(params) { return params[0].name + '
' + params[0].seriesName + ': ' + params[0].value + ' μs'; }, textStyle: { color: theme.textColor }, backgroundColor: theme.isDark ? 'rgba(26, 26, 26, 0.9)' : 'rgba(255, 255, 255, 0.9)', borderColor: theme.gridLineColor }, legend: { top: 30, data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], textStyle: { color: theme.textColor } }, grid: { left: '3%', right: '4%', bottom: '3%', top: 80, containLabel: true }, xAxis: { type: 'category', data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], axisLabel: { rotate: 0, color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } } }, yAxis: { type: 'value', name: 'Time (μs)', nameLocation: 'middle', nameGap: 50, nameTextStyle: { color: theme.textColor }, axisLabel: { color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } }, splitLine: { lineStyle: { color: theme.gridLineColor } } }, series: [{ name: 'Time (μs)', type: 'bar', data: [ { value: 956, itemStyle: { color: '#E9A320' } }, { value: 974, itemStyle: { color: '#1B365D' } }, { value: 1376, itemStyle: { color: '#718096' } }, { value: 4902, itemStyle: { color: '#718096' } } ], label: { show: true, position: 'top', color: theme.textColor } }] }); chartInstances['q3-chart'] = q3Chart; // Q4 Chart var q4Chart = echarts.init(document.getElementById('q4-chart')); q4Chart.setOption({ title: { text: 'Q4: Group by id3, avg v1, v2, v3', left: 'center', textStyle: { fontSize: 16, fontWeight: 'bold', color: theme.textColor } }, tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: function(params) { return params[0].name + '
' + params[0].seriesName + ': ' + params[0].value + ' μs'; }, textStyle: { color: theme.textColor }, backgroundColor: theme.isDark ? 'rgba(26, 26, 26, 0.9)' : 'rgba(255, 255, 255, 0.9)', borderColor: theme.gridLineColor }, legend: { top: 30, data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], textStyle: { color: theme.textColor } }, grid: { left: '3%', right: '4%', bottom: '3%', top: 80, containLabel: true }, xAxis: { type: 'category', data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], axisLabel: { rotate: 0, color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } } }, yAxis: { type: 'value', name: 'Time (μs)', nameLocation: 'middle', nameGap: 50, nameTextStyle: { color: theme.textColor }, axisLabel: { color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } }, splitLine: { lineStyle: { color: theme.gridLineColor } } }, series: [{ name: 'Time (μs)', type: 'bar', data: [ { value: 1182, itemStyle: { color: '#E9A320' } }, { value: 1182, itemStyle: { color: '#1B365D' } }, { value: 1594, itemStyle: { color: '#718096' } }, { value: 6161, itemStyle: { color: '#718096' } } ], label: { show: true, position: 'top', color: theme.textColor } }] }); chartInstances['q4-chart'] = q4Chart; // Q5 Chart var q5Chart = echarts.init(document.getElementById('q5-chart')); q5Chart.setOption({ title: { text: 'Q5: Group by id3, sum v1, v2, v3', left: 'center', textStyle: { fontSize: 16, fontWeight: 'bold', color: theme.textColor } }, tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: function(params) { return params[0].name + '
' + params[0].seriesName + ': ' + params[0].value + ' μs'; }, textStyle: { color: theme.textColor }, backgroundColor: theme.isDark ? 'rgba(26, 26, 26, 0.9)' : 'rgba(255, 255, 255, 0.9)', borderColor: theme.gridLineColor }, legend: { top: 30, data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], textStyle: { color: theme.textColor } }, grid: { left: '3%', right: '4%', bottom: '3%', top: 80, containLabel: true }, xAxis: { type: 'category', data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], axisLabel: { rotate: 0, color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } } }, yAxis: { type: 'value', name: 'Time (μs)', nameLocation: 'middle', nameGap: 50, nameTextStyle: { color: theme.textColor }, axisLabel: { color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } }, splitLine: { lineStyle: { color: theme.gridLineColor } } }, series: [{ name: 'Time (μs)', type: 'bar', data: [ { value: 1153, itemStyle: { color: '#E9A320' } }, { value: 1164, itemStyle: { color: '#1B365D' } }, { value: 1551, itemStyle: { color: '#718096' } }, { value: 6908, itemStyle: { color: '#718096' } } ], label: { show: true, position: 'top', color: theme.textColor } }] }); chartInstances['q5-chart'] = q5Chart; // Q6 Chart var q6Chart = echarts.init(document.getElementById('q6-chart')); q6Chart.setOption({ ``` -------------------------------- ### Execute Select Query on Rayforce Table in Python Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/overview.md Shows how to perform a select query on a Rayforce Table using chainable Python syntax. It demonstrates aggregation functions like `max()`, `min()`, `mean()`, `count()`, and `first()` applied to specific columns, grouped by another column. The result is then printed. ```python from rayforce import Column result = ( quotes .select( max_bid=Column("bid").max(), min_bid=Column("bid").min(), avg_ask=Column("ask").mean(), records_count=Column("time").count(), first_bid=Column("time").first(), ) .by("symbol") .execute() ) print(result) ``` -------------------------------- ### JavaScript ECharts Configuration for Performance Charts Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/get-started/benchmarks.md Configures ECharts instances to display performance benchmark data. It includes theme detection, data formatting, and chart options for titles, tooltips, legends, axes, and series. The script handles chart initialization and updates based on the detected color scheme. ```javascript var chartInstances = {}; function rgbToHex(rgb) { if (!rgb) return ''; if (rgb.startsWith('#')) return rgb; var match = rgb.match(/rgb((\d+),\s*(\d+),\s*(\d+)\)/); if (match) { var r = parseInt(match[1]).toString(16).padStart(2, '0'); var g = parseInt(match[2]).toString(16).padStart(2, '0'); var b = parseInt(match[3]).toString(16).padStart(2, '0'); return '#' + r + g + b; } return rgb; } function getChartTheme() { var textColor = '#888888'; var scheme = document.documentElement.getAttribute('data-md-color-scheme'); var isDark = scheme === 'slate'; return { textColor: textColor, gridLineColor: isDark ? '#4A5568' : '#D0D0D0', isDark: isDark }; } function initAllCharts() { var theme = getChartTheme(); var q1Chart = echarts.init(document.getElementById('q1-chart')); q1Chart.setOption({ title: { text: 'Q1: Group by id1, sum v1', left: 'center', textStyle: { fontSize: 16, fontWeight: 'bold', color: theme.textColor } }, tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: function(params) { return params[0].name + '
' + params[0].seriesName + ': ' + params[0].value + ' μs'; }, textStyle: { color: theme.textColor }, backgroundColor: theme.isDark ? 'rgba(26, 26, 26, 0.9)' : 'rgba(255, 255, 255, 0.9)', borderColor: theme.gridLineColor }, legend: { top: 30, data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], textStyle: { color: theme.textColor } }, grid: { left: '3%', right: '4%', bottom: '3%', top: 80, containLabel: true }, xAxis: { type: 'category', data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], axisLabel: { textStyle: { color: theme.textColor } } }, yAxis: { type: 'value', name: 'Time (μs)', nameLocation: 'middle', nameGap: 50, nameTextStyle: { color: theme.textColor }, axisLabel: { textStyle: { color: theme.textColor } }, splitLine: { lineStyle: { color: theme.gridLineColor } } }, series: [{ name: 'Time (μs)', type: 'bar', data: [ { value: 741, itemStyle: { color: '#E9A320' } }, { value: 761, itemStyle: { color: '#1B365D' } }, { value: 1143, itemStyle: { color: '#718096' } }, { value: 3663, itemStyle: { color: '#718096' } } ], label: { show: true, position: 'top', textStyle: { color: theme.textColor, fontWeight: 'bold' } } }] }); chartInstances['q1-chart'] = q1Chart; var q2Chart = echarts.init(document.getElementById('q2-chart')); q2Chart.setOption({ title: { text: 'Q2: Group by id1, id2, sum v1', left: 'center', textStyle: { fontSize: 16, fontWeight: 'bold', color: theme.textColor } }, tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, formatter: function(params) { return params[0].name + '
' + params[0].seriesName + ': ' + params[0].value + ' μs'; }, textStyle: { color: theme.textColor }, backgroundColor: theme.isDark ? 'rgba(26, 26, 26, 0.9)' : 'rgba(255, 255, 255, 0.9)', borderColor: theme.gridLineColor }, legend: { top: 30, data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], textStyle: { color: theme.textColor } }, grid: { left: '3%', right: '4%', bottom: '3%', top: 80, containLabel: true }, xAxis: { type: 'category', data: ['Rayforce-Py', 'Native Rayforce', 'Polars', 'Pandas'], axisLabel: { rotate: 0, color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } } }, yAxis: { type: 'value', name: 'Time (μs)', nameLocation: 'middle', nameGap: 50, nameTextStyle: { color: theme.textColor }, axisLabel: { color: theme.textColor }, axisLine: { lineStyle: { color: theme.textColor } }, splitLine: { lineStyle: { color: theme.gridLineColor } } }, series: [{ name: 'Time (μs)', type: 'bar', data: [ { value: 2351, itemStyle: { color: '#E9A320' } }, { value: 2400, itemStyle: { color: '#1B365D' } }, { value: 6763, itemStyle: { color: '#718096' } }, { value: 13675, itemStyle: { color: '#718096' } } ], label: { show: true, position: 'top', color: theme.textColor } }] }); chartInstances['q2-chart'] = q2Chart; var q3Chart = echarts.init(document.getElementById('q3-chart')); q3Chart.setOption({ title: { text: 'Q3: Group by id3, sum v1, avg v3', left: 'center', textStyle: { fontSize: 16, fontWeight: 'bold', color: theme.textColor } }, ``` -------------------------------- ### Save and Load Tables to Disk Source: https://context7.com/rayforcedb/rayforce-py/llms.txt Illustrates how to persist RayforceDB tables to disk using various formats like CSV, splayed (columnar), and parted (partitioned). Covers both saving and loading data, facilitating data exchange and storage. ```python from rayforce import Table, Vector, Symbol, F64, I64 # Create sample table data = Table.from_dict({ "product": Vector(items=["A", "B", "C"], ray_type=Symbol), "price": Vector(items=[10.5, 20.0, 15.75], ray_type=F64), "quantity": Vector(items=[100, 200, 150], ray_type=I64), }) # Save as named table in memory data.save("inventory") # Load from memory loaded = Table.from_name("inventory") # Export to CSV data.set_csv(path="/data/inventory.csv", separator=",") # Import from CSV csv_data = Table.from_csv( column_types=[Symbol, F64, I64], path="/data/inventory.csv" ) # Save as splayed table (columnar format on disk) data.set_splayed(path="/data/splayed/inventory", symlink="inventory.sym") # Load splayed table splayed = Table.from_splayed(path="/data/splayed/inventory", symfile="inventory.sym") # Save as parted table (partitioned storage) data.set_splayed(path="/data/parted/inventory/2024.01.01", symlink="part.sym") # Load parted table parted = Table.from_parted(path="/data/parted/inventory", symfile="part.sym") ``` -------------------------------- ### Get Column Names and Values from Rayforce-Py Table Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/data-types/table/access-values.md This snippet demonstrates how to retrieve all column names and all values from a Rayforce-Py Table. The `columns()` method returns a Vector of column names, while `values()` returns a List of Vectors, where each inner Vector represents the data for a column. It also shows how to iterate through the first record of each column's values. ```python >>> table: Table >>> table.columns() Vector([Symbol('symbol'), Symbol('time'), Symbol('bid'), Symbol('ask')]) >>> table.values() List([ Vector([Symbol('AAPL'), Symbol('AAPL'), Symbol('AAPL'), Symbol('GOOG'), Symbol('GOOG'), Symbol('GOOG')]), Vector([Time(datetime.time(9, 0, 0, 95000)), Time(datetime.time(9, 0, 0, 105000)), Time(datetime.time(9, 0, 0, 295000)), Time(datetime.time(9, 0, 0, 145000)), Time(datetime.time(9, 0, 0, 155000)), Time(datetime.time(9, 0, 0, 345000))]), Vector([F64(100.0), F64(101.0), F64(102.0), F64(200.0), F64(201.0), F64(202.0)]), Vector([F64(110.0), F64(111.0), F64(112.0), F64(210.0), F64(211.0), F64(212.0)]) ]) >>> [column for column in [records[0] for records in table.values()]] [Symbol('AAPL'), Time(datetime.time(9, 0, 0, 95000)), F64(100.0), F64(110.0)] ``` -------------------------------- ### Perform Window Join Source: https://context7.com/rayforcedb/rayforce-py/llms.txt Demonstrates window joins for temporal analysis, allowing joins based on time intervals. This is useful for correlating events that occur within specific time windows. Dependencies include Table, Vector, Column, Symbol, Time, F64, I64, and TableColumnInterval from rayforce, as well as the `time` object from `datetime`. ```python from rayforce import Table, Vector, Column, Symbol, Time, F64, I64, TableColumnInterval from datetime import time # Quotes table quotes = Table.from_dict({ "symbol": Vector(items=["AAPL", "AAPL", "AAPL"], ray_type=Symbol), "time": Vector( items=[time(9, 0, 0), time(9, 0, 5), time(9, 0, 10)], ray_type=Time ), "bid": Vector(items=[100.0, 101.0, 102.0], ray_type=F64), }) # Trades table trades = Table.from_dict({ "symbol": Vector(items=["AAPL", "AAPL"], ray_type=Symbol), "time": Vector(items=[time(9, 0, 3), time(9, 0, 8)], ray_type=Time), "size": Vector(items=[1000, 1500], ray_type=I64), }) # Example of a window join (specific join logic would follow) ``` -------------------------------- ### Create and Use Rayforce Dict Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/data-types/dict.md Demonstrates how to create a Dict object from a Python dictionary, access its keys and values, and perform item assignment. This relies on the `Dict` class from the `rayforce` library. ```python >>> from rayforce import Dict >>> user_data = Dict({ "name": "Alice", "age": 29, "active": True, "score": 95.5, "cache": { "enabled": True, "ttl": 3600 } }) >>> user_data Dict({'name': 'Alice', 'age': 29, 'active': True, 'score': 95.5, 'cache': {'enabled': True, 'ttl': 3600}}) >>> user_data.keys() Vector[6] >>> [i for i in user_data.keys()] [ Symbol('name'), Symbol('age'), Symbol('active'), Symbol('score'), Symbol('cache'), ] >>> user_data.values() List([Symbol('Alice'), I64(29), B8(True), F64(95.5), Dict({'enabled': True, 'ttl': 3600})]) >>> user_data["docs"] = {"is_this_docs": True} # Item assignment >>> user_data Dict({ 'name': 'Alice', 'age': 29, 'active': True, 'score': 95.5, 'cache': {'enabled': True, 'ttl': 3600}, 'docs': {'is_this_docs': True} }) ``` -------------------------------- ### Manage KDB Connection with acquire() in Python Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/plugins/kdb.md Demonstrates manually acquiring and closing a KDB connection using the .acquire() and .close() methods of the KDBEngine. This method requires explicit handling of connection disposal. ```python conn = engine.acquire() print(conn) conn.close() print(conn) ``` -------------------------------- ### Rayforce-Py Object vs RayObject Pointer Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/get-started/technical-details.md Demonstrates the difference between a safe Rayforce-Py object (I64) and a low-level RayObject pointer. RayObject holds memory address information and direct access is not recommended due to potential memory issues. ```python >>> I64(123) I64(123) # This is RayObject, which holds information # about memory address of the underlying Rayforce object, # Not recommended to access and operate with directly, # unless you know what you're doing :) >>> I64(123).ptr <_rayforce_c.RayObject at 0x1095aadb0> ``` -------------------------------- ### Execute Table Query in KDB with Python Source: https://github.com/rayforcedb/rayforce-py/blob/master/docs/docs/content/documentation/plugins/kdb.md Demonstrates executing a complex KDB table query using .execute() with specific filtering and aggregation. It shows how Rayforce-Py handles the results, including printing tabular data. ```python engine = KDBEngine(host="localhost", port=6062) with engine.acquire() as conn: result = conn.execute("0!select sum ExecQty, NotionalValue: sum ExecQty*ExecPrice by Broker, Account from MyTable where date=2025.08.01, Broker in `Bro1`Bro2`Bro3`Bro4") print(result) ```