django-tolap
TOLAP policies managed in Django admin and enforced on your QuerySets.
TOLAP (Tool-Object Level Access Protocol, AWS,
Apache-2.0) decides what an AI agent's tool may return: which tables, columns and rows,
how fields are masked, how many results. django-tolap brings that to Django:
- QuerySet enforcement.
enforce(queryset, context)returns the rows a signed TOLAP policy allows, as dicts, with hidden columns gone and masked fields masked. - ORM-native pushdown. Row filters become
Qobjects, the result limit becomes a slice, hidden columns leave theSELECT. Excluded rows never cross the wire. Proven equal to post-pass-only with upstream's fixtures and property tests; TOLAP's own post-execution pass always runs afterwards. - Policy store in Django admin. Definitions and assignments are models with migrations, validation through upstream's deserializer, schema-drift warnings, a resolve preview and an audit log.
- A tool decorator and DRF mixins that resolve, sign, verify and enforce per call.
Install
pip install django-tolap # add [drf] for the REST Framework mixins
Python 3.11+, Django 5.2 to 6.1. Pulls tolap-core and tolap-store from PyPI.
Quickstart
# settings.py
INSTALLED_APPS += ["django_tolap"]
TOLAP = {"SIGNING_KEY": "change-me"} # any secret; treat it like SECRET_KEY
python manage.py migrate django_tolap
from django_tolap import enforce, issue_context
from django_tolap.store import DjangoPolicyStore
store = DjangoPolicyStore()
store.save_definition_json({
"version": "1.0",
"name": "analyst",
"permissions": {"canQuery": True, "readOnly": True},
"objectRules": {
"allowedObjects": ["patients"],
"fieldRules": {
"hiddenFields": ["patients.ssn"],
"maskedFields": [{"field": "patients.email", "maskType": "hash"}],
},
"rowFilters": [{"field": "region", "operator": "in", "values": ["us-east", "us-west"]}],
},
"limits": {"maxResults": 500},
})
store.assign("analyst", user_id="alice", tenant_id="clinic", granted_by="admin", reason="demo")
context = issue_context("alice", "clinic", "db:clinic:patients")
rows = enforce(Patient.objects.filter(status="active"), context)
The SQL that ran selects only the visible columns, filters region in the database and
stops at 500 rows. email comes back as a SHA-256 pseudonym. Then TOLAP's post-execution
pipeline runs over the rows; that pass is the security boundary and always runs.
Full documentation, the benchmark on 1,000,000 rows, the agent-tool decorator and the Django REST Framework integration are in the repository README.
License
Apache-2.0. Not affiliated with AWS; TOLAP is their project.
Release files for django-tolap 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_tolap-0.2.0.tar.gz | 40.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_tolap-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 96.3 kB
Release files / django_tolap-0.2.0.tar.gz
| Download URL | django_tolap-0.2.0.tar.gz |
|---|---|
| Size | 40.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b25ab2abdd48d5d7ee4fc2f6796e83dfbd99a6d33d6c8f6c6dd76e97a654b4dd
|
|
BLAKE2b-256 checksum How to use checksums |
ca714a5b92deacad96fa6436bbf66b3d2acbcbefad219924617309029dd5cc69
|
| 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 Sep 26, 2026.
Transparency logRelease files / django_tolap-0.2.0-py3-none-any.whl
| Download URL | django_tolap-0.2.0-py3-none-any.whl |
|---|---|
| Size | 55.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a45484a470b1451dae6152a029b76a37dc0cac765cb2a20be80eb723caf4ee7
|
|
BLAKE2b-256 checksum How to use checksums |
e585f6e2f1c4109a611cfe1ff39cce99f05ebcb66c2891e1d458133d69d0ef75
|
| 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 Sep 26, 2026.
Transparency log