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.1.tar.gz (942.9 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.1-py3-none-win_amd64.whl (8.9 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

slatedb-0.14.1-py3-none-musllinux_1_2_x86_64.whl (10.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

slatedb-0.14.1-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.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (9.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

slatedb-0.14.1-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.1.tar.gz.

File metadata

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

File hashes

Hashes for slatedb-0.14.1.tar.gz
Algorithm Hash digest
SHA256 479cd0f4af1a6bd2f61142e4af8a179817d9640ab88a3a67ea6fa57596213eae
MD5 28929a7a06036e11007b61cc56045164
BLAKE2b-256 5bc3fddc557b9cba601173a40521676e9dcbc8eeaa8dd85a3334c78683195f1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slatedb-0.14.1-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.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e8cbe3f7c23b6044f97ba09c0aeb1c54f80a2a7fab3c53bbeb0b6dc3d2aab123
MD5 719788b5822f261ca1e2b558929ffcec
BLAKE2b-256 9605ad4dd83ffade3522230c7f09895cafdae132092de839f18eca06fcacefa5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slatedb-0.14.1-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.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 07a29e0843c109e52387c11e0746e9dff314e38345cc79a92cff339017595fe7
MD5 85466e65d00904f12f5da9dab586a576
BLAKE2b-256 24ea17b35e0a732b0b0092804b93260f5907a38134ca25d97b8f7009ed3b967b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cda97779bed1d1fa62359f035eadc4acbcd204f5e566f7b59bd1d36397c0f4c6
MD5 d309256db3f8046203155701b56059b1
BLAKE2b-256 61d699a01a942d723477a3572e1e9962d6cbb6beb089e4b3e0e2d4b804a2655b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 aced2646eb865c70f55c5764397f0d726c2d7754ddd46b6fce4aa3f48719a624
MD5 70fa451b96374c133310c9fd784c04c6
BLAKE2b-256 95478dd80622d0a2f68a3550f7aae22aeb8b275b573ee1a49199ccb249fe05cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 af849dc7c8792ed5063aa3d94553ba3111b36e878bfdeff4de26f843e9356d20
MD5 aaec4ce7dcd733f6258b55bc123b29e8
BLAKE2b-256 7550a7cf3646b0dc1be2fce729ca374e9a9e65aa18029706e24605da15760cdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a43d361c2fb8aa8c9edc6bb3ae4a6f5ee86fedb5cf8e64017749d1942e8c1d38
MD5 b5e5bc1112d4bcf7623ba17cd4932859
BLAKE2b-256 49779d21f561eb6f1ee41da1ee178f393c13cb34c827bace064995da9c80919d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55002c5caef406b4c06e17b97d0dec73b1cdd4eeffb7d3afb3722f213031c00d
MD5 d2c14d45a4f03dfd0f395064c2638a7d
BLAKE2b-256 35cae7a1ffe11bd73da6b64de8ba9469e9c1be917e9c71d88e5fea9fab696696

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 0e1c31b4f7f08bcbad1efc27b9755b0e2f5c7f0167ee2e7e46d4b7b088e16a0d
MD5 815b871116cec0b5632adc277e1848ba
BLAKE2b-256 0762a638c29307479cf97c55f15633addaba95db455e49ab000f65248cf407e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 3ac0e78fec0aeceb17b9bb2029e67294831bfeed3f966f9418f488ac5217b3d6
MD5 17d26359c39636a4a073a9e26ac86cf0
BLAKE2b-256 3b251191052f7e31c7ee418d51d0465dbcf04bb97b55eba99663331f7cd58fd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 51842bf25497df08114ca6c1b17b10da903c36a315a6e56341e8fb086cec625c
MD5 f942474ced0d643720315b1376dfb5ac
BLAKE2b-256 dcb9cd696103bca2fd56dec58993141aeca0fffe2e2048f70eaa6e5f046c14f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 e2b91ae918ac921ee1fffdd96325d8652904ffbbd9c17ee25b2eab015dfb249f
MD5 4d0f0ba2d9335c40024b68d47dda12e0
BLAKE2b-256 58c84ad747b99f8c72ea906c8cb18c18ece8c0a556d712127851333b639a4ca6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 83159a1232b780b3db2f9036e16fb8f9667b6913dbccc2882fe73a8f7d7837a7
MD5 e8f606ad5021ccf807a5e23802f34541
BLAKE2b-256 e819ee3cb590186fc186c7ae0b4084da94b9c7e97f494d3e874ec4c93abb562b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.14.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 64d19f29c5ba2555f24e0519250399f3af5f530ef008b9ed3332fd88725c2600
MD5 ffe0de0afac0717a323fff0aca865d2a
BLAKE2b-256 ea69b57427c8213c74a5a7a095c5079a77f94f7226422ee5a5b20ef7f2cdb0ae

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