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.12.1.tar.gz (631.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.12.1-py3-none-win_amd64.whl (6.7 MB view details)

Uploaded Python 3Windows x86-64

slatedb-0.12.1-py3-none-win32.whl (5.8 MB view details)

Uploaded Python 3Windows x86

slatedb-0.12.1-py3-none-musllinux_1_2_x86_64.whl (8.0 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

slatedb-0.12.1-py3-none-musllinux_1_2_i686.whl (8.1 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

slatedb-0.12.1-py3-none-musllinux_1_2_armv7l.whl (7.6 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

slatedb-0.12.1-py3-none-musllinux_1_2_aarch64.whl (7.9 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

slatedb-0.12.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

slatedb-0.12.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

slatedb-0.12.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (8.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

slatedb-0.12.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (8.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

slatedb-0.12.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (7.4 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

slatedb-0.12.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

slatedb-0.12.1-py3-none-macosx_11_0_arm64.whl (6.9 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.12.1.tar.gz
Algorithm Hash digest
SHA256 fb794c23bb33ecb7e22ae5a668438a203124d5d69dc5c5d5521709d6873f6bb1
MD5 0944b1239714f60114fed7b4d5bdc4ee
BLAKE2b-256 8a70907ccb9db2deeb018565ca517f3b3665ad19560dceaabf98b126cd61c036

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.12.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 886a47484092e76ef27b19b96b181124ea03c42af75e300c4e03ba69f826c528
MD5 75eaa30c8c9ba3d8815e9b3c019f19c0
BLAKE2b-256 9d4b3fdab5b08e5fe0abcf2cb97233f2f1056ee84632a48f2ea45af16a2bbc6a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for slatedb-0.12.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 c88f2be6c491d27593aecd5a2f4f1f3cbad2b61b20c866b6af79bd0e48df8059
MD5 9f11046bfa07f4464fae47982c304f38
BLAKE2b-256 1136f6d3fcf478e4524a4c9b9ce37dd27736d11f0747a682c76ea950c2535c06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 906415d56213b26e8647a0466dd7ab7294aed088081014d04ffa122dd8afd6f7
MD5 3abffbc6a88a348203fd2497c307924f
BLAKE2b-256 c17cd8fb21401f83975ac4a43d834fa04ddf51f5045f44341529e5bc3bc5b097

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 95e12593f141096ec7d8ea8ff27e56d4bdaf5448b12c7339bc995b23fa5eb037
MD5 4a302e92100748e48ca2cf7973312449
BLAKE2b-256 63734854f9434dc11bbcadac76a29a6490e79393faf69b6b00663fadd00c2394

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 21c748dce17a57b12900935b77f5714b3bc76bcfe9ad8f8399d6a8fbd2b1700f
MD5 b8fe2d7423a7b5b583d1fee1f1df3848
BLAKE2b-256 4d0b49e8ecd1f5e8fb540932cd8790a42d7907676178331a9fa104b2fbf94a82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 61b886275f3819eb2967a3ca555ee9a12f2c552c08dba5ffefd279c1bc7d1c83
MD5 c7302db89e9eed531f82380c3d759427
BLAKE2b-256 79a695a2b4f9928310282ee685f99d21e8965c8b5f06f2ba7bfff32a543e3898

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 72c1925931298f8865215d6936d18c286787ee450dd0ac6a973acdc8e77c9617
MD5 9005e7a025e80183934735d0839a2f85
BLAKE2b-256 566a3e2b3442a55357cc3afd4760b74c3b19cadb5b6077be5f80f5bc6b49e9d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 b28c817951faae6cb621064c736ef115ba49de6f86a279a7277721fd821138c6
MD5 370e0fe07f4c5c6905440dff6338d2fd
BLAKE2b-256 bba1d47303cfff392d4f667ef49763958a6cf10e7a1d3dfca67727f619c2008f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 466164809ef5bdaa8169ca2dc2c6d3347b29a805c44a8d6a5a3e6858279afcb3
MD5 4400036625d66a05d4c13d0a7f7b34e1
BLAKE2b-256 51d88e4ded48f25910751812ab05dcb81ae46ef03db91a0b1cc0299d605ce7b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 742cb96cb59cee1b73352c44d1b54a4323a092883fa0e0e2f95430efad592d20
MD5 f3c77ce7c830fc4ef13aff3c68c4407f
BLAKE2b-256 aa67921aeaa6e4216332b3060b0992a75f3b65008d6003f84f19dee84ce3a32f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 0a0817f96e40af145190c184e53d0eba0548946fbc069214b2694c553d0560d1
MD5 ccef6b992e39074126f2d78e45d19354
BLAKE2b-256 b428c6c77bf03b47be81d7888f3ee65a950d7932b0ce37e36f70c20c7f6d9e8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 14a03225bfe4c842ec6ffeeee07b5bcd9498ca90620d4db0dedc73a7287e995c
MD5 20b561ff38239b48c4ddd33d9fdeb502
BLAKE2b-256 88dec0308008491fc1152e0115e6a3be568ac8c63d8fdbda4633d7dafc735f18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.12.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e93a6cc0b14395d0830e1515c71288ceba2dc9ef91bc72177106b5fedd953024
MD5 a4c814b10b318df97d168595e46f7fed
BLAKE2b-256 a1b291de132b91d359bd0e24e14321764ba2108d35382457b3fcfe821cb6a001

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