Skip to main content

Official bindings for the Axiom API

Project description

[!WARNING] Version v0.9.0 removes the aggregation operation enum, see #158.

axiom-py CI PyPI version Python version

Install

pip install axiom-py

Synchronous Client

import axiom_py

client = axiom_py.Client()

client.ingest_events(dataset="DATASET_NAME", events=[{"foo": "bar"}, {"bar": "baz"}])
client.query(r"['DATASET_NAME'] | where foo == 'bar' | limit 100")

Edge Ingestion

For improved data locality, you can configure the client to use regional edge endpoints for ingest and query operations. All other API operations continue to use the main Axiom API endpoint.

import axiom_py

# Using a regional edge domain
edge_client = axiom_py.Client(
    token="xaat-your-api-token",
    edge="eu-central-1.aws.edge.axiom.co"
)

# Or using an explicit edge URL
edge_client = axiom_py.Client(
    token="xaat-your-api-token",
    edge_url="https://custom-edge.example.com"
)

Note: Edge endpoints require API tokens (xaat-), not personal tokens. Edge configuration must be passed explicitly when creating the client.

Metrics Queries (MPL)

To query OTel metrics using MPL (Metrics Processing Language), configure the client with your edge endpoint and use mpl_query:

import axiom_py
from axiom_py import MplOptions
from datetime import datetime, timedelta, timezone

client = axiom_py.Client(
    token="xaat-your-api-token",
    edge="us-east-1.aws.edge.axiom.co"
)

end = datetime.now(timezone.utc)
start = end - timedelta(hours=1)

result = client.mpl_query(
    "`my-metrics`:`http.server.duration` | align to 5m using avg",
    opts=MplOptions(start_time=start, end_time=end),
)

for series in result.series:
    print(series.metric, series.tags, series.data)

Asynchronous Client

The library also provides an async client for use with asyncio:

import asyncio
from axiom_py import AsyncClient

async def main():
    async with AsyncClient() as client:
        # Ingest events
        await client.ingest_events(
            dataset="DATASET_NAME",
            events=[{"foo": "bar"}, {"bar": "baz"}]
        )

        # Query data
        result = await client.query(r"['DATASET_NAME'] | where foo == 'bar' | limit 100")
        print(f"Found {len(result.matches)} matches")

asyncio.run(main())

Concurrent Operations

The async client enables efficient concurrent operations:

import asyncio
from axiom_py import AsyncClient

async def main():
    async with AsyncClient() as client:
        # Ingest to multiple datasets concurrently
        await asyncio.gather(
            client.ingest_events("dataset1", [{"event": "data1"}]),
            client.ingest_events("dataset2", [{"event": "data2"}]),
            client.ingest_events("dataset3", [{"event": "data3"}]),
        )

asyncio.run(main())

Documentation

Read documentation on axiom.co/docs/guides/python.

License

MIT

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

axiom_py-0.12.0.tar.gz (117.3 kB view details)

Uploaded Source

Built Distribution

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

axiom_py-0.12.0-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file axiom_py-0.12.0.tar.gz.

File metadata

  • Download URL: axiom_py-0.12.0.tar.gz
  • Upload date:
  • Size: 117.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for axiom_py-0.12.0.tar.gz
Algorithm Hash digest
SHA256 e91471c074e45b9d5f78f20efc24428939cb01b01b1539bce321e412ed3ea1e3
MD5 6bfc99bd8d93248090f0f5dc3460267f
BLAKE2b-256 dbc5be105497803b94afd77b9fa9136d2186f25f1b7fc154cb838e6709f76f4f

See more details on using hashes here.

File details

Details for the file axiom_py-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: axiom_py-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 37.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for axiom_py-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc2eef7b026a909bda8664d0535b69943f8844180bdb4d0f316b11b005627258
MD5 faa824c15a73d6699f408da6a181108c
BLAKE2b-256 7b535931ec97f1778aa6c4053e2d787999f539faafe5099cdf669653890d7b8c

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