Skip to main content

substrate-data-client

Python client for Substrate Data: governed SQL, catalog browsing and versioned files. The core depends only on httpx.

pip install substrate-data-client            # httpx only
pip install 'substrate-data-client[arrow]'   # + Polars/Arrow results (the code-interpreter sandbox image uses this)
pip install 'substrate-data-client[http2]'   # + HTTP/2 multiplexing for the async client (used when installed)
import substrate_data_client as sd

df = sd.sql("SELECT zone, count(*) AS trips FROM main.nyc.yellow GROUP BY 1")  # polars.DataFrame  [arrow]
rows = sd.rows("SELECT zone, count(*) AS trips FROM main.nyc.yellow GROUP BY 1")  # JSON rows, no extra
sd.search("taxi")  # find tables and views you may read
sd.describe("main.nyc.yellow")  # columns, partitioning, row count and a sample

Inside a Substrate code-interpreter sandbox the connection is discovered automatically (/run/substrate-data). Elsewhere set SUBSTRATE_DATA_URL and SUBSTRATE_DATA_TOKEN, or build a client. sd.sql, sd.arrow and sd.stream raise an ImportError that names the extra when it is missing.

Clients

from substrate_data_client import DataClient, AsyncDataClient, ClientCredentials

client = DataClient("https://data.example.com", token=ClientCredentials(ISSUER, ID, SECRET))

async with AsyncDataClient(url, token=my_async_token_function) as client:   # pooled, HTTP/2 if h2 is installed
    await client.files.upload("main.ws.files", "a.txt", b"hello")

token may be a string, a function (called for every request), an async def function (async client) or ClientCredentials. Idempotent requests (GET, PUT, DELETE, and POSTs the client knows are repeatable) are retried with jittered backoff on 429, 502, 503, 504 and connection failures, honouring Retry-After (RetryPolicy, or retry=None). Every request carries a W3C traceparent (continue yours with with trace_context(header): ..., or an active OpenTelemetry span).

Errors are RFC 9457 problems, one class each, all DataError: InvalidRequest, Unauthorized, Forbidden, InsufficientScope (.required), NotFound, Conflict, PreconditionFailed, QuotaExceeded (.used_bytes, .quota_bytes), PayloadTooLarge, RateLimited (.retry_after), Unavailable; each keeps status, code, detail, request_id.

Namespaces

client.sql(q) Polars DataFrame [arrow]; .arrow(q), .stream(q) (record batches, bounded memory) [arrow]; .rows(q) JSON, no extra
client.catalog catalogs(), schemas(), tables(), table(), views(), create_view(), volumes(), create_volume(), search(), grants(), update_grants()
client.files volumes' files, below
client.tenants ensure(tenant_id, alias): idempotent tenant provisioning (needs the provisioner role)
client.upload(table, files) import local files into a table (direct to storage, then ingest)

Files

files = client.files
V = "tenant_acme.workspace.files"
info = files.upload(V, "users/u1/q3.csv", "q3.csv")                     # path, bytes or file object; multipart > 64 MiB, in parallel
data = files.read(V, "users/u1/q3.csv");  files.download(V, "users/u1/q3.csv", "out.csv")
files.upload(V, "lock", b"me", if_none_match=True)                      # create only  (PreconditionFailed if present)
files.upload(V, "doc", b"v2", if_match=files.info(V, "doc"))            # compare-and-swap
for f in files.list(V, "users/u1/"): print(f.path, f.size, f.version)
files.list_dir(V, "users/u1/")                                          # one folder level: files + sub-folders
list(files.versions(V, "doc")); files.restore(V, "doc", 1)
files.copy_prefix(V, "runs/main/", "runs/branch/"); files.delete_prefix(V, "tmp/")
files.put_many(V, {"a": b"1", "b": b"2"}); files.get_many(V, ["a", "b"])   # batch signing, parallel transfers
files.usage(V, "users/u1/"); files.set_quota(V, 10 * 2**30)

The API only signs URLs; this client sends and fetches the bytes itself. Adapters that move bytes some other way use the low-level calls initiate_upload, complete_upload, sign, download_url, put_to_url. FILESTORE_KEY_MAP.md explains how the agent library's FileStore maps onto these calls. Server side: FILES.md.

Develop

uv run --package substrate-data-client pytest data/substrate-data-client/tests

Metadata

Release files for substrate-data-client 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for substrate-data-client 0.2.0
File Size Uploaded Provenance
substrate_data_client-0.2.0.tar.gz 27.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for substrate-data-client 0.2.0
File Interpreter ABI Platform
substrate_data_client-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 61.1 kB

Release files / substrate_data_client-0.2.0.tar.gz

Download URL substrate_data_client-0.2.0.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b3601c67b8721461e0bb9f6b3ea94b9b18f7abb33cbbbd7146f459aaf548f79e
BLAKE2b-256 checksum
How to use checksums
7cc6402c352b5d4716ca4606756eb79fb175ef84880a6dd90ef2b3d7054363b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / substrate_data_client-0.2.0-py3-none-any.whl

Download URL substrate_data_client-0.2.0-py3-none-any.whl
Size 33.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5379efdfce2c8e7ad880bce7b098fa7bd24b694a3ed78c177047fc4aa9aea368
BLAKE2b-256 checksum
How to use checksums
ebeacedbb1aa30369196536744760fd4ff37bca33ede6f519eccd389903aa4cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for substrate-data-client 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page