sqlalchemy-tolap
TOLAP policies enforced on SQLAlchemy Select statements with ORM-native pushdown.
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. sqlalchemy-tolap enforces a signed TOLAP
context on a SQLAlchemy 2.x Select before it runs, and applies TOLAP's own
post-execution pass afterwards.
- Pre-execution checks. Signature and expiry,
canQuery, object access for every table in the statement, referenced columns against hidden and allowed sets. Refuses rather than narrows. - Pushdown. Row filters become
WHEREclauses, the result limit aLIMIT, hidden columns leave the projection. Only where the dialect's semantics match TOLAP's; anything else is left to the post pass and reported, never approximated. - Differential proof. Pushdown plus post pass returns the same rows as post pass alone, on SQLite and PostgreSQL, against upstream's fixtures and a Hypothesis property.
Install
pip install sqlalchemy-tolap
Python 3.11+, SQLAlchemy 2.0 or 2.1. Pulls tolap-core from PyPI.
Usage
from sqlalchemy import select
from sqlalchemy_tolap import enforce
rows = enforce(
select(Patient).where(Patient.full_name.ilike(f"%{q}%")),
context, # a signed TOLAP SecurityContext from wherever you resolve policies
session, # Session or Connection; its dialect decides what can be pushed
signing_key=KEY,
)
Entity selects (select(Patient)) are the default projection; named columns and labels are
explicit references. text(), literal_column(), derived tables in FROM and set
operations are refused. enforce(..., mode="postOnly") skips the pushdown but not the
checks or the post pass.
Design notes, the vendor rules and the gap measurement against upstream's string rewriter are in the repository README.
License
Apache-2.0. Not affiliated with AWS; TOLAP is their project.
Release files for sqlalchemy-tolap 0.1.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 | |
|---|---|---|---|
| sqlalchemy_tolap-0.1.0.tar.gz | 14.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlalchemy_tolap-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.8 kB
Release files / sqlalchemy_tolap-0.1.0.tar.gz
| Download URL | sqlalchemy_tolap-0.1.0.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86085a1053764744113003df79a7278222794459d283e0076eb5973a3c81460d
|
|
BLAKE2b-256 checksum How to use checksums |
8a6033607c1d21abbbcb859172a13efe7726fe2519a7799412c7bf306a30e1d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.4
|
Release files / sqlalchemy_tolap-0.1.0-py3-none-any.whl
| Download URL | sqlalchemy_tolap-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de55a02b384e33f0a8298ed6ad676b91e7b6093e5c435530d2b784d17d92b767
|
|
BLAKE2b-256 checksum How to use checksums |
de6399919ad573eca2db5aeea6703b217828da125cdf29033c37a0c5f766c1ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.4
|