Skip to main content

A fast RocksDB wrapper for Python using pybind11.

Project description

PyPI version Python versions

pyrex

Installation

pyrex-rocksdb

A python wrapper for the original (C++) version of RocksDB.

Currently MacOS and Linux wheels are available.

Installation

For linux systems, wheels are provided and can be installed from pypi using:

pip install pyrex-rocksdb

For Windows and MacOS I have built an earlier version of the library. I will re-build once I include certain other important features in the API that are not yet implemented.

Motivation

This library is intended for providing a fast, write-optimized, in-process key value (KV) store in python. Therefore the "big brothers" of the database are the likes of MongoDB and Cassandra. The difference is that you don't need a separate server to run this (hence "in-process") and it is designed to be fairly portable.

RocksDB, which is the underlying storage engine of this database, is an LSM-tree engine. An LSM-tree is different from the ballanced tree index databases (e.g., B-tree/ and B+tree databases). LSM-tree databases offer very high write throughputs and better space efficiency. See more about the motivation for LSM-tree databases (and RocksDB in particular) in this talk.

LSM-tree + SSTable engine basics

To understand where pyrex provides efficiency gains, it is important to understand some basics about the underlying RocksDB engine.

RocksDB and LevelDB are key-value stores with a Log-Structured Merge-tree (LSM-tree) architecture.

The key components of LSM-tree architectures are

  • A MemTable that stores in-memory sorted data
  • A set of Sorted-String tables (SSTables) which are immutable sorted files on disk where data from the MemTable is flushed
  • The process of Compaction, which is a background process that merges the SSTables to remove redundant data and keep read performance high.

In such databases, fast writes create many small, sorted data files called SSTables. To prevent reads from slowing down by checking too many files, a background process called compaction merges these SSTables together. This process organizes the data into levels, where newer, overlapping files sit in Level 0 and are progressively merged into higher levels (Level 1, Level 2, etc.). Each higher level contains larger, non-overlapping files, which ensures that finding a key remains efficient and old data is purged to save space. There are several optimizations and configurations possible for these processes (configurability and "pluggability" are commonly cited RocksDB advantages).

However the main big advantage of RocksDB over LevelDB is its multi-threaded compaction support (LevelDB supports only single threaded compaction, which comes with significant performance limitations). There are several other configurability advantages RocksDB offers over LevelDB. For a more elaborate enumaration of RocksDB advantages please refer to the RocksDB wiki.

Not all are currently supported by the pyrex API, but I'm working on supporting more of them. Feel free to open an issue if there is a feature you want to see (or open a pull request).

Example usage:

Here is a simple example showing the usage of put/get in the DB:

import pyrex
import os
import shutil

DB_PATH = "./test_rocksdb_minimal"

with pyrex.PyRocksDB(DB_PATH) as db:
    db.put(b"my_key", b"my_value")
    retrieved_value = db.get(b"my_key")

print(f"Retrieved: {retrieved_value.decode()}") # Output: Retrieved: my_value

for more examples check the relevant folder and the documentation.

Native columnar batch writes

For Arrow-compatible binary or string arrays, write_columnar_batch moves the per-row batch construction loop into C++:

import pyarrow as pa
import pyrex

keys = pa.array([b"k1", b"k2", b"k3"], type=pa.binary())
values = pa.array([b"v1", b"v2", b"v3"], type=pa.binary())

with pyrex.PyRocksDB("example_columnar_db") as db:
    db.write_columnar_batch(keys, values)

Polars users can pass series.to_arrow(); Polars is not a required dependency.

Note on CICD The windows wheels are failing at the moment. The CICD workflow for package builds works and passes all tests only for MacOS and Linux.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyrex_rocksdb-0.3.0-cp312-cp312-musllinux_1_2_x86_64.whl (14.3 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.3.0-cp312-cp312-musllinux_1_2_aarch64.whl (6.6 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

pyrex_rocksdb-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyrex_rocksdb-0.3.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pyrex_rocksdb-0.3.0-cp312-cp312-macosx_14_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

pyrex_rocksdb-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.3.0-cp311-cp311-musllinux_1_2_aarch64.whl (6.6 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

pyrex_rocksdb-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyrex_rocksdb-0.3.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pyrex_rocksdb-0.3.0-cp311-cp311-macosx_14_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

pyrex_rocksdb-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl (14.1 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.3.0-cp310-cp310-musllinux_1_2_aarch64.whl (6.6 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ ARM64

pyrex_rocksdb-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyrex_rocksdb-0.3.0-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pyrex_rocksdb-0.3.0-cp310-cp310-macosx_14_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

pyrex_rocksdb-0.3.0-cp39-cp39-musllinux_1_2_x86_64.whl (14.1 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.3.0-cp39-cp39-musllinux_1_2_aarch64.whl (6.6 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ ARM64

pyrex_rocksdb-0.3.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pyrex_rocksdb-0.3.0-cp39-cp39-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

pyrex_rocksdb-0.3.0-cp39-cp39-macosx_14_0_arm64.whl (4.1 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

File details

Details for the file pyrex_rocksdb-0.3.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c4a345dec6dbdcfdbb36541192d4b2c8b369c1efc9580f90d914283129fa6874
MD5 676c2c393acafb1b78e8e56442b6159e
BLAKE2b-256 473e0c1f4d43867c4b9356e25bdb5703da51184508643deb8f2ba1a10e64027f

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp312-cp312-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a35983636762f56ac908863b2ad78dc7840d717b1483333cb52a0dfe1f80f90f
MD5 79db2b3b56e24874b0dc77b6cddaeebc
BLAKE2b-256 d7dce0e13b918827fb883c066d43d8d442385031f527cb08e399889e43155ca5

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c294db19490166df957ee975a39902b04eef327ee2b4e22d588b03927c82c122
MD5 3f197224677de01e47ef634788a5a20e
BLAKE2b-256 26018c6108a571f38faf1495dcec91e7f6a5aedf4bd576bbb781f230be07a36f

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5e2a351d66144529d2039ce8e275feb770859590f5001ba1511063620397bce9
MD5 cb85182b3665b7443ae3b33bd6544c16
BLAKE2b-256 764e91a456de9c07fadaf9968a321ef73c665e4417367f7c419c6e3ab56252fa

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 034d302d0b2583bba012a93a99086ed3b3f1664872885aee1a142dd4dfee102e
MD5 5125a3f428cdee6e1b0efd3f4db454c8
BLAKE2b-256 fd813b454effec811771cbb412398ba205ebe757d38cb241d213a234d240c540

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2163c2b28d95a6f3408661be045ac1e5ba1e4520be86bc3b774863800b2fe20b
MD5 088d76935bcb44970da5fbc5edee2c6a
BLAKE2b-256 b7c6af453ea5750d27e7fe144f95210de723b274f33f5910b806ec6436ba6ebe

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 1a4f4855accae223b35d5222e9b14d2c31489266f9783714c9ea6c0fc56463ca
MD5 88e7dfc9c08c1f7162e7694fb5cdee7b
BLAKE2b-256 e997f454bd26671bfcc7c2e688f6bd2f2d48a099a162970d971c6e15b25fd86e

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 25b597e03e17e963c0228ef9ff5e2e0a759443f6f967ee48f864b129e56bd79a
MD5 da95afd8123c05787414f24509f08216
BLAKE2b-256 79b325b35044d14d88acccb07b123ffb427e14ea1501b931ae427926c42c8a51

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7bdaff41b1617619b76ea6fb90cb855d36079c25208e4672528109497a54f268
MD5 a08f794fa5496c8eadee42930e61d4b3
BLAKE2b-256 bbda59cbf77396302c183822790cb6743d6074001244655542fc6bdfb9d4ae7f

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 47984bc09ab8f2528116929b7dedeebf03e0189a12b5306cb257c4094373d026
MD5 8b00703b3f54207a71c831b2f3989cbc
BLAKE2b-256 c0eec28f3875939b4575430c569163379d3b71bb246b946d156581695cc228fc

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f9c5b0e302bf7ebdc9634ecedf5643704998fb82ad8ee45dcdab936fac35697d
MD5 155ea9c9dbe0c544f92d563f55cd0c37
BLAKE2b-256 0e3ccb9d9a1bf4bca1719235ed5dfff9e90422ba10df338ecee70119782e3ca2

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp310-cp310-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3323cc2760c41411bfab213d8a1e6a43461ff1d4a22f2a53992cbb4480b39575
MD5 ee15e0fcd20f0d6e910b8068cbef30b9
BLAKE2b-256 859398dba9ef7fd556aafa37eee762cffeacfac83b9d0b15e6405e4da2e610cf

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9d2cf0071c01b988d40b62f4d1a88471d2af1256039bfef2e1f129c09bda0cea
MD5 778b688259433bfbc7fb922185ee09dd
BLAKE2b-256 61df501c6669c240eada32a9bd15ef78ac7a94c5c17ff6100d473ce9db8986c7

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8f1115c5d46e632d333eb226d7fb8335fc9a81ffb5c931936fa8dd66446e71aa
MD5 26bbaba41654a31596808614c940051a
BLAKE2b-256 51dcd00d930e00ca20b83c5aab064ec6c076e28dcb58597a8ffb15cad2fc7312

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 18341a3559fbd5ec0ec44d6b762163364617bb02a73a63c0fa9c07f51e48fef1
MD5 7e25ee207acd1ad4745e211228e4bfaa
BLAKE2b-256 cfd3e3ac2649b0cdf3bc4b0310252b81833fbbf374964f097d0aae90120339d5

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8d642f3efd4cbb9df7826a51c1ba0ead82ea0276bdc500af9c613aa1aea83f59
MD5 9c4569aba5bb2a4c9838d215be8b40b7
BLAKE2b-256 047dfb2b96374238615fdaa59bf00f76c9428ca0ab918af9d95dc108126eb76a

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp39-cp39-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp39-cp39-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3355b8c4ec8be9a52c252d1869c3452a0400f1247143601e232cb265734db25a
MD5 d289d0516cb7409c1871eb00352e987f
BLAKE2b-256 8c55bcdf4d9bcabec04913aaa785146e88cae101b4c303a1b9d4ebdda49451fa

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 56d1971b9d0d287814f1b5ee3c51a547b7fb835019ccf5852805c39e25f4d4fa
MD5 575632371b67b6b1d95fabfc249265d7
BLAKE2b-256 849be859220a08ff69f8197a51afcabfda2bc44a36952887a4ebc8b0b2088b5d

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp39-cp39-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp39-cp39-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 120b21e6bf8925c9480b1e7d2a200cca7efcf8149382203b42a879229c79b364
MD5 0e17e20b6f10edf01a07fb1c0823b924
BLAKE2b-256 557ded6babd35bb99a77f738c8dd8c2e3d46feb74117af161e00199f0b3769b6

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.3.0-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.3.0-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 95acf1f141a2eca76318fefa7f740d31b68e10f84c9dc4640a1ad5559e7fdcee
MD5 af2cc87b6bfa753e9d20b5429458db68
BLAKE2b-256 3d0f98bfa6b2578d1d59b8b60b31eced602633280c9c58c6ce3fa5b224caabed

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