LevelDB reader for Python — Rust core with PyO3 bindings
Low maintenance activity. Last release 8 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install rleveldbrleveldb
A LevelDB reader for Python, implemented in Rust. Reads .ldb (SSTable), .log (write-ahead log), and .sst files without linking against the original C++ LevelDB library. Snappy decompression is handled internally.
The Python API follows the same shape as ccl_leveldb, so it can act as a drop-in for read workloads. The main difference is performance: parsing is done in Rust with memory-mapped I/O, and the GIL is not held during file reads.
Read-only. This library cannot write to or modify databases.
Installation
Pre-built wheels are published to PyPI for Linux (x86-64, ARM64), macOS (x86-64, ARM64), and Windows (x86-64):
pip install rleveldb
To build from source you need a Rust toolchain and maturin:
pip install maturin
maturin develop
Usage
import rleveldb
with rleveldb.RawLevelDb("/path/to/leveldb") as db:
records = db.iterate_records_raw()
# Sort by sequence number to replay writes in order
records.sort(key=lambda r: r.seq)
state = {}
for rec in records:
key = rec.user_key.decode("utf-8", errors="replace")
if rec.state == rleveldb.KeyState.Live:
state[key] = rec.value
elif rec.state == rleveldb.KeyState.Deleted:
state.pop(key, None)
iterate_records_raw() returns every record from every data file, including tombstones. It does not deduplicate or merge—that is left to the caller, which is intentional for forensic use cases where you want to see deleted entries.
Iterating in reverse file order
records = db.iterate_records_raw(reverse=True)
Records come back in descending file-number order. Useful when you only care about the most recent version of each key and want to stop early.
API
RawLevelDb(path: str)
Opens a LevelDB directory. Raises ValueError if path is not a directory or the database cannot be opened.
Supports use as a context manager. Calling .close() or exiting the with block releases file handles and memory maps.
Methods
iterate_records_raw(*, reverse: bool = False) -> list[Record]Returns all records from all data files, ordered by file number. Each file's records are in the order they appear on disk.