chronix-client (Python)
Async Python client for the Chronix time-series database.
Features
- Async, on
httpx - Writes as JSON or line protocol, with exact decimals and idempotency keys
- Structured queries, SQL and PromQL; Arrow Flight SQL through ADBC
- Schema discovery, namespaces, and full type annotations (
py.typed)
Installation
pip install chronix-client
With pandas support:
pip install "chronix-client[pandas]"
Quick Start
import asyncio
from chronix_client import ChronixClient, Point, TimeRange
async def main():
async with ChronixClient("http://localhost:8086") as client:
# Write
await client.write([
Point("cpu", {"usage": 42.5}, tags={"host": "a"})
])
# Query
result = await client.query(
"cpu",
TimeRange(start=0, end=2**63 - 1),
tags={"host": "a"},
)
for row in result:
print(row)
# SQL
result = await client.sql("SELECT * FROM cpu ORDER BY _time DESC LIMIT 10")
df = result.to_dataframe() # requires pandas extra
asyncio.run(main())
Exact Decimals
f64 cannot represent 0.1. For a meter register a bill is computed from,
write a decimal.Decimal and the digits stay digits — in the request body,
in storage, and in the query result:
from decimal import Decimal
await client.write([
Point("meter", {"z1nb_q": Decimal("1234.5678")}, tags={"device": "main"})
])
The client sends {"z1nb_q": {"decimal": "1234.5678"}} rather than a JSON
number, because a JSON number is parsed as a double at the other end. Line
protocol uses the d suffix: meter,device=main z1nb_q=1234.5678d.
A decimal column stores a fixed number of fractional digits, set when the column is created; a value needing more is refused rather than rounded. Declare it first when the first value might not carry the digits you mean to keep — see Data Model.
Line Protocol Writes
await client.write_line_protocol([
"cpu,host=a usage=42.5 1700000000000000000",
"mem,host=a total=16384i,used=8192i 1700000000000000000",
])
PromQL Queries
# Instant query
result = await client.prom_query('cpu_usage{host="server-1"}')
# Range query
result = await client.prom_query_range(
'rate(cpu_usage[5m])',
start="2024-01-01T00:00:00Z",
end="2024-01-02T00:00:00Z",
step="60s",
)
# Label discovery
labels = await client.prom_labels()
values = await client.prom_label_values("host")
Arrow Flight SQL (Zero-Copy)
For high-throughput analytical queries, use Arrow Flight SQL via ADBC:
import adbc_driver_flightsql.dbapi
uri = ChronixClient.flight_sql_uri("localhost", 8817)
conn = adbc_driver_flightsql.dbapi.connect(uri)
cursor = conn.cursor()
cursor.execute("SELECT * FROM cpu WHERE _time > now() - INTERVAL '1 hour'")
table = cursor.fetch_arrow_table()
df = table.to_pandas()
Authentication & Multi-Tenancy
client = ChronixClient(
"http://localhost:8086",
api_key="your-api-key",
namespace="production",
)
Idempotent Writes
await client.write(
[Point("cpu", {"usage": 42.5})],
idempotency_key="batch-2024-01-15-001",
)
# Second call with same key → WriteError (HTTP 409)
API Reference
ChronixClient
| Method | Description |
|---|---|
health() |
Health check |
ready() |
Readiness check |
server_info() |
Server metadata |
write(points, *, idempotency_key, backfill) |
Write points (JSON); backfill=True imports history outside the out-of-order window |
write_line_protocol(lines, *, idempotency_key) |
Write (line protocol) |
query(measurement, time_range, *, tags, fields, limit, offset) |
Structured query |
sql(query) |
SQL query |
explain(measurement, time_range) |
Explain query plan |
list_measurements() |
List measurements |
get_schema(measurement) |
Get column schema |
drop_measurement(measurement) |
Drop measurement |
delete(measurement, time_range=None, *, tags) |
Delete data; returns a DeleteResult — check .complete |
prom_query(query, *, time) |
PromQL instant query |
prom_query_range(query, start, end, step) |
PromQL range query |
prom_labels() |
List Prometheus labels |
prom_label_values(label) |
Label values |
prom_series(match) |
Find series |
list_rollups() |
List rollup rules |
list_connectors() |
List connectors |
openapi_spec() |
Fetch OpenAPI spec |
flight_sql_uri(host, port) |
Build Flight SQL URI |
Models
| Type | Description |
|---|---|
Point |
Data point with measurement, tags, fields, timestamp. A decimal.Decimal field is written exactly |
TimeRange |
Closed [start, end] in nanoseconds — both ends inclusive |
QueryResult |
Query result with .rows, .to_dataframe() |
ColumnSchema |
Column metadata (name, role, data_type) |
MeasurementInfo |
Measurement summary (name) |
ServerInfo |
Server metadata (version, uptime, measurement_count) |
Exceptions
| Exception | When |
|---|---|
ChronixError |
Base exception. Every error carries .hint (what the request probably meant), .span (the (start, end) byte range of the query it is about) and .retry_after, each None when the server sent none |
ConnectionError |
Cannot reach server |
WriteError |
Write failure (including idempotency conflict, HTTP 409) |
QueryError |
Any other 4xx |
BackpressureError |
HTTP 429/503/507 — back off and retry; .retry_after carries the server's hint |
DeadlineExceeded |
HTTP 504 — the server stopped waiting; the write may still land |
License
MIT OR Apache-2.0, at your option — the same as Chronix.
Metadata
Release files for chronix-client 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chronix_client-0.8.0.tar.gz | 24.4 kB | With provenance | Details for chronix_client-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chronix_client-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for chronix_client-0.8.0-py3-none-any.whl |
Total release size: 39.9 kB
Release files / chronix_client-0.8.0.tar.gz
| Download URL | chronix_client-0.8.0.tar.gz |
|---|---|
| Size | 24.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6dcbf1d01d3c322264477e8f196a249d8c31ce4e691837128e22249ed0cd6ac
|
|
BLAKE2b-256 checksum How to use checksums |
35fd3576beefd00167528c0676f4d7493218e4e4d07eaa50c1e0f05e89f470a6
|
| 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 17, 2026.
Transparency logRelease files / chronix_client-0.8.0-py3-none-any.whl
| Download URL | chronix_client-0.8.0-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dc55549bdfc5f6a73617099e63847a19f700c4ffb4c142418e056f507e78f819
|
|
BLAKE2b-256 checksum How to use checksums |
72573db3cb222f5f15ad636b8787de021342f3f0b07279804bcdb90de35022b1
|
| 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 17, 2026.
Transparency logSecurity for chronix-client 0.8.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for chronix_client-0.8.0.tar.gz
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 17, 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.