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

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

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

Uploaded Python 3musllinux: musl 1.2+ x86-64

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

Uploaded Python 3musllinux: musl 1.2+ i686

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

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

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

Uploaded Python 3musllinux: musl 1.2+ ARM64

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

Uploaded Python 3manylinux: glibc 2.17+ s390x

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

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

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

Uploaded Python 3manylinux: glibc 2.17+ i686

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

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

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

Uploaded Python 3manylinux: glibc 2.17+ ARM64

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

File metadata

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

File hashes

Hashes for slatedb-0.13.1.tar.gz
Algorithm Hash digest
SHA256 53942b1707e7af3ab6ad89064b665a6c770fbbd7919dd3fdb715e9c126f236f7
MD5 a70857933f8719143435add9439f25ad
BLAKE2b-256 2fbaaecf57f6bf6fdefc6275af79e6aeacd9a483bf0911a3b8302e29c9c35e1c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slatedb-0.13.1-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.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 a9c2b2fe6ef38be5624bc7f2aec8776dad5880f43c84c8b11fe9153692781286
MD5 e6de2f8fbe61a1566e6513bafa0ce725
BLAKE2b-256 1e1bf90c7a24a5cddca9a8df28f7b017703ed75eeb2bc1e41763a8978e325f03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: slatedb-0.13.1-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.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 db91e08d22c463782d305c5a567002f5777dda137fa5b946227a2f19a52df30c
MD5 cd42f7f8638ba1921f49ce6cba7af343
BLAKE2b-256 8a60e169f0e23cfeaac160be8f71a824ad58bfaabbea0dbd4467c15d44638a40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dbd8a7054395c699e25be33435ea2baa0535a59d4cb5ce62ff0cd41aeb2ec1e3
MD5 a2ff106bd0c353c4a1584910af7bac66
BLAKE2b-256 c70d8df6cc56e3e902327113ebcd02e497c1d9c89789f39a88aad24a83cdfced

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 3dfd5cc507db9435d29c1a810c2a4b793c0aeb4025b2316c36a2ffebb5b5e94c
MD5 a87739fda6b53a95f61fb9956b19dcab
BLAKE2b-256 47e2ef8e43d4a2cb3d4b84f726f446a6e0c0bf8e5fb58b775fba735afd844c1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 48de98d142b116c34f5de49e72d04acabe643bf2f0b658ed04e90cb6fe4f1a66
MD5 ffa6943e0b6fa44f6d76ce53184affa0
BLAKE2b-256 be14f45645c2e4bd526fd97929a190eea8df28a8d1ed61ec947d87dbd420ec8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f2b7616b6467079197afd742e6727d4e5463de30be5d0ec3a83691cc4f95fcd2
MD5 27dd489ba460420d087765ceea4cf7fa
BLAKE2b-256 915c573c2366dbfb2fe7be0e849b1484cac49e1e2d42a5a3e171155f1438a903

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c9791259c00b304971ec291c6979bd402bf09d9551c5981d8745f00640e0206f
MD5 d2c74cbb266fb7648d279c42d84f3362
BLAKE2b-256 98bca207d2384e53425b8e2f8ba848be372cef576b2c845b5720196542592867

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 e8e10d594bdc9ce5e6bae2a78d705514b959efc329196d63042f87d47717e167
MD5 b7e205053c56000fa3ff24b3b6cbe905
BLAKE2b-256 564c056ef3f7f313bfc032aab715f4d2fe03554494a9f8b1d8b8a66f46c14ae1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 051cadd9ac8e607d9871806fe03508aad178adeeba25d31e93160ed74c012dab
MD5 fc5a6563c565eee2b7644dca14748d76
BLAKE2b-256 412040f76dfce9cf4e9cc2cae5c3f1a7e00f66ea43b5d70d77927eaa92107a78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 db6f333d2eb2f8d3739eab006ce3ee2841d5504aa72f8c3b134facfb29aa31a0
MD5 2f46330b6e10b191555829e42112b822
BLAKE2b-256 1689d08a4f84b732f5f8529aa8ebe7bb8731637138dd59ee6f1eee89f25ad73b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 2bfc8dc79257922ab695f43049515f701ec1167ee0fe526340a3b50e1945cc0c
MD5 591be30eee4899d3e3bbdb2e8d690cfe
BLAKE2b-256 d36b778f9d5d258ab0a9786fcbaa81de9a5bc0590d18ef219ddc3e70f3f32a20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f8d0dd31f7f74dff07132f0e2fed2b4c74fa5a0c485a67d8ae6923727243cdf5
MD5 a1ccf2ef0005c302328cddb89a571d92
BLAKE2b-256 dc0dea25e823322d6f260c8685591a6741b7d132a1604319047974aeed4ee70d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for slatedb-0.13.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 70cee6fcda74fcefd3912919d45c1cab2a561cc52cf5fc393d858529706519b3
MD5 6efb1e0ac55da1732503f2d7e4aa1889
BLAKE2b-256 b8be5eb833a129072a53f2b94ba64a5e7fba5895a7e68e7e829db0e41f7c3e0f

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