Skip to main content

An unofficial SpiceDB client for Python.

Project description

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"]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spicedb-0.1.0a2.tar.gz (8.1 kB view hashes)

Uploaded Source

Built Distribution

spicedb-0.1.0a2-py3-none-any.whl (9.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page