Skip to main content

sapl-base

Core SAPL Policy Enforcement Point (PEP) library for Python. Provides the async PDP client, constraint enforcement engine, and enforcement primitives used by the framework integrations (sapl-flask, sapl-django, sapl-fastapi).

Implements the SAPL 4.1 enforcement model: a planner that binds constraint handlers to lifecycle signals, the SUSPEND decision verb, an optional RSocket transport, and a library-owned transaction boundary that rolls back on post-write denial.

How It Works

Your application sends authorization subscriptions to the Policy Decision Point (PDP) and enforces the decision. The PDP evaluates SAPL policies and returns permit/deny decisions with optional obligations, advice, and resource transformations.

from sapl_base.transport import HttpPdpClient, HttpPdpClientOptions
from sapl_base.types import AuthorizationSubscription

client = HttpPdpClient(HttpPdpClientOptions(base_url="https://localhost:8443"))
decision = await client.decide_once(AuthorizationSubscription(
    subject={"user": "alice", "roles": ["DOCTOR"]},
    action="read",
    resource="patient-record",
))
print(decision.decision)  # PERMIT, DENY, INDETERMINATE, NOT_APPLICABLE, or SUSPEND
policy "permit doctors to read patient data"
permit
  action == "read";
  "DOCTOR" in subject.roles

For streaming decisions that update as policies change:

async for decision in client.decide(subscription):
    print(decision.decision)

What You Get

  • Async HTTP client for all PDP REST endpoints (decide-once, decide, multi-decide, multi-decide-all, multi-decide-all-once)
  • Streaming SSE subscriptions with automatic reconnect and exponential backoff
  • Constraint enforcement via a single ConstraintHandlerProvider, returning ScopedHandler entries whose shape is a runner (no value), a consumer (observes a value), or a mapper (transforms a value)
  • Built-in content filtering via filterJsonContent (blacken, delete, replace)
  • Pre-enforce and post-enforce primitives for request/response authorization
  • Streaming enforcement through a single stream_enforce decorator backed by the run_pipeline engine
  • Bearer token and HTTP basic auth support; HTTPS by default

Most applications should use a framework integration instead of this package directly.

Database Transactions

One-shot enforcement can own a transaction boundary. When you configure a transaction provider, pre_enforce and post_enforce wrap the protected call plus enforcement in it, so a denial that lands after a DB write rolls the write back. The three triggers are a post_enforce DENY, a post_enforce output-obligation failure, and a pre_enforce output-obligation failure (the pre-decision permits, but its output obligations run after the method writes). A clean permit commits. This is opt-in: with no provider, the PEP owns no transaction and behaviour is unchanged.

A provider is a zero-arg factory returning an async context manager that commits on clean exit and rolls back on a propagated exception, exactly the semantics of SQLAlchemy AsyncSession.begin() and Django transaction.atomic(). The framework integrations expose set_transaction_provider(provider). For a sync transaction boundary (sync SQLAlchemy session.begin or Django transaction.atomic), wrap it with from_sync_context:

from sapl_base.pep import from_sync_context

The provider factory should resolve the current request's session or transaction.

Getting Started

pip install sapl-base

For the decision-verb semantics and the unified enforcement model, see the SAPL documentation.

Links

License

Apache-2.0

Metadata

Release files for sapl-base 4.1.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 sapl-base 4.1.0
File Size Uploaded Provenance Actions
sapl_base-4.1.0.tar.gz 51.5 kB Without provenance Details for sapl_base-4.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sapl-base 4.1.0
File Interpreter ABI Platform Actions
sapl_base-4.1.0-py3-none-any.whl Python 3 none any Details for sapl_base-4.1.0-py3-none-any.whl

Total release size: 111.3 kB

Release files / sapl_base-4.1.0.tar.gz

Download URL sapl_base-4.1.0.tar.gz
Size 51.5 kB
Tags Source
SHA-256 checksum
How to use checksums
009f7cef37f594426636bf84c0e332dd191911b50db504e0c2104b0d6661a66a
BLAKE2b-256 checksum
How to use checksums
41ede793433b0ac62ea57097c715848448884968756a70722b80d115654bdffd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Release files / sapl_base-4.1.0-py3-none-any.whl

Download URL sapl_base-4.1.0-py3-none-any.whl
Size 59.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ab6d4ec90e698369cb73e9878fa0a80f07144c6a1255af1dbbf61148fe95ea4
BLAKE2b-256 checksum
How to use checksums
79c140cd091d9342b3903c4bd6c2685c42e9cc3c0c478269f0a91886d525c19f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.13

Security for sapl-base 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.

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