sapl-sqlalchemy
SAPL signal source for SQLAlchemy. Contributes the SQL_QUERY signal and a
sql:queryRewriting constraint handler provider so a SAPL policy can shape the
relational queries an application issues, the same way sapl-pymongo
contributes MONGO_QUERY for MongoDB queries.
SQLAlchemy exposes a mutating query hook, the do_orm_execute event on the
Session. The cut point is therefore a listener on the ORM session that
discharges SQL_QUERY with the statement before it executes and applies the
rewritten statement. Registering the listener attaches to the Session class,
so it covers every session, including AsyncSession through its sync-session
proxy.
Obligation
SqlQueryRewritingProvider handles the sql:queryRewriting obligation (and its
relational:queryRewriting alias), mirroring the Spring provider so the same
obligation narrows identically on every SAPL SQL PEP. Narrowing-only (criteria
and conditions are AND-merged into the user's WHERE, never widening it):
{
"type": "sql:queryRewriting",
"criteria": [
{"column": "tenant_id", "op": "=", "value": 7},
{"or": [{"column": "owner_id", "op": "=", "value": "alice"},
{"column": "public", "op": "=", "value": true}]}
],
"conditions": ["status IN ('active', 'pending')"],
"columns": ["id", "name"]
}
criteria ops: =, !=, >, >=, <, <=, in, like, notLike,
isNull, isNotNull; and / or group nested criteria. conditions carries
raw SQL fragments for features the typed form cannot express (BETWEEN,
EXISTS, vendor functions), and columns narrows the projection. A statement
that cannot carry a WHERE clause, a raw text() statement, or a malformed
criterion fails closed.
Usage
from sapl_sqlalchemy import SqlQueryRewritingProvider, register_orm_listener
# At startup: register the ORM listener once (this also registers the shim with
# the planner, so a sql:queryRewriting obligation is admissible).
register_orm_listener()
# Register the provider with the EnforcementPlanner that backs your framework
# wrapper: providers=(SqlQueryRewritingProvider(),)
# In a @pre_enforce-protected handler, query through the ORM session as usual; a
# sql:queryRewriting obligation on the decision narrows the statement automatically.
Off-session access
Execution that bypasses the ORM session (SQLAlchemy Core engine.execute(), a
raw DBAPI cursor) never triggers the event, so no filter is applied. Once the
listener is registered the obligation is accepted, so off-session access is left
unfiltered rather than denied: you own row-level security manually for that path.
Metadata
Release files for sapl-sqlalchemy 4.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 | Provenance | Actions |
|---|---|---|---|---|
| sapl_sqlalchemy-4.1.0.tar.gz | 13.4 kB | Without provenance | Details for sapl_sqlalchemy-4.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sapl_sqlalchemy-4.1.0-py3-none-any.whl | Python 3 | none | any | Details for sapl_sqlalchemy-4.1.0-py3-none-any.whl |
Total release size: 21.3 kB
Release files / sapl_sqlalchemy-4.1.0.tar.gz
| Download URL | sapl_sqlalchemy-4.1.0.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f6ac1bc9fe93df2ee819a220e4cbdbc32f7dcf808cf45e8a065744c6e29f7c7
|
|
BLAKE2b-256 checksum How to use checksums |
3a36a8e05e31aea8e4b60ff3020742c2a99bbe59a34a7f518d85e7852772b744
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Release files / sapl_sqlalchemy-4.1.0-py3-none-any.whl
| Download URL | sapl_sqlalchemy-4.1.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b5f549ca65d30f972332547badc0bbe66fcdf0287a5b748b5c6e00f1f551646
|
|
BLAKE2b-256 checksum How to use checksums |
67bc477320590794dc60ed915b5e38822af70cea6cb6415aebeecf445122eebc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Security for sapl-sqlalchemy 4.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.