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.

Download files

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

Source Distribution

slatedb-0.15.0.tar.gz (1.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

slatedb-0.15.0-py3-none-win_amd64.whl (9.1 MB view details)

Uploaded Python 3Windows x86-64

slatedb-0.15.0-py3-none-win32.whl (8.0 MB view details)

Uploaded Python 3Windows x86

slatedb-0.15.0-py3-none-musllinux_1_2_x86_64.whl (10.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

slatedb-0.15.0-py3-none-musllinux_1_2_i686.whl (10.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

slatedb-0.15.0-py3-none-musllinux_1_2_armv7l.whl (10.0 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

slatedb-0.15.0-py3-none-musllinux_1_2_aarch64.whl (10.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

slatedb-0.15.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

slatedb-0.15.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (9.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

slatedb-0.15.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (11.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

slatedb-0.15.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (11.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

slatedb-0.15.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (9.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

slatedb-0.15.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

slatedb-0.15.0-py3-none-macosx_11_0_arm64.whl (9.0 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file slatedb-0.15.0.tar.gz.

File metadata

  • Download URL: slatedb-0.15.0.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for slatedb-0.15.0.tar.gz
Algorithm Hash digest
SHA256 ba202f6dffbe68fd4f36d81297829e989bc180dd3e15ebcac43213e114793065
MD5 2972063a98c47167c205283662d2c32b
BLAKE2b-256 8a0f05d5e995d5eeb22344884c4047ee8d9ad9f3b7d4e3255ff2b4ff60054060

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: slatedb-0.15.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 9.1 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for slatedb-0.15.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4dbffb1692969f71e2b0891f50eef6b17eaabc1072662853f2b6480b092e285b
MD5 816e74a8f7d9510f50b3237ef5655f9a
BLAKE2b-256 60729cb7b8d59a7c2231ba64957844651fece4a59deb24429aa0f30b932b2dac

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-win32.whl.

File metadata

  • Download URL: slatedb-0.15.0-py3-none-win32.whl
  • Upload date:
  • Size: 8.0 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for slatedb-0.15.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 78b5760917d624f187282425c273729bbad7cdf190694f8f0ff7a848ec55ef14
MD5 f0d1c26f1a10a3cf461607771b64e350
BLAKE2b-256 30a5f7ad0fec124b007823daa065128b36c6afbc2491d655648d0913cf297529

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 01b2cb4578d227e743d5545ab74afeaa8d54439a4ee3e9a26655e9aa17e9cd5a
MD5 fb607dbc84046906facbccec2c835d1b
BLAKE2b-256 e0245bed898da274f1c4aa9b00a2873f71e67cab003dffef7c3c66858d53f999

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 dfd9e46ab979b65ea26068dae471b603bd078fff67397c471ffcbbd0a1169372
MD5 f6530b1e607c391042373ed4bbb76029
BLAKE2b-256 486b026d900d7eae7aad082866eec2193987bdfd6e61bc6a9d4db848ee86bf62

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 1aa90bd8d65a853b259c84097ec3e6b1e3b2551de21e035cea4435d1f8dd4f42
MD5 9d18d4583d1e56db2f0dbdebd728218c
BLAKE2b-256 0dd378592555950d3b614e31ff513b680b10170d00294ead9fcec2d00c7ac469

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 85ced7ff12bf59652395c63c2bc1412b9fb2c7a64d5cb953dfe6b886141f9906
MD5 3dbbaf7a180d716a3dea609e9ba56fb7
BLAKE2b-256 0ac45ca455ff7c27d21fa42df349fd8a277c0434b4f362899eac700ab60ef286

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fee3355ecd0fe1c6ece703c3fb2248438cf26528883279f95de00992f04fcfe5
MD5 8e687bc650c4f0b64a2766ab569ad694
BLAKE2b-256 bbb92c6c99cd6b6d831075bf260b44a2885f82a838f59fd5df457e007fe8b1aa

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 5f7b2d9114ebc0c24df2631b76b9284e52efc56494d66179195e8d0c24aa8211
MD5 65713eab6a4016bc7ab60a0771e0b6aa
BLAKE2b-256 dc5e55803e305833d82ae464ed7c4864dff3254d2c89316f42994b707ad53fda

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 a2bbd125c634d0e2520d0167156b21b39d3b77f59b53602cd88c96f547147bd6
MD5 ffd9908ae7edda93a1790db42d28ebf9
BLAKE2b-256 2d2b9c43a02fa857478df58986c3f2c4763ee5ac37dea1c1e29f084598511dbd

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 44952333b2cec28865f473e4044c56ca47d11137201720e54de9535e2fc1159a
MD5 15dd7d878b77190ccd50a19c8c8c4d5c
BLAKE2b-256 497ecdf3a34368be2456803682f816527c7956e3aebf8725295f9673b302b8fe

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 50b1acdcedccf2c15e12e6cdbf9e9d1d851a287260e4624369fef9409594446f
MD5 f899b79d37df276162c324042b2a9271
BLAKE2b-256 b67251a1f923b54f77a83533ecff088ada9c4f23e0cfd6f8c86aaab9a8867979

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 95f134deeb4ed26aed55e21850ddb59b4579315bdfaa3754065b663f8438f2ce
MD5 9d94d1078b3829fc9826f7c6e9661756
BLAKE2b-256 a8a290c378d342fb6b3f67799a4908b3b5776ce4b324c2a98c4bcc74f60b430a

See more details on using hashes here.

File details

Details for the file slatedb-0.15.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for slatedb-0.15.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b7e67f825a2d8c8da950975f9b303239476d0ba5624c59abe4352ae7e5f038a9
MD5 b5412a27c285a31f0cb3b26bb35d10db
BLAKE2b-256 a5f04f6671141a2224dd5ef83aeb7663512f15f0b4077bdc59bcde69b33f96c9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.15.0 This release

14 files

0.14.1

14 files

0.14.0

14 files

0.13.1

14 files

0.13.0

14 files

0.12.1

14 files

0.12.0

14 files

0.11.1

95 files

0.11.0

95 files

0.10.0

95 files

0.9.2

92 files

0.9.0

76 files

0.8.1

77 files

0.8.0

77 files

0.7.0

77 files

0.6.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page