A cloud native embedded storage engine built on object storage.
Actively maintained. Last release 4 weeks ago. A safe choice.
pip install slatedbREADME as published on PyPI with version 0.18.1.
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 asmemory:///DbBuilderopens a writable database andDbReaderBuilderopens a read-only reader- most database operations are
asyncand should be used withasyncio WriteBatchis mutated synchronously and then consumed bydb.write(...)db.shutdown()andreader.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(...)