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:
urlparameter orDENIED_URLenvironment variable (default:http://localhost:8421) - API Key:
api_keyparameter orDENIED_API_KEYenvironment 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 principalresource_uri(str, optional): The identifier of the resourceprincipal_attributes(dict, optional): The attributes of the principalresource_attributes(dict, optional): The attributes of the resourceaction(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: PrincipalCheckresource: ResourceCheckaction: str
CheckResponse
Authorization check response with:
allowed: boolreason: str | None
Requirements
- Python >= 3.10
- httpx >= 0.28.1
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27f195ec9306a51693ae06b4a1e2c94dc24523488b416cfe484a2ea2b25dc51f
|
|
| MD5 |
19a524bf555560aeb7766b6fea3c587f
|
|
| BLAKE2b-256 |
3078a579249c9ff29e7dcd540392d0cf103a35e5430e4ccc0b0258c4ed174352
|
File details
Details for the file denied_sdk-0.4.0-py3-none-any.whl.
File metadata
- Download URL: denied_sdk-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
354a23a704c0c9c972e99950a4288f3ed684cc26a356755b64b9aa873a2a73f7
|
|
| MD5 |
cf22a0a1d9f6725890253761ca69acce
|
|
| BLAKE2b-256 |
91d2f606f5b58c4444d84f44a783648e0a0a2ef01d79e5199e48c6fff84c48f9
|