Skip to main content

Audit trail and activity log for Arvel — automatic model change history plus a fluent business-event recorder.

Project description

arvel-audit

PyPI MIT License

Automatic audit trail and a fluent activity log for Arvel.

Two logging layers in one package:

  • Audit trail — add Auditable to a model and every create / update / delete writes an AuditEntry (old values, new values, actor) inside the same transaction. No per-model observer or middleware code.
  • Activity log — record business events ("user exported report") with the fluent activity() API. Attach an actor, a subject, a causer, and arbitrary properties; persist in any backend.

Status: Pre-alpha.


Documentation: https://arvel.dev/packages/audit


Install

uv add "arvel[audit]"
# or: pip install arvel-audit

Register the provider in bootstrap/providers.py:

from arvel_audit import AuditServiceProvider

providers = [
    # ...other providers...
    AuditServiceProvider,
]

Publish the migrations (audit_entries, activity_entries) and run them:

arvel vendor:publish --tag=arvel-audit   # or: arvel audit:install
arvel migrate

The provider binds AuditConfig and wires the Auditable observers on boot.

Audit trail

from arvel.database import Model, id_, string
from arvel_audit import Auditable


class Invoice(Model, Auditable):
    __tablename__ = "invoices"
    __audit_redact__ = {"card_number", "cvv"}   # masked as "***" in the trail

    id: int = id_()
    status: str = string(20, default="new")

Creating, updating, or deleting an Invoice now records an AuditEntry automatically. The actor is read from Context.get("user_id") when present, otherwise stored as None.

Query the trail:

from arvel_audit import AuditLog

history = await AuditLog(session).for_model(invoice).get()
mine = await AuditLog(session).by_actor(user.id).action("updated").get()
page = await AuditLog(session).for_model(invoice).paginate(per_page=50)

Activity log

from arvel_audit import activity, ActivityQuery

await (
    activity("exports", session=session)
    .log("Exported Q1 report")
    .by(user)
    .on(report)
    .with_properties({"format": "pdf", "rows": 1200})
    .save()
)

entries = await ActivityQuery(session).for_subject(report).get()

Encryption

Set AUDIT_ENCRYPT_VALUES=true to store old_values / new_values as AES-256-GCM ciphertext (keyed from APP_KEY). Reads decrypt transparently.

See the full reference for column control and query options.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arvel_audit-0.6.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arvel_audit-0.6.2-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file arvel_audit-0.6.2.tar.gz.

File metadata

  • Download URL: arvel_audit-0.6.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for arvel_audit-0.6.2.tar.gz
Algorithm Hash digest
SHA256 6ac48947b47fb30587efbf9df74c5950e12bbdf624b0a3604dc23cd0ea05543a
MD5 a7d151564ffd1e8dca5a7ed12814736d
BLAKE2b-256 b8c5ca77ca786e6a0423bfabd3df74cec9d4fb57de03c7ef8cd213a6da9caedb

See more details on using hashes here.

Provenance

The following attestation bundles were made for arvel_audit-0.6.2.tar.gz:

Publisher: publish.yml on mohamed-rekiba/arvel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arvel_audit-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: arvel_audit-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for arvel_audit-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d2506462f3b1190e0401efa283d189afc9f9fb6765db239bf579820c9f2dccf
MD5 7c057dde6bf8ac7c413f12d4d77bc6fd
BLAKE2b-256 258a377b5630a17e85178aff91bc04312efb2d358612d01152ee0f8f855a6528

See more details on using hashes here.

Provenance

The following attestation bundles were made for arvel_audit-0.6.2-py3-none-any.whl:

Publisher: publish.yml on mohamed-rekiba/arvel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page