Skip to main content

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 WHERE clauses, the result limit a LIMIT, 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.2.0

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

Source distribution (sdist)

Source distribution for sqlalchemy-tolap 0.2.0
File Size Uploaded
sqlalchemy_tolap-0.2.0.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-tolap 0.2.0
File Interpreter ABI Platform
sqlalchemy_tolap-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.4 kB

Release files / sqlalchemy_tolap-0.2.0.tar.gz

Download URL sqlalchemy_tolap-0.2.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2c20caccb4030c5f1320c1f7d6f883bfb98478aa1699c2e004b7f74c9488d413
BLAKE2b-256 checksum
How to use checksums
3b509775ba19aea1a3274796b10972ab196c0b8a4cbf453649359fb35686054c
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 / sqlalchemy_tolap-0.2.0-py3-none-any.whl

Download URL sqlalchemy_tolap-0.2.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e568225401c1b7c51c5d46ccec7e5e57d74413a5762e244ed343f342fce58608
BLAKE2b-256 checksum
How to use checksums
3c826f9ca0b44a7b9ac9f918b2007eb8066e619b345f20a25fe6029c2d18168b
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

0.2.1

2 release files

This release

0.2.0 This release

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