Audit logging library with pluggable backends
Project description
airlog
A Python audit logging library with pluggable backends and compliance-grade features.
Features
| Feature | Details |
|---|---|
| Immutable log stream | AuditStream is append-only – no modify or delete operations |
| Structured events | AuditEvent is a frozen dataclass with nanosecond-precision timestamps |
| Correlation IDs | correlation_id field tracks a request across its entire lifecycle |
| Principal tracking | Principal captures subject, auth method (password / API key / certificate / JWT / …), and arbitrary metadata |
| Integrity verification | SHA-256 checksum over all event fields; event.verify() detects tampering |
| Unique event IDs | UUID v4 per event + monotonically increasing sequence numbers |
| Pluggable backends | Implement AuditStream.emit() to target stdout, files, syslog, databases, or any custom destination |
| loguru / JSON | LoguruAuditStream ships out of the box for newline-delimited JSON output |
| Thread-safe | Sequence counter is protected by a lock |
Requirements
- Python 3.11+
- uv (recommended package manager)
Installation
uv add airlog
Or with pip:
pip install airlog
Quick start
from airlog import LoguruAuditStream, Principal
stream = LoguruAuditStream() # JSON → stderr by default
event = stream.record(
"login",
principal=Principal(subject="alice", auth_method="password", metadata={"ip": "10.0.0.1"}),
resource="session",
resource_id="ses-42",
correlation_id="req-abc123",
)
# Verify integrity at any time
assert event.verify()
print(event.event_id) # UUID v4
print(event.sequence) # 1
print(event.timestamp) # UTC datetime
print(event.checksum) # SHA-256 hex
Custom backend
from airlog import AuditEvent, AuditStream, Principal
class SyslogStream(AuditStream):
def emit(self, event: AuditEvent) -> None:
import syslog
syslog.syslog(f"[{event.sequence}] {event.action} by {event.principal.subject}")
stream = SyslogStream()
stream.record(
"delete",
principal=Principal(subject="bob", auth_method="certificate"),
resource="document",
resource_id="doc-7",
outcome="success",
)
Sample JSON output (LoguruAuditStream)
Each call to record() emits one newline-delimited JSON line. All audit
fields are stored under record.extra:
{
"record": {
"extra": {
"event_id": "4e1b2f3c-…",
"sequence": 1,
"timestamp_ns": 1735000000000000000,
"timestamp": "2025-01-01T00:00:00+00:00",
"action": "login",
"principal_subject": "alice",
"principal_auth_method": "password",
"principal_metadata": {"ip": "10.0.0.1"},
"resource": "session",
"resource_id": "ses-42",
"outcome": "success",
"correlation_id": "req-abc123",
"context": {},
"checksum": "a3f1…"
}
}
}
Examples
Comprehensive examples are available in the examples/ directory:
- Basic Usage: Simple getting started examples with various adapters
- Pipeline & Middleware: Building pipelines with enrichment and redaction
- Context Tracking: Automatic event enrichment using audit contexts
- Metrics & Monitoring: Collecting metrics from audit events
- Policy & Routing: Policy-based event routing to different streams
- Integrity & Verification: Tamper detection and integrity checking
- Retention Management: Configuring retention rules and automatic cleanup
- Backend Adapters: OCSF format and OpenTelemetry integration
- Registry: Using the global pipeline registry
Run any example:
python examples/basic_usage.py
# or
uv run examples/basic_usage.py
See examples/README.md for the complete list and details.
Development
make install # install all dependencies
make lint # check formatting + lint rules
make format # auto-format and fix lint issues
make test # run tests with coverage (≥90 %)
make build # build wheel/sdist + twine check
make release # test + build
make clean # remove dist/, coverage output
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file airlog-1.0.0.tar.gz.
File metadata
- Download URL: airlog-1.0.0.tar.gz
- Upload date:
- Size: 101.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b1fcfea1975735ec5dc48c62336c99a45e6abaf88206f33c0c0f3aa2e7ba382
|
|
| MD5 |
cdd586baa61acf69e4fccded064bebee
|
|
| BLAKE2b-256 |
da7aecda21921e9bcdf9b6d88cfc03224d74030fbdf7e69af290abc6d6581d09
|
Provenance
The following attestation bundles were made for airlog-1.0.0.tar.gz:
Publisher:
publish.yml on ashforge-rs/airlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airlog-1.0.0.tar.gz -
Subject digest:
7b1fcfea1975735ec5dc48c62336c99a45e6abaf88206f33c0c0f3aa2e7ba382 - Sigstore transparency entry: 1429051806
- Sigstore integration time:
-
Permalink:
ashforge-rs/airlog@ca568c62cd0b8f2b038c74c708fb7208e5fd598f -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ashforge-rs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ca568c62cd0b8f2b038c74c708fb7208e5fd598f -
Trigger Event:
release
-
Statement type:
File details
Details for the file airlog-1.0.0-py3-none-any.whl.
File metadata
- Download URL: airlog-1.0.0-py3-none-any.whl
- Upload date:
- Size: 62.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e2c35acadc7fb0e3a784b4b8354542a9e7e84b106d0b28e23496efa3ec4030f
|
|
| MD5 |
2e36584843edeabd8399542bb736e284
|
|
| BLAKE2b-256 |
09d97258822c89f1345e4f3495ab5cafb3d978657fff9399bca94f77370f83ab
|
Provenance
The following attestation bundles were made for airlog-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on ashforge-rs/airlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
airlog-1.0.0-py3-none-any.whl -
Subject digest:
3e2c35acadc7fb0e3a784b4b8354542a9e7e84b106d0b28e23496efa3ec4030f - Sigstore transparency entry: 1429051835
- Sigstore integration time:
-
Permalink:
ashforge-rs/airlog@ca568c62cd0b8f2b038c74c708fb7208e5fd598f -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/ashforge-rs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ca568c62cd0b8f2b038c74c708fb7208e5fd598f -
Trigger Event:
release
-
Statement type: