auditledge-python
Official Python SDK for Auditledge — the audit log API for SaaS developers.
Add "who did what and when" to your app in minutes.
Install
pip install auditledge
Quickstart
from auditledge import AuditLedge
client = AuditLedge('your_api_key')
# Log an event
client.log({
'actor': {'id': 'user_123', 'name': 'Alice', 'email': 'alice@example.com'},
'action': 'invoice.deleted',
'resource': {'type': 'invoice', 'id': 'inv_456', 'name': 'Invoice #1042'},
'organization_id': 'org_789',
'metadata': {'ip': '192.168.1.1'}
})
# Query events
result = client.query({
'organization_id': 'org_789',
'limit': 50
})
print(result['events']) # list of events
print(result['total']) # total matching count
# Query with filters
result = client.query({
'actor_id': 'user_123',
'action': 'invoice', # partial match
'start_date': '2026-01-01T00:00:00Z',
'end_date': '2026-12-31T23:59:59Z',
})
# Export as CSV
csv_data = client.export({'format': 'csv', 'organization_id': 'org_789'})
# Export as JSON
events = client.export({'format': 'json', 'organization_id': 'org_789'})
# Check quota usage
info = client.usage()
print(info['plan']) # 'free', 'starter', or 'growth'
print(info['events_this_month']) # events logged this month
print(info['events_limit']) # monthly cap
Django / FastAPI Example
from auditledge import AuditLedge
audit = AuditLedge('your_api_key')
def delete_invoice(request, invoice_id):
invoice = Invoice.objects.get(id=invoice_id)
invoice.delete()
audit.log({
'actor': {'id': str(request.user.id), 'name': request.user.get_full_name()},
'action': 'invoice.deleted',
'resource': {'type': 'invoice', 'id': str(invoice_id)},
'organization_id': str(request.user.organization_id),
'metadata': {'ip': request.META.get('REMOTE_ADDR')}
})
Reference
AuditLedge(api_key, base_url=None, timeout=30)
| Param | Description |
|---|---|
api_key |
Your Auditledge API key |
base_url |
Override the API base URL (optional) |
timeout |
HTTP request timeout in seconds (default 30) |
log(event) → dict
Log an audit event. All fields marked required will raise AuditLedgeError locally before the request is made.
| Field | Required | Description |
|---|---|---|
actor.id |
Yes | ID of the user or service performing the action |
actor.name |
No | Display name |
actor.email |
No | Email address |
action |
Yes | Dot-notation string, e.g. invoice.deleted |
resource.type |
Yes | Resource type, e.g. invoice |
resource.id |
Yes | Resource ID |
resource.name |
No | Display name |
organization_id |
No | Defaults to the key's organisation |
metadata |
No | Any additional key/value data |
timestamp |
No | ISO 8601 string — defaults to now |
query(filters) → dict
| Filter | Description |
|---|---|
organization_id |
Filter by organisation |
actor_id |
Exact match on actor ID |
actor_name |
Partial match on actor name |
action |
Partial match on action string |
resource_type |
Exact match on resource type |
search |
Full-text search across action, actor name, and resource type |
start_date |
ISO 8601 — events on or after this date |
end_date |
ISO 8601 — events on or before this date |
limit |
Max results (default 20) |
offset |
Pagination offset (default 0) |
Returns { events: [...], total: int, limit: int, offset: int }.
get(event_id) → dict
Fetch a single event by ID.
export(options) → str or list
| Option | Description |
|---|---|
format |
'csv' or 'json' (default 'json') |
organization_id |
Filter by organisation |
start_date |
ISO 8601 start date |
end_date |
ISO 8601 end date |
Returns a str for CSV, or a list of event dicts for JSON.
usage() → dict
Returns { plan, events_this_month, events_limit, retention_days }.
Links
- 🌐 Website: auditledge.com
- 📖 Docs: docs.auditledge.com
- 🐛 Issues: github.com/auditledge/auditledge-python/issues
License
MIT
Release files for auditledge 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| auditledge-0.1.1.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| auditledge-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.6 kB
Release files / auditledge-0.1.1.tar.gz
| Download URL | auditledge-0.1.1.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22bdcfab03a45e628d31742e6ffae3874c0184c464b7a1b819103296b04ef85f
|
|
BLAKE2b-256 checksum How to use checksums |
18dcab5ab6e1d4867b52854704649b802f05e5f99d8a799fa7f434f3076cd6cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / auditledge-0.1.1-py3-none-any.whl
| Download URL | auditledge-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
74ac92715d139c2eddb4061cfa5cf556badf6b408c8d115c0b7553d909000a29
|
|
BLAKE2b-256 checksum How to use checksums |
e9186c7c7ea1e00e72e93b43354f20e0753450d4003f2ebb3e29e3e23c3554bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|