Official Python SDK for Auditledge — Audit Log API for SaaS developers
Project description
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
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 auditledge-0.1.1.tar.gz.
File metadata
- Download URL: auditledge-0.1.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22bdcfab03a45e628d31742e6ffae3874c0184c464b7a1b819103296b04ef85f
|
|
| MD5 |
fd9d2b5b87f549625f061feae4177360
|
|
| BLAKE2b-256 |
18dcab5ab6e1d4867b52854704649b802f05e5f99d8a799fa7f434f3076cd6cd
|
File details
Details for the file auditledge-0.1.1-py3-none-any.whl.
File metadata
- Download URL: auditledge-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74ac92715d139c2eddb4061cfa5cf556badf6b408c8d115c0b7553d909000a29
|
|
| MD5 |
e8975dad9509673866912ffd6a63e17b
|
|
| BLAKE2b-256 |
e9186c7c7ea1e00e72e93b43354f20e0753450d4003f2ebb3e29e3e23c3554bc
|