Registry / auth-security / authzed

authzed

JSON →
library1.25.0pypypi✓ verified 22d ago

The `authzed` library is the official Python client for Authzed's SpiceDB, a permissions database and service. It enables developers to define authorization schemas, manage relationships between objects, and perform efficient permission checks within their applications. The library supports both the v1 Core SpiceDB API and the materialize/v0 API for building materialized permission views. It maintains an active development status with regular updates.

pip install authzed
INSTALL
IMPORT
SIG · AUTHZED
A
authzed
auth-securitypythonv1.25.0
Install
3.0s avg
Import
706ms
Disk
41MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.25.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 3.7s
py 3.11
✓ —
✓ 3s
py 3.12
✓ —
✓ 2.6s
py 3.13
✓ —
✓ 2.7s
py 3.9
✕ build_error
✕ build_error
41MB installed
● package 41MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from authzed.api.v1 import Client
bearer_token_credentials
from grpcutil import bearer_token_credentials
from authzed.grpcutil import bearer_token_credentials
`grpcutil` is typically imported directly, not as a submodule of `authzed`.
insecure_bearer_token_credentials
from grpcutil import insecure_bearer_token_credentials
Used for local development without TLS/self-signed certificates.

This quickstart demonstrates how to initialize the Authzed client using an API token and perform a basic permission check. Ensure `SPICEDB_ENDPOINT` and `SPICEDB_API_TOKEN` environment variables are set or replaced with your actual SpiceDB connection details.

import os from authzed.api.v1 import Client, CheckPermissionRequest, ObjectReference, SubjectReference from grpcutil import bearer_token_credentials # Replace with your SpiceDB endpoint and API token from environment variables SPICEDB_ENDPOINT = os.environ.get('SPICEDB_ENDPOINT', 'grpc.authzed.com:443') SPICEDB_API_TOKEN = os.environ.get('SPICEDB_API_TOKEN', 't_your_token_here_1234567deadbeef') if not SPICEDB_API_TOKEN: raise ValueError("SPICEDB_API_TOKEN environment variable not set or is empty.") # Initialize the client with bearer token credentials client = Client( SPICEDB_ENDPOINT, bearer_token_credentials(SPICEDB_API_TOKEN), ) try: # Example: Check if a user 'emilia' can 'view' a document 'first_doc' request = CheckPermissionRequest( resource=ObjectReference(object_type="document", object_id="first_doc"), permission="view", subject=SubjectReference(object=ObjectReference(object_type="user", object_id="emilia")) ) response = client.CheckPermission(request) print(f"Permission check result: {response.permissionship}") except Exception as e: print(f"An error occurred: {e}")
spicedb --version
Debug
Known issues
gotchaWhen developing locally or with self-signed certificates, standard `bearer_token_credentials` might fail due to TLS verification issues. Use `insecure_bearer_token_credentials()` for non-TLS connections or explicitly provide `certChain` for custom certificates.
fix
For local insecure connections: `from grpcutil import insecure_bearer_token_credentials; client = Client('localhost:50051', insecure_bearer_token_credentials('your_token'))`. For self-signed certs: pass the root certificate as `certChain` to `bearer_token_credentials`.
affects: All versions
gotchaThe 'Dual-Write Problem' is a common architectural challenge when integrating Authzed/SpiceDB with an application database. Ensuring consistency between both systems (e.g., when creating a file and its permissions) requires careful handling.
fix
Implement patterns like the transactional outbox to ensure eventual consistency between your application database and SpiceDB. Avoid treating API calls as RPCs that immediately reflect system state.
affects: All versions
gotchaThe `InsecureClient` provided by `authzed-py` uses `grpc.insecure_channel`, which is not inherently compatible with `asyncio`. Attempting to use it with asynchronous operations, especially methods like `LookupResources` that return `UnaryStreamCall`, may lead to authentication errors or unexpected behavior.
fix
For asynchronous use, consider implementing an async-compatible client or using documented workarounds/patterns for async gRPC interactions. Consult the Authzed community for the latest best practices on async usage.
affects: All versions
gotchaPeriodically, specific minor releases may encounter packaging issues that prevent correct installation or module imports, as was observed with `authzed-py v1.22.0`.
fix
If encountering unexpected import errors or installation failures after an update, check the project's GitHub issues for known packaging problems. Pinning to a previous stable version may be necessary until a fix is released (e.g., `pip install authzed==1.21.0`).
affects: ~1.22.0
gotchaAvoid creating cycles in your SpiceDB schema definitions. While recursive schemas can be powerful, incorrect usage or accidental cycles can lead to significant performance issues and unexpected behavior in permission evaluations.
fix
Design schemas carefully to ensure acyclic relationships where possible. If recursion is necessary (e.g., groups having subgroups), ensure the structure directly refers back to itself in a controlled manner, avoiding indirect cycles through other definitions.
affects: All versions
gotchaWhen making permission checks, prefer checking permissions directly rather than relations. If the logic for a check needs to change, modifying a permission definition is significantly easier and safer than changing a relation definition, which often requires a data migration.
fix
Structure your schema so that a permission points to a relation, and then check the permission. Example: `permission read = reader`, then check `document:id#read@user:id` instead of `document:id#reader@user:id` directly.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'authzed'
The 'authzed' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install authzed'.
ImportError: cannot import name 'Client' from 'authzed.api.v1alpha1'
The 'Client' class has been moved from 'authzed.api.v1alpha1' to 'authzed.api.v1'.
fix
Update the import statement to: 'from authzed.api.v1 import Client'.
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAVAILABLE details = "failed to connect to all addresses"
The client is unable to connect to the SpiceDB server, possibly due to incorrect server address or network issues.
fix
Verify the server address and network connectivity; ensure the server is running and accessible.
ValueError: Bearer token must be provided
The 'bearer_token_credentials' function was called without providing a valid API token.
fix
Provide a valid API token when calling 'bearer_token_credentials': 'bearer_token_credentials("your_api_token")'.
TypeError: 'NoneType' object is not callable
Attempting to call a method on a 'None' object, possibly due to a failed client initialization.
fix
Ensure the client is properly initialized before making API calls; check for errors during initialization.
Upgrade
Version history
1.25.0latest on PyPI · released Jul 14, 2026
Audit
Dependencies
grpciorequiredCore dependency for gRPC communication with SpiceDB.
protobufrequiredRequired for Protocol Buffers serialization/deserialization used by gRPC.
protovalidateoptionalOptional dependency for schema validation tooling.
Agent activity
28 hits · last 30 days
node
22
OpenAI (training)
1
Resources
authzed — pip install authzed · libregistry