Skip to main content

Permguard Python SDK (Authorization Check) - https://www.permguard.com

Project description

Permguard Python SDK

GitHub License X (formerly Twitter) Follow

Documentation Build, test and publish the artifacts

The Permguard Python SDK provides a simple and flexible client to perform authorization checks against a Permguard Policy Decision Point (PDP) service using gRPC. Plase refer to the Permguard Documentation for more information.


Prerequisites

  • Python 3.8, 3.9, 3.10, 3.11 (supported versions)

This package is compatible with the following Python versions:

  • Programming Language :: Python :: 3.8
  • Programming Language :: Python :: 3.9
  • Programming Language :: Python :: 3.10
  • Programming Language :: Python :: 3.11

Make sure you have one of these versions installed before proceeding.


Installation

Run the following command to install the SDK:

pip install permguard

Usage Example

Below is a sample Python code demonstrating how to create a Permguard client, build an authorization request using a builder pattern, and process the authorization response:

from permguard.az.azreq.builder_principal import PrincipalBuilder
from permguard.az.azreq.builder_request_atomic import AZAtomicRequestBuilder
from permguard.az_client import AZClient
from permguard.az_config import with_endpoint


az_client = AZClient(with_endpoint("localhost", 9094))

principal = PrincipalBuilder("amy.smith@acmecorp.com").build()

entities = [
    {
        "uid": {"type": "MagicFarmacia::Platform::BranchInfo", "id": "subscription"},
        "attrs": {"active": True},
        "parents": [],
    }
]

req = (
    AZAtomicRequestBuilder(
        895741663247,
        "809257ed202e40cab7e958218eecad20",
        "platform-creator",
        "MagicFarmacia::Platform::Subscription",
        "MagicFarmacia::Platform::Action::create",
    )
    .with_request_id("1234")
    .with_principal(principal)
    .with_entities_items("cedar", entities)
    .with_subject_role_actor_type()
    .with_subject_source("keycloack")
    .with_subject_property("isSuperUser", True)
    .with_resource_id("e3a786fd07e24bfa95ba4341d3695ae8")
    .with_resource_property("isEnabled", True)
    .with_action_property("isEnabled", True)
    .with_context_property("time", "2025-01-23T16:17:46+00:00")
    .with_context_property("isSubscriptionActive", True)
    .build()
)

ok, response = az_client.check(req)

if ok:
    print("✅ authorization permitted")
else:
    print("❌ authorization denied")
    if response and response.context:
        if response.context.reason_admin:
            print(f"-> reason admin: {response.context.reason_admin.message}")
        if response.context.reason_user:
            print(f"-> reason user: {response.context.reason_user.message}")
        for eval in response.evaluations:
            if eval.context and eval.context.reason_user:
                print(f"-> reason admin: {eval.context.reason_admin.message}")
                print(f"-> reason user: {eval.context.reason_user.message}")
    if response and response.evaluations:
        for eval in response.evaluations:
            if eval.context:
                if eval.context.reason_admin:
                    print(f"-> evaluation requestid {eval.request_id}: reason admin: {eval.context.reason_admin.message}")
                if eval.context.reason_user:
                    print(f"-> evaluation requestid {eval.request_id}: reason user: {eval.context.reason_user.message}")

Version Compatibility

Our SDK follows a versioning scheme aligned with the PermGuard server versions to ensure seamless integration. The versioning format is as follows:

SDK Versioning Format: x.y.z

  • x.y: Indicates the compatible PermGuard server version.
  • z: Represents the SDK's patch or minor updates specific to that server version.

Compatibility Examples:

  • SDK Version 1.3.0 is compatible with PermGuard Server 1.3.
  • SDK Version 1.3.1 includes minor improvements or bug fixes for PermGuard Server 1.3.

Incompatibility Example:

  • SDK Version 1.3.0 may not be guaranteed to be compatible with PermGuard Server 1.4 due to potential changes introduced in server version 1.4.

Important: Ensure that the major and minor versions (x.y) of the SDK match those of your PermGuard server to maintain compatibility.


Created by Nitro Agility.

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

permguard-0.0.11.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

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

permguard-0.0.11-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file permguard-0.0.11.tar.gz.

File metadata

  • Download URL: permguard-0.0.11.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for permguard-0.0.11.tar.gz
Algorithm Hash digest
SHA256 8bd426307db300eed07ea4545d0fa7033e86a4b5021190d53af3261ca69152ca
MD5 fb9314bc191cfa4707b648f08267a9b3
BLAKE2b-256 cb25145c41066da20695b99a18ac49ad302e51e30c2b09457b557a91bc1c9946

See more details on using hashes here.

Provenance

The following attestation bundles were made for permguard-0.0.11.tar.gz:

Publisher: permguard-python-ci.yml on permguard/permguard-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file permguard-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: permguard-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for permguard-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 3be0c7d5adad18aa2b4e586209902f72fd81ba7323c7991dbdde99862ff590f7
MD5 529b0c87b595f6e8db9c4c0b1a352c3e
BLAKE2b-256 3096840aa4ff4827a0e23cef18986bb6152180de3e555048dffaa9237716e8f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for permguard-0.0.11-py3-none-any.whl:

Publisher: permguard-python-ci.yml on permguard/permguard-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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