Skip to main content

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 Q objects, the result limit becomes a slice, hidden columns leave the SELECT. 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-tolap 0.2.1
File Size Uploaded
django_tolap-0.2.1.tar.gz 41.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-tolap 0.2.1
File Interpreter ABI Platform
django_tolap-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 97.0 kB

Release files / django_tolap-0.2.1.tar.gz

Download URL django_tolap-0.2.1.tar.gz
Size 41.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9b9dd4c57bacbd20aced15da9982d7efe305dcd215ed762bb09de230bab6e397
BLAKE2b-256 checksum
How to use checksums
c33c6de56cd0076f3ea1812bf118e5bad39d9c715f55d489d83e3c90ff107369
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

Release files / django_tolap-0.2.1-py3-none-any.whl

Download URL django_tolap-0.2.1-py3-none-any.whl
Size 55.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3bab0fb084d0622f7b4f0ebf1108591678d7f44eba255bc4f7449bd154292a8
BLAKE2b-256 checksum
How to use checksums
8c3c49644f5de73c3bc2681924590cfceb883576b8ae8d2a37405d68b5a19c75
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

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page