Skip to main content

Denied SDK for Python

Project description

Denied SDK for Python

A lightweight Python SDK for the Denied authorization platform.

Installation

pip install denied-sdk

Quick Start

from denied_sdk import DeniedClient

client = DeniedClient(api_key="your-api-key")

result = client.check(
    subject="user://alice",
    action="read",
    resource="document://secret",
)

print(result.decision)        # True or False
print(result.context.reason)  # Optional reason string

Configuration

Parameter Environment variable Default
Base URL url DENIED_URL https://api.denied.dev
API Key api_key DENIED_API_KEY -

Configure the SDK by instancing the DeniedClient with the desired parameters.

# with constructor parameters
client = DeniedClient(
    url="https://example.denied.dev",
    api_key="your-api-key",
)

# or with environment variables
client = DeniedClient()

API Reference

check()

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

Signature:

client.check(subject, action, resource, context=None) -> CheckResponse

Arguments:

  • subjectSubject object, dict, or "type://id" string
  • actionAction object, dict, or plain string
  • resourceResource object, dict, or "type://id" string
  • context — optional dict of additional context

Examples:

from denied_sdk import Action, Resource, Subject

# URI string shorthand — simplest
result = client.check(subject="user://alice", action="read", resource="document://123")

# Typed objects — full IDE support and Pydantic validation
result = client.check(
    subject=Subject(type="user", id="alice", properties={"role": "admin"}),
    action=Action(name="read"),
    resource=Resource(type="document", id="123"),
    context={"ip": "192.168.1.1"},
)

bulk_check()

Perform multiple authorization checks in a single request.

Signature:

client.bulk_check(check_requests: list[CheckRequest]) -> list[CheckResponse]

Examples:

from denied_sdk import Action, CheckRequest, Resource, Subject

results = client.bulk_check([
    CheckRequest(
        subject=Subject(type="user", id="alice"),
        action=Action(name="read"),
        resource=Resource(type="document", id="1"),
    ),
    CheckRequest(
        subject=Subject(type="user", id="bob"),
        action=Action(name="write"),
        resource=Resource(type="document", id="1"),
    ),
])

Types

  • Subject / Resourcetype: str, id: str, properties: dict (optional)
  • Actionname: str, properties: dict (optional)
  • CheckRequestsubject, action, resource, context: dict (optional)
  • CheckResponsedecision: bool, context (optional: reason: str, rules: list[str])

Async Client

from denied_sdk import AsyncDeniedClient

async with AsyncDeniedClient(api_key="your-api-key") as client:
    result = await client.check(
        subject="user://alice",
        action="read",
        resource="document://secret",
    )

Requirements

Python >= 3.10

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.5.2.tar.gz (159.7 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.5.2-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for denied_sdk-0.5.2.tar.gz
Algorithm Hash digest
SHA256 a420717616af0a9fce9da109e42853ddf5916230431a345aab340d2775be1af1
MD5 0ee09aacda207a42725bc3f1f7695cab
BLAKE2b-256 95fb5b9601bf48151cb1201756aad0b78869abda595274289b2f17d77aac2a63

See more details on using hashes here.

File details

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

File metadata

  • Download URL: denied_sdk-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for denied_sdk-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 caa6920630611e921c415a3b97a33d1bccdae1f9f83414e9385520c096c8296f
MD5 f97554b07e6762238cb686dc8d13aa17
BLAKE2b-256 5d93918f244e9788444109e891f0a41f487ed3a4a858feb6c8c63f1c491e612a

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