Skip to main content

A cloud native embedded storage engine built on object storage.

Project description

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.

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

slatedb-0.14.0.tar.gz (939.0 kB view details)

Uploaded Source

Built Distributions

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

slatedb-0.14.0-py3-none-win_amd64.whl (8.9 MB view details)

Uploaded Python 3Windows x86-64

slatedb-0.14.0-py3-none-win32.whl (7.8 MB view details)

Uploaded Python 3Windows x86

slatedb-0.14.0-py3-none-musllinux_1_2_x86_64.whl (10.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

slatedb-0.14.0-py3-none-musllinux_1_2_i686.whl (10.4 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

slatedb-0.14.0-py3-none-musllinux_1_2_armv7l.whl (9.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

slatedb-0.14.0-py3-none-musllinux_1_2_aarch64.whl (10.3 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

slatedb-0.14.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

slatedb-0.14.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (9.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

slatedb-0.14.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (11.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

slatedb-0.14.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (10.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

slatedb-0.14.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (9.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

slatedb-0.14.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (10.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

slatedb-0.14.0-py3-none-macosx_11_0_arm64.whl (8.7 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.14.0.tar.gz
Algorithm Hash digest
SHA256 8517622a7d08d970da2bb3562292faae8fed461ef1189c52474fb381dbd71a31
MD5 894fb655a1357a60079f857708d74b93
BLAKE2b-256 82e2c678894b1dade8e1404e1196777bf0644ac3b02c964a6bdcc472e96b04ab

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.14.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 1037f2c01849da1918e9f55d5cf05e3480bf90f1f4855f6f505cdd556348ef30
MD5 a20c3583049df8aed3214ed55fcc2b31
BLAKE2b-256 c6c3146869cede108b8c2150f860a05b6c50b3013c93ed7c66283db2497a0803

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.14.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 76ff717d784336343b21ddfadd43efc3fbe7c17b5758893804af7bb295833cac
MD5 55d2d61ea9371dce4a272a4e3242337f
BLAKE2b-256 071c5ebc3d54177afd5d638335a1baf25bec3539ded6f36f7b54dabc6d1933b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1872071ad15a8b9d89b62975d5d97cecadde137ba631bca90aefdc05df767296
MD5 d495cb0dacdef5a1d9c415e34a6face8
BLAKE2b-256 d694eeae7a4f8354cbd0eb9b6dfb7833742b1e2ac761cdc92625db291334d2cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c28a3664b370c900c762f806f4eba43354445a53f1271ba5124741a523eb799e
MD5 951ddeab59fe41462020d9379d7164f5
BLAKE2b-256 eefa524bc40d8c8b0f49369cfaf9b035dcafc85217f3b261066fd59a33e2441f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 e9eef03a6e7d14f3c3ae4ce42cfb0a358a75c701ff4e6997cfed4e116ea57039
MD5 be920f913103bc49b8236a8bf7df6d3f
BLAKE2b-256 c7940a37595d0b4dc3337d8b25adea4dd051b4c72eee08088b02ea9f7e39f1ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c781f9c34307d68e8c72213bb2e4429193dba55f83c17cd2d15106a801a0d1ba
MD5 da1267a2f345a7d6f5dfdcfd7c6ffdc4
BLAKE2b-256 a6970a86f0d8739f5e24dfb39b4a1bbe2dd44ca838940666be0870c40d8db6c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 94d230aa1a4635e5325e1a37dd7dda848570bb0b2b40c9001a8d3e6eac4dfda5
MD5 38522f578c3d816f877cbb17163f7000
BLAKE2b-256 24b45bbd7f5671b6c55684685209497d1de88e55babddc0a90cbe35cafd6c1ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 66d153fb81e8a435a4ac585dd9ca5c5813dc4305017aebffd8b30f2226129e5e
MD5 26252289bd292548436d418cc865c9be
BLAKE2b-256 2c3fc2bb1b3366e89150d23013ddd2ac2fe57a0a1cde8cfcb667025b27758ab2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 b289c3e656c6d12186dfe3c28b0ae7e56c01d26a25e8354eab37a6c9dd71903a
MD5 3ca70b046c7794535699ba3014e3e227
BLAKE2b-256 381692e1184d44159ddf16617aabc1bb6954cc999dce6629e2520d40779a4b28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e5481775078c3d7760eafc09d772ce23816e6eaa5db52a08b571fcaae2ab1aab
MD5 1af649b47ff42fa199c3013811ece73b
BLAKE2b-256 6304fdefb204e833a6cad8c7118521d6785a39cfc89ee5012f6bbcd4ed40c99f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 7468d9b141ced8210cd5ec3d735aacbafc05b96b0f623a56bb6be8ccab7ba55c
MD5 2cca7de6fbba5982a902cbcc0ca731a1
BLAKE2b-256 7e05242084fd2ffab393a6018fd1b9aca785997525d5af1fb2217b16ab0994cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 942781f148e6d84418d623b62939b78a2bf079d8857275b855717f51a88dc454
MD5 1936f34a1d6947d160b5d355a38e0706
BLAKE2b-256 6620d5d5e53c9baf84a718de1bfe976c7bead3df6e1bee7fd90e55efbd51a999

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 096d4a3aba48f16e57e6c2953562ce2fbd6ddf5714a4cc24f12d2e243af81f25
MD5 68004d3ff48f7b227bd068b7c6c322d4
BLAKE2b-256 37e7456975941bd3bf494148d634abe99532b27f6f3d9ee6e2d4a29b5b063344

See more details on using hashes here.

Supported by

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