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.

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.

Installation

Note on CICD The wheels provided are not completely platform-independent at the moment. I heavily rely on github actions to develop since I don't own mac or windows machines. The CICD workflow for package builds is under development A windows/macos/linux build was successful, but further development is needed.

Benchmarks

Pyrex was benchmarked against plyvel and lmdb (which is based on a B+tree -- based architecture and relies on OS's block cache).

Initial benchmarks are promissing and to be reported soon.

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.1.4-cp312-cp312-musllinux_1_2_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

pyrex_rocksdb-0.1.4-cp312-cp312-macosx_14_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

pyrex_rocksdb-0.1.4-cp311-cp311-musllinux_1_2_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

pyrex_rocksdb-0.1.4-cp311-cp311-macosx_14_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

pyrex_rocksdb-0.1.4-cp310-cp310-musllinux_1_2_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

pyrex_rocksdb-0.1.4-cp310-cp310-macosx_14_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

pyrex_rocksdb-0.1.4-cp39-cp39-musllinux_1_2_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.1.4-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

pyrex_rocksdb-0.1.4-cp39-cp39-macosx_14_0_arm64.whl (3.9 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

pyrex_rocksdb-0.1.4-cp38-cp38-musllinux_1_2_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.8musllinux: musl 1.2+ x86-64

pyrex_rocksdb-0.1.4-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.8 MB view details)

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

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 626787680e88cec287d1bd8e51bb381d4f8aa3ba2609914371f2b87ee46f94cd
MD5 d907c614a1cbef3718495fc04c2232f2
BLAKE2b-256 b8408665b35da38b266b59910d6734d305a53f42d48169f1bf24b5ca8897248b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bb8ef9a22b0ba2b6bfbb9ca18bfb8cbd8dc7099328ec78a8b30adb99f1d21a58
MD5 4321feaef0a4a63b6c888638c78a84d2
BLAKE2b-256 b35fe0aeb9eac4a67897a7f47fb75a5c0f45485f885555d5a6a8b03543ec5b5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 415695e697ee253b3e72af6e4062d81d6782bcf81c1b13fcf4401e8266ea5d78
MD5 b89bde8bc27d89d289fb9487bff9eb4b
BLAKE2b-256 b2f664f5680ca1810289fbb4941921f89b92396d062c39ef88dc7f72f4fa37a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b7bf21de84fcdd981486f01b44c91ff458f015500c931e832938e83adfce2dcb
MD5 ec9795b039aeba3f3a73f42649a02451
BLAKE2b-256 81c88ab8f937dcd34d1999bc86f4587c6fec858e4cc10cd8f7e7cfd9ebf074f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8e6e58baf865b64bdf34016411b38c06a7560dde0568c2dd9d65b48e6e704208
MD5 8cb50707ed7f5acd4040c4df346b2c0c
BLAKE2b-256 966aa4d6326a47902800da70ae3b4adaf4b075772d9663a1a5b1950e605484a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b16fed2dad8990d279ccdd9a7e26beb8798eb16b4c71d9b5d947914c777578f3
MD5 ce4cdaccf40060cf2e49724b7eb74b29
BLAKE2b-256 766deff6c307b02fbd321fcac2946f2a7654cf94caf21b1c7f8aca3b01d7e1ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c370c847d2115da8d90b05ccc23d48570c4c702a3a7cd5a8d3b11f165f943825
MD5 1cde84fd4046546aa358f765cbb68841
BLAKE2b-256 04647f5ba0286bb8e3ec34f0ea0569e30bb0f2e6255b9353986d9254982c995f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5a83c01495f8dfe93d99192bd900e99fe2580f8aa6c191f9d2449e1539fe5562
MD5 e509a0dde9510e30047088a0f6e6e9c3
BLAKE2b-256 563e807840b13e517bfe8ce807cee927150785d2963a05d127573d96edf5b89f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 330a865c5808501a95ae52fa6589c24beccbe4430a90518e5437dbb4ec318550
MD5 a3c370ebdd38ae480756ba6016022792
BLAKE2b-256 baffe8163b8307f3821f7ec6db985bba5c0a495782a9c5479b7828d1d5575d9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 948ff7029e85e2a51e51aba52f4a1590d76a0232131f3011573bde071258be90
MD5 8e5f4c04f86cd6e100d520639d426452
BLAKE2b-256 90d8b34a9dcada38fef38cd6e95dca2c8cb3409a14c08ac478819f83156920fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f4c7af8fd64b6b12ceaa50c61617c2338cea5a9161432b648a7672063a05993c
MD5 685393fc990f9017aeb3faca893f46f5
BLAKE2b-256 8785be96e727e20d3778c588494a2dbe9e811a2863558a7cec920b69f989e2da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 deec9d0c3b0308666ead02ac70dd0568519e7a35bc32337046a8d017cce51ed9
MD5 f14225a25eaea79f907d105909d3b3c3
BLAKE2b-256 55f5f9a10c3375c10dd7036b324b6bca93a30c2c4074192e22f258aa3e54e4ca

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.1.4-cp38-cp38-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp38-cp38-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e0dfae45d3d0223eb518bbc159c920fc3bbd1dfeda141e7a84b5045c947ddc12
MD5 505d8743c2fcb951f7edcc0c8a68c525
BLAKE2b-256 1db6a3b7d1132eaa538512fcd4125516844e8566aeffca78d20affe2f9b5d2a6

See more details on using hashes here.

File details

Details for the file pyrex_rocksdb-0.1.4-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrex_rocksdb-0.1.4-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 49bcffdf7463be339782b54f9ce316019b1b09378ebdee7ebccb23496195726d
MD5 9631fd8c8cc9862757987a5691e5f80e
BLAKE2b-256 57b8517e3db9aefaed9c085cb3d5a30cc3f8ce87bac00aa24f86dd0c8de90ad8

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