Skip to main content

SlateDB Python Binding

bindings/python contains the official UniFFI-based Python package for SlateDB.

Requirements

  • Python 3.10 or newer

Install

pip install slatedb

API Model

  • ObjectStore.resolve(...) opens an object store from a URL such as memory:///
  • DbBuilder opens a writable database and DbReaderBuilder opens a read-only reader
  • most database operations are async and should be used with asyncio
  • WriteBatch is mutated synchronously and then consumed by db.write(...)
  • db.shutdown() and reader.shutdown() explicitly close native resources

Quick Start

import asyncio

from slatedb.uniffi import (
    DbBuilder,
    IsolationLevel,
    KeyRange,
    ObjectStore,
    WriteBatch,
)


async def main() -> None:
    store = ObjectStore.resolve("memory:///")
    builder = DbBuilder("demo-db", store)
    db = await builder.build()

    try:
        await db.put(b"user:1", b"Alice")
        value = await db.get(b"user:1")
        assert value == b"Alice"

        batch = WriteBatch()
        batch.put(b"user:2", b"Bob")
        batch.put(b"user:3", b"Carol")
        await db.write(batch)

        scan = await db.scan_prefix(
            b"user:",
            KeyRange(
                start=None,
                start_inclusive=False,
                end=None,
                end_inclusive=False,
            ),
        )
        while (row := await scan.next()) is not None:
            print(row.key, row.value)

        tx = await db.begin(IsolationLevel.SERIALIZABLE_SNAPSHOT)
        await tx.put(b"user:4", b"Dora")
        await tx.commit()
    finally:
        await db.shutdown()


asyncio.run(main())

Metrics

The Python binding exposes both custom metrics callbacks and the built-in DefaultMetricsRecorder:

  • DbBuilder.with_metrics_recorder(...)
  • DbReaderBuilder.with_metrics_recorder(...)
  • DefaultMetricsRecorder.snapshot()
  • DefaultMetricsRecorder.metrics_by_name(...)
  • DefaultMetricsRecorder.metric_by_name_and_labels(...)

Example:

from slatedb.uniffi import DbBuilder, DefaultMetricsRecorder, ObjectStore

store = ObjectStore.resolve("memory:///")
recorder = DefaultMetricsRecorder()
builder = DbBuilder("metrics-demo", store)

builder.with_metrics_recorder(recorder)
db = await builder.build()

try:
    await db.put(b"hello", b"world")

    metric = recorder.metric_by_name_and_labels("slatedb.db.write_ops", [])
    if metric is not None and metric.value.is_counter():
        print(metric.value[0])
finally:
    await db.shutdown()

Runtime Notes

Writable databases and readers enter a dedicated multi-threaded Tokio runtime while opening so SlateDB's long-lived background tasks capture a multi-threaded Tokio handle. Foreground binding calls are still awaited through the normal Python async API. By default, the runtime uses the host's available parallelism. Set SLATEDB_UNIFFI_RUNTIME_THREADS to a positive integer before the first DbBuilder.build() or DbReaderBuilder.build() call to override the worker thread count for the lifetime of the process.

Local Development

This package reuses the shared Rust UniFFI crate at ../uniffi/Cargo.toml. The generated Python module under slatedb/uniffi/_slatedb_uniffi/ is build output and should not be edited by hand.

Editable Build

From the repository root:

cd bindings/python
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install maturin "uniffi-bindgen==0.31.0" ruff
maturin develop
ruff check .
python -c "import slatedb; import slatedb.uniffi; from slatedb.uniffi import *"

Run Tests

From bindings/python after building the extension with test extras:

maturin develop --extras test
pytest

Build Release Artifacts

From bindings/python:

maturin build
maturin sdist

Editable builds generate slatedb/uniffi/_slatedb_uniffi/ in-tree. If you switch from maturin develop to maturin build in the same checkout, remove that generated directory first or run the artifact build from a fresh checkout.

License

SlateDB is licensed under the Apache License, Version 2.0.

Metadata

Release files for slatedb 0.16.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 slatedb 0.16.0
File Size Uploaded
slatedb-0.16.0.tar.gz 1.1 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for slatedb 0.16.0
File
slatedb-0.16.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
slatedb-0.16.0-py3-none-win32.whl Python 3 none Windows x86-32 Details
slatedb-0.16.0-py3-none-musllinux_1_2_x86_64.whl Python 3 none Linux musl 1.2+ x86-64 Details
slatedb-0.16.0-py3-none-musllinux_1_2_i686.whl Python 3 none Linux musl 1.2+ x86-32 Details
slatedb-0.16.0-py3-none-musllinux_1_2_armv7l.whl Python 3 none Linux musl 1.2+ ARMv7l Details
slatedb-0.16.0-py3-none-musllinux_1_2_aarch64.whl Python 3 none Linux musl 1.2+ ARM64 Details
slatedb-0.16.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details
slatedb-0.16.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl Python 3 none Linux glibc 2.17+ IBM System/390x Details
slatedb-0.16.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl Python 3 none Linux glibc 2.17+ PowerPC 64-le Details
slatedb-0.16.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl Python 3 none Linux glibc 2.17+ x86-32 Details
slatedb-0.16.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl Python 3 none Linux glibc 2.17+ ARMv7l Details
slatedb-0.16.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details
slatedb-0.16.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 131.7 MB

Release files / slatedb-0.16.0.tar.gz

Download URL slatedb-0.16.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
77d143462260facd3e014bf2e5cd358fa1b39140c63e7ea549d0031fc025d1a4
BLAKE2b-256 checksum
How to use checksums
7dcf95dd581901017626b648385f8b9f0144ec0813b40508f4944a20b2c90259
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-win_amd64.whl

Download URL slatedb-0.16.0-py3-none-win_amd64.whl
Size 9.1 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
db77dbee70b1d77ad7c83eb68972e6de289d438797af39e7862ab18ce36eb12a
BLAKE2b-256 checksum
How to use checksums
42e54cc1e03c3d86792ad4f5a8161477dadba7cb68d18189da19bdd0158085b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-win32.whl

Download URL slatedb-0.16.0-py3-none-win32.whl
Size 8.0 MB
Tags Python 3 Windows x86-32
SHA-256 checksum
How to use checksums
2f56118633bf5bc066a408b92505600d46ac3fd05c6fc963c4134676999e665c
BLAKE2b-256 checksum
How to use checksums
e0afe96cb33963df2d89acd16687a616d1fafb8d45d89cfa6d6d4d15a70ed568
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-musllinux_1_2_x86_64.whl

Download URL slatedb-0.16.0-py3-none-musllinux_1_2_x86_64.whl
Size 10.8 MB
Tags Linux musl 1.2+ x86-64 Python 3
SHA-256 checksum
How to use checksums
e5b748cb2bfc9d74935d29c2805251576b8b409002cf3659f8d01120f4f49d24
BLAKE2b-256 checksum
How to use checksums
cf486a46ffce6afd92f825051713a25c5676080fe798134992a66c145fa89113
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-musllinux_1_2_i686.whl

Download URL slatedb-0.16.0-py3-none-musllinux_1_2_i686.whl
Size 10.6 MB
Tags Linux musl 1.2+ x86-32 Python 3
SHA-256 checksum
How to use checksums
8fa0ca6ce9d8854ae1b84175d39a732abd4d8c271e29604e9d8eb5c3eadffe67
BLAKE2b-256 checksum
How to use checksums
556977c424db693929f348afc381f1b1f78098ec46794b7f1edb33305ab26e08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-musllinux_1_2_armv7l.whl

Download URL slatedb-0.16.0-py3-none-musllinux_1_2_armv7l.whl
Size 10.0 MB
Tags Linux musl 1.2+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
30b2a0c795ff8179921aaba7ab044a3cb11073bf0bd25bfe1023403b1d9ebef7
BLAKE2b-256 checksum
How to use checksums
cf6be86dbe1624668657c8961f6bf95a1a1b4c63a81079a1668f68b5f97efae7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-musllinux_1_2_aarch64.whl

Download URL slatedb-0.16.0-py3-none-musllinux_1_2_aarch64.whl
Size 10.6 MB
Tags Linux musl 1.2+ ARM64 Python 3
SHA-256 checksum
How to use checksums
5cf97be45cf52b852683739450d9f6bfd498a86830479e70ffd38a0478c16816
BLAKE2b-256 checksum
How to use checksums
ee450dad4e2f1b2491e3b021fad76f68b9f7699b83d450b42793efc405ab2259
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL slatedb-0.16.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 10.4 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
1d6d10481adaf98f1d84dc4efa72d79bb3128e40f0aca1daae1039527f20fbe9
BLAKE2b-256 checksum
How to use checksums
97905c8290b976dab2412b4f23ad261a725a632f6e786d523c8edc8df4ffedcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL slatedb-0.16.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 9.7 MB
Tags Linux glibc 2.17+ IBM System/390x Python 3
SHA-256 checksum
How to use checksums
7aac6ea7a1ea8776fcf960dfe5c07b57fab3bd19fd51ee2a60040095233d02c2
BLAKE2b-256 checksum
How to use checksums
8b49d989a7cebd33da43e94b95215c07e015bf9aabfa2c773810872fcfefe2fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL slatedb-0.16.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 11.4 MB
Tags Linux glibc 2.17+ PowerPC 64-le Python 3
SHA-256 checksum
How to use checksums
f52bc1a30278e382648e222562d6938c847deb43401958b5bdce1835ba611d1f
BLAKE2b-256 checksum
How to use checksums
0f7ffbc940d1ae9ecdd69559677c259f4139545e8232bdc61ef0eaec44c97c5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL slatedb-0.16.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Size 10.9 MB
Tags Linux glibc 2.17+ x86-32 Python 3
SHA-256 checksum
How to use checksums
086f1a0b1457d7ea02f7b9e5a47e0cd25aeb18c449336f12b3d56848d9f8e866
BLAKE2b-256 checksum
How to use checksums
3783d1e6e812d9b8ef2b6f5977e74dbef88b9c4d94ec6bb44e1b9ce65a890618
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL slatedb-0.16.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 9.7 MB
Tags Linux glibc 2.17+ ARMv7l Python 3
SHA-256 checksum
How to use checksums
9b9f12a770b550f3075132a9bdbfe472ab71ce676d4ba98f6d5b6372ca0537ca
BLAKE2b-256 checksum
How to use checksums
25aae527098dc0b39bc9ef24c19f1a8f8976b817b86557bda80dc0a5280def08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL slatedb-0.16.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 10.4 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
221265c36c2da4404123f334292efb6d4f780386fb486f9b30220c46b054e126
BLAKE2b-256 checksum
How to use checksums
1859e8b24b2f39e7dbe112c281e746f23e167a7660d736cc8eab671cb8d3afb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release files / slatedb-0.16.0-py3-none-macosx_11_0_arm64.whl

Download URL slatedb-0.16.0-py3-none-macosx_11_0_arm64.whl
Size 9.0 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
14869014b93d3c5edeabd207ffe1f372c3759a4cf3b1c6ee12e1affca73351f7
BLAKE2b-256 checksum
How to use checksums
e7d1599e9528ce87dcea14564fa3ac6734218be2c830f20baf2721be44e82e4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

This release

0.16.0 This release

14 release files

0.9.2

92 release files

0.8.0

77 release files

0.6.1

2 release files

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