Skip to main content

spicedb-embedded (Python)

Sometimes you need a simple way to run access checks without spinning up a new service. This library provides an embedded version of SpiceDB in various languages. Each implementation is based on a C-shared library (compiled from the SpiceDB source code) with a very thin FFI binding on top of it. This means that it runs the native SpiceDB code within your already-running process.

from spicedb_embedded import EmbeddedSpiceDB
from authzed.api.v1 import (
    CheckPermissionRequest,
    CheckPermissionResponse,
    Consistency,
    ObjectReference,
    Relationship,
    SubjectReference,
)

schema = """
definition user {}

definition document {
    relation reader: user
    permission read = reader
}
"""

rel = Relationship(
    resource=ObjectReference(object_type="document", object_id="readme"),
    relation="reader",
    subject=SubjectReference(
        object=ObjectReference(object_type="user", object_id="alice")
    ),
)

with EmbeddedSpiceDB.start(schema, [rel]) as spicedb:
    req = CheckPermissionRequest(
        consistency=Consistency(fully_consistent=True),
        resource=ObjectReference(object_type="document", object_id="readme"),
        permission="read",
        subject=SubjectReference(
            object=ObjectReference(object_type="user", object_id="alice")
        ),
    )
    resp = spicedb.permissions().CheckPermission(req)
    allowed = (
        resp.permissionship == CheckPermissionResponse.PERMISSIONSHIP_HAS_PERMISSION
    )

Who should consider using this?

If you want to spin up SpiceDB, but don't want the overhead of managing another service, this might be for you.

If you want an embedded server for your unit tests and don't have access to Docker / Testcontainers, this might be for you.

If you have a schema and set of permissions that are static / readonly, this might be for you.

Who should avoid using this?

If you live in a world of microservices that each need to perform permission checks, you should almost certainly spin up a centralized SpiceDB deployment.

How does storage work?

The default datastore is "memory" (memdb). If you use this datastore, keep in mind that it will reset on each app startup. This is a great option if you can easily provide your schema and relationships at runtime. This way, there are no external network calls to check relationships at runtime.

If you need a longer term storage, you can use any SpiceDB-compatible datastores.

from spicedb_embedded import EmbeddedSpiceDB, StartOptions

# Run migrations first: spicedb datastore migrate head --datastore-engine postgres --datastore-conn-uri "postgres://..."
schema = """
definition user {}

definition document {
    relation reader: user
    permission read = reader
}
"""

options = StartOptions(
    datastore="postgres",
    datastore_uri="postgres://user:pass@localhost:5432/spicedb",
)

with EmbeddedSpiceDB.start(schema, [], options=options) as spicedb:
    # Use full Permissions API (writeRelationships, checkPermission, etc.)
    pass

Running code written in Go compiled to a C-shared library within my service sounds scary

It is scary! Using a C-shared library via FFI bindings introduces memory management in languages that don't typically have to worry about it.

That being said, the SpiceDB code still runs in a Go runtime with garbage collection, which is where the vast majority of time is spent. To help mitigate some of the risk, the FFI layer is kept as straightforward as possible. protobuf is marshalled and unmarshalled at the FFI <--> language runtime boundary in a standardized way. After unmarshalling, requests are sent directly to the SpiceDB server, and responses are returned directly back to the language runtime (after marshalling).

Installation

pip install spicedb-embedded

Or from source:

cd python && pip install -e .

Prerequisites: Go 1.23+ with CGO enabled. Build the shared library first:

cd shared/c && CGO_ENABLED=1 go build -buildmode=c-shared -o libspicedb.dylib .  # macOS
cd shared/c && CGO_ENABLED=1 go build -buildmode=c-shared -o libspicedb.so .      # Linux

The library looks for libspicedb.dylib (macOS) or libspicedb.so (Linux) in SPICEDB_LIBRARY_PATH or relative to the working directory (shared/c, ../shared/c, etc.). Override with SPICEDB_LIBRARY_PATH=/path/to/shared/c.

Usage

from spicedb_embedded import EmbeddedSpiceDB
from authzed.api.v1 import (
    CheckPermissionRequest,
    CheckPermissionResponse,
    Consistency,
    ObjectReference,
    Relationship,
    SubjectReference,
)

schema = """
definition user {}

definition document {
    relation reader: user
    permission read = reader
}
"""

rel = Relationship(
    resource=ObjectReference(object_type="document", object_id="readme"),
    relation="reader",
    subject=SubjectReference(
        object=ObjectReference(object_type="user", object_id="alice")
    ),
)

with EmbeddedSpiceDB.start(schema, [rel]) as spicedb:
    stub = spicedb.permissions()
    req = CheckPermissionRequest(
        consistency=Consistency(fully_consistent=True),
        resource=ObjectReference(object_type="document", object_id="readme"),
        permission="read",
        subject=SubjectReference(
            object=ObjectReference(object_type="user", object_id="alice")
        ),
    )
    resp = stub.CheckPermission(req)
    allowed = (
        resp.permissionship == CheckPermissionResponse.PERMISSIONSHIP_HAS_PERMISSION
    )

API

  • EmbeddedSpiceDB.start(options=) — Start an instance without bootstrapping schema or relationships. Supports context manager (with).
  • EmbeddedSpiceDB.start(schema, relationships, options=) — Start an instance and bootstrap it with schema and optional relationships. Supports context manager (with).
  • permissions() — Permissions service stub (CheckPermission, WriteRelationships, ReadRelationships, etc.).
  • schema() — Schema service stub (ReadSchema, WriteSchema, ReflectSchema, etc.).
  • watch() — Watch service stub for relationship changes.
  • channel() — Underlying gRPC channel for custom usage.
  • close() — Dispose the instance and close the channel.

Use types from authzed.api.v1 (ObjectReference, SubjectReference, Relationship, etc.).

StartOptions

from spicedb_embedded import EmbeddedSpiceDB, StartOptions

options = StartOptions(
    datastore="memory",  # or "postgres", "cockroachdb", "spanner", "mysql"
    datastore_uri="postgres://user:pass@localhost:5432/spicedb",  # required for remote
)

with EmbeddedSpiceDB.start(schema, [], options=options) as spicedb:
    ...

Metrics & Tracing

Metrics are disabled by default. Set metrics_enabled=True to turn them on.

Prometheus — exposes http://localhost:9090/metrics for scraping:

options = StartOptions(
    metrics_enabled=True,
    metrics_port=9090,
)

OpenTelemetry traces — pushes to an OTLP gRPC collector (insecure):

options = StartOptions(
    metrics_enabled=True,
    otlp_endpoint="localhost:4317",
    otlp_service_name="my-app-spicedb",  # service.name on SpiceDB's spans; default "spicedb"
)

With opentelemetry-api installed (pip install "spicedb-embedded[opentelemetry]"), every call carries the current OpenTelemetry context, so SpiceDB's spans join your trace as children of the span that made the call and follow its sampling decision. Without it, each call starts its own trace.

Both can be combined. datastore_metrics_enabled and cache_metrics_enabled default to True when metrics_enabled is set; pass False to opt out of either.

Metadata

Release files for spicedb-embedded 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spicedb-embedded 0.8.0
File Size Uploaded Provenance Actions
spicedb_embedded-0.8.0.tar.gz 11.7 kB With provenance Details for spicedb_embedded-0.8.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for spicedb-embedded 0.8.0
File Actions
spicedb_embedded-0.8.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for spicedb_embedded-0.8.0-py3-none-win_amd64.whl
spicedb_embedded-0.8.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for spicedb_embedded-0.8.0-py3-none-manylinux_2_28_x86_64.whl
spicedb_embedded-0.8.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for spicedb_embedded-0.8.0-py3-none-manylinux_2_28_aarch64.whl
spicedb_embedded-0.8.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for spicedb_embedded-0.8.0-py3-none-macosx_11_0_arm64.whl

Total release size: 21.4 MB

Release files / spicedb_embedded-0.8.0.tar.gz

Download URL spicedb_embedded-0.8.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5725b1dd9a045abbc11cb794a5a9d5082fb5d70831cf82d38c4a6f9f154562b8
BLAKE2b-256 checksum
How to use checksums
c56a8e24b3d5db73c487467b47177df7bd9ee9cf838b2b41e59725f7e4b0064e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / spicedb_embedded-0.8.0-py3-none-win_amd64.whl

Download URL spicedb_embedded-0.8.0-py3-none-win_amd64.whl
Size 11.2 kB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
3f13c78e504f12307ff450d227d41f65a04c94a80918c269df248d2ebc57199f
BLAKE2b-256 checksum
How to use checksums
33371c26146ab28b366755ab9e76e7b26ee44e6977f781f56e11f3fa08f0d05c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / spicedb_embedded-0.8.0-py3-none-manylinux_2_28_x86_64.whl

Download URL spicedb_embedded-0.8.0-py3-none-manylinux_2_28_x86_64.whl
Size 11.2 kB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
1ba34ccec9deb6b7952084f96792ea3c1feb7ec11ea0ec2e5ac07dafa99a6b0f
BLAKE2b-256 checksum
How to use checksums
b1e1f1dc466182bb2fb213a9acf53e2afb6b4d481f76e303825f44124f7e3ca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / spicedb_embedded-0.8.0-py3-none-manylinux_2_28_aarch64.whl

Download URL spicedb_embedded-0.8.0-py3-none-manylinux_2_28_aarch64.whl
Size 11.2 kB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
0c38f5df2dc673420a1d75592ff184b4398f4584eb04fce685aa1b70b187b133
BLAKE2b-256 checksum
How to use checksums
b63525700ade0ded0be643a0f84364910a674fa4b91fcc0b5f98a199f72a719f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / spicedb_embedded-0.8.0-py3-none-macosx_11_0_arm64.whl

Download URL spicedb_embedded-0.8.0-py3-none-macosx_11_0_arm64.whl
Size 21.3 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2b4232cf3de02aa29beeca74ac990c804b30e5148222f19418b9dc772541413d
BLAKE2b-256 checksum
How to use checksums
9e4c0622d0436784fd4abf66966abdabbfb57e3ceab67d58dc549f76ee1f95c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Security for spicedb-embedded 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for spicedb_embedded-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.8.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page