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,
    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:")
        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()

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.13.0.tar.gz (798.4 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.13.0-py3-none-win_amd64.whl (7.3 MB view details)

Uploaded Python 3Windows x86-64

slatedb-0.13.0-py3-none-win32.whl (6.4 MB view details)

Uploaded Python 3Windows x86

slatedb-0.13.0-py3-none-musllinux_1_2_x86_64.whl (8.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

slatedb-0.13.0-py3-none-musllinux_1_2_i686.whl (8.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

slatedb-0.13.0-py3-none-musllinux_1_2_armv7l.whl (8.2 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

slatedb-0.13.0-py3-none-musllinux_1_2_aarch64.whl (8.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

slatedb-0.13.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

slatedb-0.13.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (8.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

slatedb-0.13.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (9.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

slatedb-0.13.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (9.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

slatedb-0.13.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (8.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

slatedb-0.13.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

slatedb-0.13.0-py3-none-macosx_11_0_arm64.whl (7.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.13.0.tar.gz
Algorithm Hash digest
SHA256 a7c89840117c43bc7fd091aa0bd86f8ed21febb0e51c5deaac8bdf907d588217
MD5 f1df4168da1d6176a33ada715ec37ce4
BLAKE2b-256 7aedc7ecbea3301d1518e97e69f6a29529497bfe70d1fb5bbee06a52470c89f9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.13.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5628b50ccd37a591ca08e788c811d8441544dcb22dca7a3c975005889c97b5cd
MD5 e56d7bd58d7b57be38f9ef933f2d624c
BLAKE2b-256 7289d922602f8fc0912452d4ff2147397bb148439d34098a41fe5376fd8d5520

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.13.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 8720f4da36096f882df69cb6b4e2ecd970f2e43442446dbaeb7e140dee7b21bc
MD5 df0df001d4af7607bb6cf874d9269393
BLAKE2b-256 4b454c5cab9fb45676451cb9eed2ff3f3fd2e261e3c135c3b0b51f5df2bebb44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b2dedb8ae04f1d3b34297d7d309bface576128451a4fe31ca9f638c1f25aed31
MD5 ff1b4b5f01ce1bcf526a5a4f1e82250c
BLAKE2b-256 9d912b90b2b50002ac11e4c5da2b44ecc5aa8ee1f60efa0a1fa7b1a91309e5b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 8154aaf3ce1a309dd09674679fb8bb46315dacce83fc9699a46ec8b8128e8e0d
MD5 1222c6a0fc14234955dd04de07e97252
BLAKE2b-256 3476dc427c65c013388a74d10ac314be21e95680f693686aa5c110c2d027df60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 e7e7f07359c5a728002a330470207daa68932c6536a13905f531d4b968ea1a2c
MD5 ac51563aa0b2fd5eb369b409b33de235
BLAKE2b-256 b10c1797c24eebfcc7936b4220e5c55d45ce77ab3ecd57accda6fe524c0f3d74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3fbfb5bf546450c9b4a656a5597853b431713c99575459998bb736d300327ca1
MD5 4f605c3c75ecb77b93e3e3f04fdea97c
BLAKE2b-256 f004979a113f0757ff923a3206ec023b7663d15d27387de3b73ed5680717ccfd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 10c5299c1e16f44dcf0a82ddfc1a8588b403bc3f7f7c60307e06320dbe1ac7c0
MD5 b4ef6ad687a1fa2246c135de7bae2f15
BLAKE2b-256 aca898a3d9975349aebbf8d88f73436b2136e9438f6f31bd6f149b993e02f1d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 d645c397fcb274683790d422f2f0c700ce90eb5a00bfcbdb30031c453d9d08cf
MD5 2b43967033ebf3c415c05e16e4d72bf4
BLAKE2b-256 38efca132779dfeacbb123596bb93a5a127d728d8555cb4f8e30488b6254d3b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 34cdddb198ec6386e6fd32fc7880dfb872a99552a0566e88e60605b024dac359
MD5 d0145f4c6ae2efa976e659509008da61
BLAKE2b-256 29b25b7be118912f705b5efb725b8a49f7f9205adae919e8c78e5df386d2d774

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 a76faa79b40d3ea3d59aa599996935d4d40987be1c7515cd5ed82c40a197637e
MD5 32a20d5208371ced4ea53806d04c7404
BLAKE2b-256 a88fb4c700d720f44db8ca500a2f103510373e0e34f48aa189c1f31565223c99

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0f28e1a6c074c3ef0465f421136952479cced096ee50ec9a90cb449d0303bcf7
MD5 5002232247d78b72414ea7b3a52eda94
BLAKE2b-256 3d663b5bafe84d8a5f6e211b91f8ca310ca921c182dd57206a1d78d85182d46e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5b55e4ccbaafa0a8e23cd13eff3075f8e94102e4e49c09b84a71bb376ca6dc96
MD5 464d338eb8b970360de26cd5f503d80b
BLAKE2b-256 53ff9f1c8e00b1dd713b44480699a493ea47362c776f96f3402b284d74dba4e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e3b59344214952f6cda7cfe08bcab837a4c9bef475a13414f5d817608fdf26d
MD5 50444c7b530616031acb2ee9cadf6a8b
BLAKE2b-256 b47d0f2ca01abad519eba7adf55cf7f5928d46dd81a4c7fa59df22e54c208225

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