Python SDK Examples
Init the SDK
from permit import Permit
permit = Permit(
# the API key to the Permit environment you wish to connect to
token="<YOUR_API_KEY>",
# the url in which the SDK can connect to the PDP container
pdp="http://localhost:7766",
# use this to turn on sdk logs:
log={"level": "debug", "enable": True},
)
Resources
Create a resource
from permit import ResourceRead
document: ResourceRead = await permit.api.resources.create(
{
"key": "document",
"name": "Document",
"urn": "prn:gdrive:document",
"description": "google drive document",
"actions": {
"create": {},
"read": {},
"update": {},
"delete": {},
},
"attributes": {
"private": {
"type": "bool",
"description": "whether the document is private",
},
},
}
)
Update a resource
from permit import ResourceRead
resource_after_changes: ResourceRead = await permit.api.resources.update(
# the key of the resource
"document",
# updated fields
{
"description": "wat",
"actions": {
"find": {}
}
},
)
List all resources
from permit import ResourceRead
resources: List[ResourceRead] = await permit.api.resources.list()