Skip to main content

auditrails

Official Python SDK for auditrails.io — tamper-proof audit logging as a service.

Install

pip install auditrails

Requires Python 3.9+. Zero dependencies (uses stdlib urllib).

For async support:

pip install auditrails[async]

Quick Start

from auditrails import AuditRails, AuditEvent, Config

audit = AuditRails(Config(api_key="at_live_..."))

# Fire-and-forget (buffered, flushed in background thread)
audit.log(AuditEvent(
    action=Actions.AUTH_LOGIN,   # typed compliance action constant
    actor_id="user_123",
    resource="session/sess_456",
    metadata={"ip": "1.2.3.4"},
))

# Before process exit:
audit.close()

That's it. Your first audit event in under 2 minutes.

Compliance Action Constants

The SDK includes Actions class with typed constants for all 42 compliance actions:

from auditrails.actions import Actions

audit.log(AuditEvent(action=Actions.AUTH_LOGIN, actor_id="user_1"))
audit.log(AuditEvent(action=Actions.CONSENT_GIVEN, actor_id="user_1"))
audit.log(AuditEvent(action=Actions.PHI_ACCESSED, actor_id="user_1", resource="patient/123"))

Raw strings are still accepted for backward compatibility.

API

AuditRails(config)

Config Option Type Default Description
api_key str required Your API key (at_live_... or at_test_...)
base_url str https://api.auditrails.io Ingestion API URL
batch_size int 100 Max events per batch (max 100)
flush_interval float 1.0 Auto-flush interval in seconds
max_retries int 3 Retry attempts for 5xx errors
timeout float 10.0 Request timeout in seconds

audit.log(event)

Buffer an event for batch sending. Never raises — errors are logged silently.

audit.log(AuditEvent(
    action="document.created",    # required
    actor_id="user_123",          # who did it
    resource="document/doc-456",  # what was affected
    metadata={"key": "value"},    # extra context (max 10 keys)
))

audit.log_direct(event) -> LogResponse

Send a single event immediately. Raises AuditRailsError on API errors.

response = audit.log_direct(AuditEvent(action="user.deleted", actor_id="admin_1"))
print(response.log_id)      # "01HX..."
print(response.request_id)  # "req_01HX..."

audit.log_batch_direct(events) -> BatchResponse

Send a batch of events immediately. Raises on error.

audit.flush()

Flush all buffered events immediately.

audit.close()

Flush remaining events and shut down. After close(), log() calls are silently ignored.

Async Client

For asyncio applications, use AsyncAuditRails (requires httpx):

from auditrails import AsyncAuditRails, AuditEvent, Config

audit = AsyncAuditRails(Config(api_key="at_live_..."))
await audit.start()

audit.log(AuditEvent(action="user.login", actor_id="user_123"))

response = await audit.log_direct(AuditEvent(action="user.deleted"))

await audit.close()

Error Handling

The SDK never crashes your application:

  • log() never raises — errors go to logging.getLogger("auditrails")
  • log_direct() and log_batch_direct() raise AuditRailsError on API errors
  • 5xx errors are retried with exponential backoff
  • 4xx errors fail immediately (no retry)
from auditrails import AuditRailsError

try:
    audit.log_direct(AuditEvent(action="test"))
except AuditRailsError as e:
    print(e.code)         # "validation/missing_action"
    print(e.status_code)  # 422
    print(e.request_id)   # "req_..."
    print(e.doc_url)      # link to docs

Type Safety

The SDK is fully typed and ships with py.typed for mypy compatibility.

License

MIT

Metadata

Release files for auditrails 1.0.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 auditrails 1.0.0
File Size Uploaded Provenance
auditrails-1.0.0.tar.gz 13.0 kB With provenance Details

Built distribution (wheel)

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

Total release size: 25.3 kB

Release files / auditrails-1.0.0.tar.gz

Download URL auditrails-1.0.0.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6329f6b94cbaae0c3f975a36098a04e4a92503534f06e2064a82df61743b32f8
BLAKE2b-256 checksum
How to use checksums
8de0e14cfdc5720425cf97852d4888733d901105ea9adde8cd047cd5467fc502
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 Aug 31, 2026.

Transparency log

Release files / auditrails-1.0.0-py3-none-any.whl

Download URL auditrails-1.0.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6def953b45e181529c9d3e641fa9cb85d9cd4893d4528d82f9a9720704b9982b
BLAKE2b-256 checksum
How to use checksums
0e5d88024086a6b44de701d7c978e0c8f20dc43b3a122604bb447f7b084ceaeb
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 Aug 31, 2026.

Transparency log

Security for auditrails 1.0.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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for auditrails-1.0.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 Aug 31, 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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full 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