The Authzed Python client supports an ORM-like mechanism for easier interaction with the Authzed API..
Starting with a simple set of namespace configurations:
We can translate them into model definitions:
Note here that the
Relation references are well-typed: we indicate the kind of objects that can be applied in the relation.
All API requests to Authzed in the Python client must be made via a
ArrakisClient instance, which keeps a reference to the authentication token for the calling application:
Note that we include the created model definitions in the constructor to
To Check, the client provides the
Let's say we wanted to check if a user has
viewer permission on a document.
To do so via the Python client, we would first construct the objects we are referencing (here, the document and the user):
Next, we would load the most recently stored Zookie for the document from our database:
Finally, we'd issue the check result:
can_view is an object that can be implicitly converted to
To Write, the client provides the
Let's say we wanted to write some permissions for users on some documents:
To do so via the Python client, we would first construct the objects we are referencing (here, the document and the users):
Next, we can call
batch_write to write the permission tuples:
Finally, we save the returned Zookie on the document:
A full example can be found at https://github.com/authzed/authzed-py/tree/main/examples