Skip to main content

SAPL Policy Enforcement Point (PEP) core library for Python

Project description

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).

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.pdp_client import PdpClient, PdpConfig
from sapl_base.types import AuthorizationSubscription

client = PdpClient(PdpConfig(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, or NOT_APPLICABLE
policy "permit doctors to read patient data"
permit
  action == "read"
where
  "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-once, multi-decide, multi-decide-all-once, multi-decide-all)
  • Streaming SSE subscriptions with automatic reconnect and exponential backoff
  • Constraint enforcement engine with seven handler types (runnable, consumer, mapping, filter predicate, error handler, error mapping, method invocation)
  • Built-in content filtering via filterJsonContent (blacken, delete, replace)
  • Pre-enforce and post-enforce primitives for request/response authorization
  • Three streaming enforcement strategies: enforce-till-denied, enforce-drop-while-denied, enforce-recoverable-if-denied
  • Bearer token and HTTP basic auth support; HTTPS by default

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

Getting Started

pip install sapl-base

For the PEP implementation specification and constraint handler reference, see the PEP documentation.

Links

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sapl_base-4.0.0.tar.gz (51.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sapl_base-4.0.0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file sapl_base-4.0.0.tar.gz.

File metadata

  • Download URL: sapl_base-4.0.0.tar.gz
  • Upload date:
  • Size: 51.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sapl_base-4.0.0.tar.gz
Algorithm Hash digest
SHA256 9a7975d6ff53369406f881c0d234868732fd14ab9a43cb230dfe3b642f883668
MD5 09370315c123cdee802c1994acc21cc2
BLAKE2b-256 436d9b208ee0939fab593cc7ac484489f149846360cda85bdbea45d41ccdcded

See more details on using hashes here.

File details

Details for the file sapl_base-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: sapl_base-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 30.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sapl_base-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38870316afedeff7448d617a03adce0c2ad51433b6ebc78673b6b29203a51fa7
MD5 bd2b1d4c25f86a49b689a14536e0dbc4
BLAKE2b-256 892fe171df2b1babac6a201dda1c4bdacec5aec62f74c43bd35e499512fbcbb3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page