Introduction
This is the Python binding for msd. msd is a high-performance financial time series database.
It provides a native Rust client MsdConnection, which handles streaming binary table frames directly via Tokio and Reqwest with zero-copy NumPy conversion, native joins, snapshots, and fast data imports.
Installation
pip install pymsd
Native Client: MsdConnection
MsdConnection is implemented in Rust. It eliminates Python HTTP overhead, streams and parses binary table frames natively, and returns lightweight Table objects with zero-copy conversion to NumPy ndarrays.
import pymsd
# Initialize connection (supports optional bearer token and zstd compression)
conn = pymsd.MsdConnection("http://localhost:50510", token="", compress=True)
Table Representation
Queries through MsdConnection return native Table instances:
- Metadata:
table.name,table.obj,table.rows,table.columns,table.header. - Cell access:
table[row, col]returns typed Python values. - Zero-copy export to NumPy (transfers memory buffer and resets the
Tableinstance):table.to_dict(): returns{column_name: np.ndarray}table.to_list(): returns[(column_name, np.ndarray), ...]- Convert directly to pandas or polars DataFrames:
import pandas as pd import polars as pl df_pd = pd.DataFrame(table.to_dict()) df_pl = pl.DataFrame(table.to_dict())
Querying Data
1. Grouped Query (query)
Executes SQL queries and groups the results into a 2-level dictionary: {obj: {table_name: Table}}.
sql = "SELECT * FROM kline WHERE obj = 'SH600000' LIMIT -100;"
results = conn.query(sql)
for obj, tables in results.items():
for table_name, table in tables.items():
print(obj, table_name, table.rows, table.columns)
2. Streaming Query with Callback (query_map)
Streams each table frame progressively as it arrives from the server and invokes a callback handler. This keeps memory usage minimal when processing large query result sets.
def on_table(table: pymsd.Table):
print(f"Received table: {table.obj}.{table.name} with {table.rows} rows")
conn.query_map("SELECT * FROM kline WHERE obj IN ('SH600000', 'SZ000001');", on_table)
3. Native As-Of Join (query_join)
Aligns and joins multiple time-series tables across multiple objects directly in Rust.
sql = """
SELECT * FROM stock_kline_1d WHERE obj = 'SH600*' LIMIT -1000;
SELECT * FROM stock_shares WHERE obj = 'SH600*';
"""
# Aligns stock_shares to stock_kline_1d using backward fill, based on SH600000 timeline
table, objs, bars = conn.query_join(
sql=sql,
base_table="stock_kline_1d",
fill={"stock_shares": "backward", "*": "nan"},
base_obj="SH600000",
)
print(f"Joined {len(objs)} objects, each {bars} rows. Total rows: {table.rows}")
4. Multi-Table Snapshot (snapshot)
Takes the latest snapshot across multiple tables for a set of objects and joins them by object into a single table.
Supports:
- Objects: single code (
'SH600000'), wildcard pattern ('SH600*'), or block lookup ('@stock_block:全部A股'). - Field selection:
'table_name: field1, field2'. - Timestamp feature filtering:
'table_name@ts.month=12: field1, field2'.
table = conn.snapshot(
tables=[
"stock_kline_1d",
"stock_shares: total_shares",
"stock_capital_flow",
"stock_financial@ts.month=12: f001, f002", # only take the annal report
],
objects=["@stock_block:全部A股"],
)
print("Snapshot shape:", table.rows, table.columns)
Importing Data
MsdConnection provides high-throughput data import methods.
1. Import CSV (import_csv)
Import CSV data from raw bytes, a file path (str or Path), or a binary file-like stream object.
# From file path or Path object
res = conn.import_csv("my_table", "data.csv", header=True, delimiter=",")
# From file-like object with .read()
with open("data.csv", "rb") as f:
res = conn.import_csv("my_table", f, header=True)
print("Import result:", res)
2. Import Table Frame (import_table)
Import native Table Frame binary format from a Table instance, raw bytes, a file path, or a binary file-like stream object.
# Import from an existing Table instance
res = conn.import_table("target_table", table)
# Import from a .tbl file
res = conn.import_table("target_table", "data.tbl")
3. Import DataFrames (import_dataframes / import_dataframe)
Stream pandas or polars DataFrames into msd:
import pandas as pd
df = pd.DataFrame({
"ts": [1700000000000000, 1700000060000000],
"close": [10.5, 10.8],
})
# Supports a single (obj, df) tuple, list/iterator of (obj, df), or pre-packed bytes
data = ("SH600000", df)
res = conn.import_dataframes("stock_kline", data, decimal_fields={"close": 2})
Performance
For a test node, MsdConnection can query about 7.4M rows across 1846 different symbols in under 1 second. See test_query.py for more details.
Metadata
Release files for pymsd 0.1.29
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymsd-0.1.29-cp312-abi3-win_amd64.whl | CPython 3.12 | abi3 | Windows x86-64 | Details for pymsd-0.1.29-cp312-abi3-win_amd64.whl |
| pymsd-0.1.29-cp312-abi3-manylinux_2_34_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.34+ x86-64 | Details for pymsd-0.1.29-cp312-abi3-manylinux_2_34_x86_64.whl |
| pymsd-0.1.29-cp312-abi3-macosx_11_0_arm64.whl | CPython 3.12 | abi3 | macOS 11.0+ ARM64 | Details for pymsd-0.1.29-cp312-abi3-macosx_11_0_arm64.whl |
Total release size: 10.9 MB
Release files / pymsd-0.1.29-cp312-abi3-win_amd64.whl
| Download URL | pymsd-0.1.29-cp312-abi3-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.12 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
200fbbea4413ef3db05cf3c62334ed0edb679140dbe43a32fcecb47d765bf8d5
|
|
BLAKE2b-256 checksum How to use checksums |
ea69032209e7fb13104b2c5d8ecfcb0aa04b46d3a733a49c7bba4e75c64178a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / pymsd-0.1.29-cp312-abi3-manylinux_2_34_x86_64.whl
| Download URL | pymsd-0.1.29-cp312-abi3-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
fa098ca2374c69070fa0b9fd29785660c0ec11796ffa118e5bb16e260612fa61
|
|
BLAKE2b-256 checksum How to use checksums |
fb7be1c105f35232f06141109627e28e202de085bdfe6e75c77be645f09edad6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / pymsd-0.1.29-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | pymsd-0.1.29-cp312-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.12 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
51e5d24134e2e03d1e0428d5528f9bdd9a7c226d5ce88103d77451e322c66929
|
|
BLAKE2b-256 checksum How to use checksums |
05f07405fad2aed632cc96fa546d19b9112a53679a2e04e0383bc7857cf32f11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logSecurity for pymsd 0.1.29
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 3 files in this release have been uploaded with provenance metadata.
Attestation for pymsd-0.1.29-cp312-abi3-win_amd64.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.