Skip to main content

Denied SDK for Python

Project description

Denied SDK for Python

A lightweight Python SDK for the Denied authorization platform.

Installation

uv add denied-sdk

Or with pip:

pip install denied-sdk

Quick Start

from denied_sdk import DeniedClient

# Initialize the client
client = DeniedClient(url="http://localhost:8421", api_key="your-api-key")

# Check authorization
result = client.check(
    principal_uri="user:alice",
    resource_uri="document:secret",
    action="read"
)

print(f"Allowed: {result.allowed}")
if result.reason:
    print(f"Reason: {result.reason}")

Configuration

The SDK can be configured using constructor parameters or environment variables:

  • URL: url parameter or DENIED_URL environment variable (default: http://localhost:8421)
  • API Key: api_key parameter or DENIED_API_KEY environment variable
# Using environment variables
import os
os.environ["DENIED_URL"] = "https://denied.example.com"
os.environ["DENIED_API_KEY"] = "your-api-key"

client = DeniedClient()  # Will use environment variables

API Reference

check()

Check whether a principal has permissions to perform an action on a resource.

Parameters:

  • principal_uri (str, optional): The identifier of the principal
  • resource_uri (str, optional): The identifier of the resource
  • principal_attributes (dict, optional): The attributes of the principal
  • resource_attributes (dict, optional): The attributes of the resource
  • action (str, optional): The action to check (default: "access")

Returns: CheckResponse with allowed (bool) and optional reason (str)

Examples:

# Check with URIs
result = client.check(
    principal_uri="user:alice",
    resource_uri="document:123",
    action="read"
)

# Check with attributes
result = client.check(
    principal_attributes={"role": "admin"},
    resource_attributes={"type": "document", "classification": "secret"},
    action="write"
)

# Mix URIs and attributes
result = client.check(
    principal_uri="user:bob",
    resource_attributes={"type": "public"},
    action="access"
)

bulk_check()

Perform multiple permission checks in a single request.

Parameters:

  • check_requests (list[CheckRequest]): List of check requests

Returns: list[CheckResponse]

Example:

from denied_sdk import CheckRequest, PrincipalCheck, ResourceCheck, EntityType

requests = [
    CheckRequest(
        principal=PrincipalCheck(uri="user:alice", attributes={}),
        resource=ResourceCheck(uri="document:1", attributes={}),
        action="read"
    ),
    CheckRequest(
        principal=PrincipalCheck(uri=None, attributes={"role": "viewer"}),
        resource=ResourceCheck(uri=None, attributes={"type": "public"}),
        action="access"
    ),
]

results = client.bulk_check(requests)
for result in results:
    print(f"Allowed: {result.allowed}")

Types

EntityType

Enum for entity types:

  • EntityType.Principal: Represents a principal (user, service, etc.)
  • EntityType.Resource: Represents a resource

CheckRequest

Authorization check request with:

  • principal: PrincipalCheck
  • resource: ResourceCheck
  • action: str

CheckResponse

Authorization check response with:

  • allowed: bool
  • reason: str | None

Requirements

  • Python >= 3.10
  • httpx >= 0.28.1

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

denied_sdk-0.4.0.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

denied_sdk-0.4.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file denied_sdk-0.4.0.tar.gz.

File metadata

  • Download URL: denied_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for denied_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 27f195ec9306a51693ae06b4a1e2c94dc24523488b416cfe484a2ea2b25dc51f
MD5 19a524bf555560aeb7766b6fea3c587f
BLAKE2b-256 3078a579249c9ff29e7dcd540392d0cf103a35e5430e4ccc0b0258c4ed174352

See more details on using hashes here.

File details

Details for the file denied_sdk-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for denied_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 354a23a704c0c9c972e99950a4288f3ed684cc26a356755b64b9aa873a2a73f7
MD5 cf22a0a1d9f6725890253761ca69acce
BLAKE2b-256 91d2f606f5b58c4444d84f44a783648e0a0a2ef01d79e5199e48c6fff84c48f9

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