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 authzedVerified import paths — ran on the pinned version, not inferred.
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.
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`.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.
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.
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`).
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.
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.
Install the package using pip: 'pip install authzed'.
Update the import statement to: 'from authzed.api.v1 import Client'.
Verify the server address and network connectivity; ensure the server is running and accessible.
Provide a valid API token when calling 'bearer_token_credentials': 'bearer_token_credentials("your_api_token")'.Ensure the client is properly initialized before making API calls; check for errors during initialization.