Skip to main content

audr

PyPI Python versions

The core Python SDK for AUDR (Agent Usage Detail Record) builds records, validates them against the published schema, and delivers them to any Sink, such as a file, a queue or a metering backend, through a bounded, batching async pipeline. Adapters and sinks build on it, and an application can emit records with this package alone.

Status: alpha. The record model tracks AUDR v1.1.0; until 1.0.0, a minor release may change the public API.

Setup

pip install audr

Requires Python 3.11 or later.

Usage

import asyncio
import audr

record = audr.AUDR(
    timing=audr.Timing(duration_ms=812),  # event_time defaults to now
    resource=audr.Resource(
        provider="anthropic",
        type="model",
        name="claude-sonnet-5",
        operation="generation",
        modality="text",
    ),
    usage=audr.Usage(llm=audr.LlmUsage(input_tokens=1200, output_tokens=340, requests=1)),
    run=audr.Run(run_id="01J8ZQ8Y2K3M4N5P6Q7R8S9T0V", span_id="turn-3", run_type="agent_run"),
    attribution=audr.Attribution(environment="production", account_id="acct_42"),
)  # record_id and spec_version defaulted


async def main() -> None:
    async with audr.Client(
        audr.FileSink("audr.jsonl"),
        emitter=audr.Emitter(component="harness", name="my-harness", version="1.4.0"),
    ) as client:
        result = client.record(record)
        assert result.queued, result.issues
    print(client.stats)


asyncio.run(main())

client.record() validates and queues the record and returns at once; a background worker batches records and hands each batch to the sink. Leaving the async with block drains the queue and closes the sink. Runnable versions, including a custom sink, are in examples/.

Validation

Records arriving as JSON are parsed and validated by AUDR.from_json(), which raises audr.ValidationError carrying one issue per problem:

import audr

payload = '{"spec_version": "1.1.0", "resource": {"type": "model"}}'
try:
    record = audr.AUDR.from_json(payload)
except audr.ValidationError as error:
    for issue in error.issues:
        print(issue.code, issue.path)  # for example: REQUIRED /timing

Each issue carries a stable ErrorCode and a JSON-pointer path, never the offending value, so issues are safe to log. record.validate() returns the same issues for a record built in code.

Delivery

BatchResult from the sink Each record becomes
ACCEPTED sent, except records the sink names as rejected (dropped) or unknown
RETRYABLE_FAILURE, PERMANENT_FAILURE, CLOSED dropped

Every record admitted through client.record() ends in exactly one of sent, dropped or unknown. An unknown record may or may not have arrived, so a consumer that de-duplicates on record_id can replay it safely. The pipeline never retries; retrying is the sink's responsibility. FileSink flushes once per batch, and when a write fails part way, the batch is reported retryable while the lines already written remain in the file.

Documentation

  • Reference: client options, submission outcomes, callbacks, the sink contract, validation codes, testing helpers
  • Examples: runnable offline, against the local filesystem
  • Changelog
  • AUDR specification, which defines every record field

License

Apache-2.0. Contributions follow CONTRIBUTING.md.

Metadata

Release files for audr 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 audr 0.2.0
File Size Uploaded Provenance Actions
audr-0.2.0.tar.gz 31.1 kB With provenance Details for audr-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for audr 0.2.0
File Interpreter ABI Platform Actions
audr-0.2.0-py3-none-any.whl Python 3 none any Details for audr-0.2.0-py3-none-any.whl

Total release size: 70.2 kB

Release files / audr-0.2.0.tar.gz

Download URL audr-0.2.0.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8b8e20b95a303fee8ef5d0d10065202480032ddde9dabe6ead464932b90c76a3
BLAKE2b-256 checksum
How to use checksums
75bcd308d849d826bd0bd3b7ca34744acbbbacd8f5e995e4ac7564bcecda18b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

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

Download URL audr-0.2.0-py3-none-any.whl
Size 39.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6ea16dfa8fa6968a8839b83561ebef8411b8f40a29d7b389d6a85d6ae7bd602
BLAKE2b-256 checksum
How to use checksums
066d52ed1b50cfef03d644e5feb61a7383db1cf211d243702d510678e5dde4d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 20, 2026.

Transparency log

Security for audr 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for audr-0.2.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 Oct 20, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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