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.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 sqlalchemy-tolap 0.2.1
File Size Uploaded
sqlalchemy_tolap-0.2.1.tar.gz 16.7 kB Details

Built distribution (wheel)

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

Total release size: 37.4 kB

Release files / sqlalchemy_tolap-0.2.1.tar.gz

Download URL sqlalchemy_tolap-0.2.1.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3ec04b7eea3f64d4f76555ec84fe4fcaaec6151ead1680122f111917a23f3a60
BLAKE2b-256 checksum
How to use checksums
d80229e6ee6e33240053daa75c5ecf8d9c406b0f5760ca2fc27066e0a42f899b
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.1-py3-none-any.whl

Download URL sqlalchemy_tolap-0.2.1-py3-none-any.whl
Size 20.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf97e9d2479646a30e7235e031157c6b10c02727d7bbd6f085ed6c9e6149e6a0
BLAKE2b-256 checksum
How to use checksums
1989c86feabb5884bc37e6d4a68f46980a132fdae5f281219b351316cbc9a25c
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.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