Skip to main content

Permguard Python SDK

PyPI ci licence

Permguard SDK for Python. Ask Permguard, from Python: the official Python client of the Permguard Policy Decision Point, Python 3.8 or newer, over HTTP or gRPC, Apache-2.0. Beside it, a Python window opens a client for grpc://localhost:7443 and evaluates whether the User alice may read in the ledger main-ledger of the zone acme; the answer is permit.

Permguard · Documentation · Install · Quick start · Develop

The official Python client of the Permguard Policy Decision Point.

Before your code acts, it asks Permguard whether a subject may perform an action on a resource, and Permguard answers from the policies of a ledger. This SDK is how Python code asks: one synchronous client for the native, stateless PDP interface permguard.api.pdp.native.v1, over HTTP/JSON or gRPC, with the same request and the same answer on both.

How a decision is asked. Your Python code asks before it acts: who, User alice; does what, read; on what, Document budget-2026. The Permguard Python SDK, one client with evaluate and evaluate_many, sends it as JSON to an http or https endpoint or over gRPC to a grpc or grpcs endpoint. The Permguard data plane, the PDP of the native v1 interface, decides with the policies of the ledger main-ledger in the zone acme, under the profile gateway, on Cedar, Rego or Dogwood. The answer is a permit, a deny, which is a normal answer, or a permguard.Refusal with its class and code.

Your code asks, the SDK carries the question, the data plane decides with the ledger's policies.

Install

The SDK needs Python 3.8 or newer, and is published on PyPI.

pip install permguard

With uv, uv add permguard; with Poetry, poetry add permguard. It needs a Permguard data plane to ask: by default it listens on port 7443, for HTTP and gRPC alike. See the Permguard repository to run one.

Quick start

from permguard import Action, Client, Entity, EvaluateRequest, Refusal

request = EvaluateRequest(
    zone="acme",
    ledger="main-ledger",
    subject=Entity(type="User", id="alice"),
    resource=Entity(type="Document", id="budget-2026"),
    action=Action(name="read"),
    request_id="example-1",
)

try:
    # grpc:// or grpcs:// speaks gRPC; http:// or https:// speaks JSON.
    with Client("grpc://localhost:7443") as client:
        response = client.evaluate(request)
except Refusal as refusal:
    raise SystemExit(f"refused: class={refusal.error_class} code={refusal.code} message={refusal.message}")

print("permitted:", response.decision)

The same program is in examples/cmd; set PERMGUARD_PDP_URL to point it at another data plane.

A request that names no profile is decided by the ledger's default profile: the manifest permguard init writes declares it, with one partition, cedar. A ledger whose manifest declares other profiles is asked with the profile's name, and its partition inputs are keyed by that profile's partitions.

The request

Field What it says
zone, ledger the ledger whose policies decide, in its zone
profile the profile of the ledger's manifest that selects the partitions to run
subject who asks: a type and an id, with optional properties
resource what is acted on: a type and an id, with optional properties
action what is done: a name, with optional properties
context any other fact the policies read
partition_inputs runtime data for the partitions of the profile, see below
request_id your id for the call, given back in the answer

The answer

A deny is not an exception: it is a successful response whose decision is False. Validation, authorization, availability and server failures raise permguard.Refusal, with their stable error_class and code.

Partition inputs

Runtime data is addressed to the partition name the ledger's profile declares:

from permguard import PartitionInput

request.partition_inputs["cedar"] = PartitionInput(
    type="permguard.cedar.entities.v1",
    data=[
        {
            "uid": {"type": "Team", "id": "engineering"},
            "attrs": {"active": True},
            "parents": [],
        }
    ],
)

The key selects a partition the profile already declares. The input type is checked against that declaration; it does not select a runtime.

Many evaluations at once

Set the defaults on the request, list the evaluations, and call evaluate_many:

from permguard import (
    Action,
    Entity,
    EvaluateRequest,
    Evaluation,
    EvaluationOptions,
    EvaluationsSemantic,
)

response = client.evaluate_many(
    EvaluateRequest(
        zone="acme",
        ledger="main-ledger",
        subject=Entity(type="User", id="alice"),
        evaluations=[
            Evaluation(
                resource=Entity(type="Document", id="budget-2026"),
                action=Action(name="read"),
                request_id="read",
            ),
            Evaluation(
                resource=Entity(type="Document", id="budget-2026"),
                action=Action(name="update"),
                request_id="update",
            ),
        ],
        options=EvaluationOptions(
            evaluations_semantic=EvaluationsSemantic.EXECUTE_ALL,
        ),
    )
)

Each evaluation inherits what it does not set from the request.

Endpoints and options

Endpoint Transport
http:// JSON over HTTP
https:// JSON over HTTPS
grpc:// permguard.data.v1.PolicyDecisionPoint
grpcs:// permguard.data.v1.PolicyDecisionPoint on TLS
with Client(
    "https://pdp.example.com",
    timeout=5.0,
    headers={"authorization": f"Bearer {token}"},
) as client:
    configuration = client.get_configuration()
Keyword Sets
timeout the timeout of every call, in seconds, 5 by default
headers static headers, also sent as gRPC metadata
tls_context the ssl.SSLContext for https://
grpc_credentials the grpc.ChannelCredentials for grpcs://

Every call also takes its own timeout. get_configuration reads the data plane's discovery document. The client reuses its HTTP connection or gRPC channel: use it as a context manager, or call close().

Credentials

In production a data plane admits a call only with an access token of its cluster's Authority Plane, issued to a service account whose scopes include decision.evaluate on that data plane. Obtain one with the account's access key and secret key, then send it on every call as authorization: Bearer <token>, with the header option above.

curl -s -u "$PERMGUARD_ACCESS_KEY:$PERMGUARD_SECRET_KEY" \
  -d grant_type=client_credentials \
  https://permguard.example:8443/authority/v1/token | jq -r .access_token

A token lasts an hour unless asked shorter: obtain another before it expires. The development configurations Permguard ships grant decision.evaluate to everybody, so the quick start needs no token. See the Authority Plane for service accounts, their scopes and keys.

Compatibility

This major version implements permguard.api.pdp.native.v1. Compatibility is tied to that versioned interface, not to a server minor release.

Develop

hatch run protoc
hatch run dev
hatch -e lint run all
hatch build

A release tag publishes to PyPI. The package version is read from permguard/__about__.py and set from the release tag.

License

Apache License 2.0: see LICENSE, NOTICE.md and THIRD_PARTY_NOTICES.md.

Permguard is a trademark of Nitro Agility S.r.l., see TRADEMARKS.md. Python and the Python logos are trademarks of the Python Software Foundation, shown only to name the language this SDK is for.

Metadata

Release files for permguard 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 permguard 0.2.0
File Size Uploaded Provenance Actions
permguard-0.2.0.tar.gz 35.4 kB With provenance Details for permguard-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 63.4 kB

Release files / permguard-0.2.0.tar.gz

Download URL permguard-0.2.0.tar.gz
Size 35.4 kB
Tags Source
SHA-256 checksum
How to use checksums
5425b8a7207b94cac2c50a17a31be323a444445e6d137694a5d528bd201ac415
BLAKE2b-256 checksum
How to use checksums
532fcc053ed937ac472bb91b58bd7a30571d273d7a2b031fd8422b5d8469da8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 19, 2026.

Transparency log

Release files / permguard-0.2.0-py3-none-any.whl

Download URL permguard-0.2.0-py3-none-any.whl
Size 28.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4fc8cd4b6db0fe7d9433660c191dbb70719ad26bf46f7cbafa74b80b5b65526
BLAKE2b-256 checksum
How to use checksums
3c50d286f3b362c5ec1d7ab7032376dc26751ab9ffc15408b872ee6f65ecf3e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 19, 2026.

Transparency log

Security for permguard 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for permguard-0.2.0.tar.gz

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 Nov 19, 2026.

Transparency log

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