An unofficial SpiceDB client for Python. https://pypi.org/project/spicedb
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2024-06-18 16:12:53 +07:00
spicedb feat: implement reverse lookup 2024-06-18 16:03:31 +07:00
.gitignore Initial commit 2024-06-15 19:10:54 +07:00
LICENSE Initial commit 2024-06-15 19:10:54 +07:00
NOTICE Initial commit 2024-06-15 19:10:54 +07:00
poetry.lock Initial commit 2024-06-15 19:10:54 +07:00
poetry.toml Initial commit 2024-06-15 19:10:54 +07:00
pyproject.toml release: 0.1.0a2 2024-06-18 16:12:53 +07:00
README.md Initial commit 2024-06-15 19:10:54 +07:00

spicedb-python

An unofficial SpiceDB client for Python.

pip install spicedb

Note that this is a very unstable package and the API is subject to change.

Getting started

Initialize the client:

from spicedb import SpiceDB, SpiceRelationship

client = SpiceDB("https://api.spicedb.example.net/", "API_KEY")

Set up a schema:

await client.write_schema("""
    definition user {}

    definition team {
        relation admin: user
        relation member: user
    }

    definition project {
        relation parent: team

        permission view = parent->member
        permission edit = parent->admin
    }
""")

Create some relationships:

alice = {"type": "user", "id": "alice"}
bob = {"type": "user", "id": "bob"}
team = {"type": "team", "id": "acme-co"}
cool_project = {"type": "project", "id": "cool_project"}

await client.bulk(
    create=[
        SpiceRelationship(team, "parent", cool_project),
        SpiceRelationship(alice, "admin", team),
        SpiceRelationship(bob, "member", team),
    ],
)

Check permissions:

await client.authorize(alice, "edit", cool_project)  # => True
await client.authorize(bob, "edit", cool_project)    # => False

List resources:

await client.list(alice, "edit", "project")  # => ["cool_project"]