Skip to main content

Python client for the Axes data API, and the axes.agent framework

Project description

Axes Client Library

Python client for the Axes data API. Send SQL, get parquet back.

pip install axes-client

Quickstart

from axes import sql

result = sql("SELECT state, AVG(income) FROM american_community_survey.demographics GROUP BY state")

result.rows        # int — number of rows
result.bytes       # int — parquet response size in bytes
result.columns     # list[str] — ordered column names
result.elapsed_ms  # int — wall-clock time for the request

# Check size before loading into memory
if result.bytes < 100 * 1024 * 1024:
    df = result.collect()   # polars DataFrame — full result in memory
else:
    lf = result.scan()      # polars LazyFrame — safe for large results

# Save to parquet
result.save("/work/result.parquet")

# Stream directly to a file — never buffers the full response in memory
result = sql(
    "SELECT * FROM american_community_survey.demographics",
    out="/work/result.parquet",
)
lf = result.scan()  # polars LazyFrame over the file

Results under 10 MB are kept in memory. Larger results spill to a temp file in /tmp and are deleted when the SqlResult is garbage collected. .scan() is always safe — it returns a scan_parquet LazyFrame when spilled rather than loading into memory.

Configuration

export AXES_TOKEN=your-personal-access-token

AXES_ENDPOINT defaults to https://app.axes.com. Override it if you are running a self-hosted instance:

export AXES_ENDPOINT=https://your-axes-instance.com
export AXES_TOKEN=your-personal-access-token

Explicit client

from axes import Client, sql

client = Client(
    endpoint="https://your-axes-instance.com",
    token="your-token",
)

result = sql("SELECT * FROM american_community_survey.demographics", client=client)

CLI

# Stream rows to stdout as newline-delimited JSON (ndjson), one object per line
axes sql "SELECT state, AVG(income) FROM american_community_survey.demographics GROUP BY state"

# Pipe to jq — each line is a standalone JSON object
axes sql "SELECT state FROM american_community_survey.demographics" | jq '.state'

# Write parquet and print a JSON summary
axes sql "SELECT * FROM american_community_survey.demographics" --out /work/result.parquet

When --out is provided, a JSON summary is printed to stdout:

{
  "path": "/work/result.parquet",
  "rows": 51,
  "bytes": 4096,
  "columns": ["state", "income"],
  "elapsed_ms": 340
}

Errors

from axes.exceptions import QueryError, ResultTooLarge, AuthError

try:
    result = sql("SELECT * FROM american_community_survey.demographics")
except QueryError as e:
    print(e.message)      # SQL rejected by the server (400)
except ResultTooLarge as e:
    print(e.message)      # Exceeded row/byte cap (413)
except AuthError as e:
    print(e.status_code)  # 401 or 403

Appending data

append_table_data uploads a parquet file to an existing table. It needs a write-scoped token bound to the target dataset — the ingestion runner injects one as AXES_TOKEN; personal access tokens are read-only and raise AuthError.

from axes import append_table_data

# Accepts a polars DataFrame, a parquet path, or raw parquet bytes
result = append_table_data("demographics", df)

result.row_count           # rows written
result.byte_count          # bytes written
result.table_data_file_id  # id of the created file

# Atomically retire this firing's earlier files instead of adding to them
append_table_data("demographics", df, replace=True)

The uploaded parquet's columns must match the table's registered schema; a mismatch raises WriteError (409).

Agent framework

axes.agent is the container-side framework for authoring Chat Plot agents. Agents already read the data catalog through this client, so the framework ships here rather than as a separate package.

from axes.agent import Agent, Tool, RunContext

Author an agent as an Agent subclass with Tool members (and other Agent instances as subagents); the axes-agent console script reads one step off stdin, runs plan_step or run_tool, and writes the result to stdout. Chat Plot drives the multi-turn loop and owns the LLM call, persistence, and streaming. See weather-agent for a worked example.

Development

uv sync

uv run task test    # pytest
uv run task lint    # ruff check
uv run task format  # ruff format
uv run task check   # mypy (strict)

task fix runs ruff check --fix. Linting (ruff), formatting, and strict type checking (mypy) all run in CI on every push and pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

axes_client-0.4.0.tar.gz (73.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

axes_client-0.4.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file axes_client-0.4.0.tar.gz.

File metadata

  • Download URL: axes_client-0.4.0.tar.gz
  • Upload date:
  • Size: 73.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for axes_client-0.4.0.tar.gz
Algorithm Hash digest
SHA256 fbf0afb017c5fb919de69f4246604b4b4643213f472ac87a6602eda4c354e967
MD5 06091f343611c10c87f96dbd153ef2c2
BLAKE2b-256 aa37650f3a073019e65e8121bedb3c21eefa74313d98a20e966e93ff6ae61aba

See more details on using hashes here.

File details

Details for the file axes_client-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: axes_client-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for axes_client-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58e33087d76fc57a2b449c5eb0e9fa9fe5ef88efba629aaded038b36e9be86f4
MD5 c151fc0d49aecae6ca32cb658f54dd90
BLAKE2b-256 423edf3a8847805161aea30915aebbcd4c6f188b0ba698c0da31bda04b2b096a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page