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.1.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.1-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: denied_sdk-0.5.1.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.1.tar.gz
Algorithm Hash digest
SHA256 170ffb224aee3b80084ca4206a7ae5b8401598ea058b9fe7940c76f2261889d8
MD5 d7905ed67e2f6dd2d6cda643a0e40dd8
BLAKE2b-256 067a0b2e8d99b93aa4fa6685d4f346ccf2bde5febfc62eea0ca2a28c09342949

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for denied_sdk-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1f9a052f09855d357f82d60eed926c4f97a2e9f085efa5c14ef7b27892432ae
MD5 c523ad700409aa288e748f3fcbd6cf81
BLAKE2b-256 41d2e5d01c8732ae4864a4e1057a4fbbc20c7f062ebbbcce4ad84ff0c368439f

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