Skip to main content

Rocksdb Python Binding

Project description

RocksDict

Key-value storage supporting any python object

CI PyPI PyPI Support python versions

Introduction

This library has two purposes.

  1. As an on-disk key-value storage solution for Python.
  2. As a RocksDB interface.

These two purposes operate in different modes:

  • Default mode, which allows storing int, float, bool, str, bytes, and other python objects (with Pickle).

  • Raw mode (options=Options(raw_mode=True)), which allows storing only bytes.

Installation

Wheels available, just pip install rocksdict.

Examples

A minimal example

from rocksdict import Rdict
import numpy as np
import pandas as pd

path = str("./test_dict")

# create a Rdict with default options at `path`
db = Rdict(path)
db[1.0] = 1
db["huge integer"] = 2343546543243564534233536434567543
db["good"] = True
db["bytes"] = b"bytes"
db["this is a list"] = [1, 2, 3]
db["store a dict"] = {0: 1}
db[b"numpy"] = np.array([1, 2, 3])
db["a table"] = pd.DataFrame({"a": [1, 2], "b": [2, 1]})

# reopen Rdict from disk
db.close()
db = Rdict(path)
assert db[1.0] == 1
assert db["huge integer"] == 2343546543243564534233536434567543
assert db["good"] == True
assert db["bytes"] == b"bytes"
assert db["this is a list"] == [1, 2, 3]
assert db["store a dict"] == {0: 1}
assert np.all(db[b"numpy"] == np.array([1, 2, 3]))
assert np.all(db["a table"] == pd.DataFrame({"a": [1, 2], "b": [2, 1]}))

# iterate through all elements
for k, v in db.items():
    print(f"{k} -> {v}")

# batch get:
print(db[["good", "bad", 1.0]])
# [True, False, 1]
 
# delete Rdict from dict
db.close()
Rdict.destroy(path)

An Example of Raw Mode

This mode allows only bytes as keys and values.

from rocksdict import Rdict, Options

PATH_TO_ROCKSDB = str("path")

# open raw_mode, which allows only bytes
db = Rdict(path=PATH_TO_ROCKSDB, options=Options(raw_mode=True))

db[b'a'] = b'a'
db[b'b'] = b'b'
db[b'c'] = b'c'
db[b'd'] = b'd'

for k, v in db.items():
    print(f"{k} -> {v}")

# close and delete
db.close()
Rdict.destroy(PATH_TO_ROCKSDB)

More Examples on BatchWrite, SstFileWrite, Snapshot, RocksDB Options, and etc.

Go to example folder.

A Simple Benchmark

Compared to PyVidarDB and semidbm, which are all cross-platform key-value storage solutions.

Small Value: 100 byte value

sequetial insertion

image

sequential read

image

random read

image

Large Value: 100 kb value

sequetial insertion

image

sequential read

image

random read

image

Limitations

Currently, do not support merge operation and custom comparator.

Full Documentation

See rocksdict documentation.

Contribution

This project is still in an early stage of development. People are welcome to add tests, benchmarks and new features.

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

rocksdict-0.3.0-cp311-none-win_amd64.whl (2.5 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

rocksdict-0.3.0-cp311-none-win32.whl (2.2 MB view hashes)

Uploaded CPython 3.11 Windows x86

rocksdict-0.3.0-cp311-cp311-manylinux_2_28_x86_64.whl (4.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

rocksdict-0.3.0-cp311-cp311-manylinux_2_28_aarch64.whl (4.5 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.28+ ARM64

rocksdict-0.3.0-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (6.4 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

rocksdict-0.3.0-cp310-none-win_amd64.whl (2.5 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

rocksdict-0.3.0-cp310-none-win32.whl (2.2 MB view hashes)

Uploaded CPython 3.10 Windows x86

rocksdict-0.3.0-cp310-cp310-manylinux_2_28_x86_64.whl (4.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.28+ x86-64

rocksdict-0.3.0-cp310-cp310-manylinux_2_28_aarch64.whl (4.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.28+ ARM64

rocksdict-0.3.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (6.4 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

rocksdict-0.3.0-cp39-none-win_amd64.whl (2.5 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

rocksdict-0.3.0-cp39-none-win32.whl (2.2 MB view hashes)

Uploaded CPython 3.9 Windows x86

rocksdict-0.3.0-cp39-cp39-manylinux_2_28_x86_64.whl (4.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.28+ x86-64

rocksdict-0.3.0-cp39-cp39-manylinux_2_28_aarch64.whl (4.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.28+ ARM64

rocksdict-0.3.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (6.4 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

rocksdict-0.3.0-cp38-none-win_amd64.whl (2.5 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

rocksdict-0.3.0-cp38-none-win32.whl (2.2 MB view hashes)

Uploaded CPython 3.8 Windows x86

rocksdict-0.3.0-cp38-cp38-manylinux_2_28_x86_64.whl (4.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.28+ x86-64

rocksdict-0.3.0-cp38-cp38-manylinux_2_28_aarch64.whl (4.5 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.28+ ARM64

rocksdict-0.3.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (6.4 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

rocksdict-0.3.0-cp37-none-win_amd64.whl (2.5 MB view hashes)

Uploaded CPython 3.7 Windows x86-64

rocksdict-0.3.0-cp37-none-win32.whl (2.2 MB view hashes)

Uploaded CPython 3.7 Windows x86

rocksdict-0.3.0-cp37-cp37m-manylinux_2_28_x86_64.whl (4.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.28+ x86-64

rocksdict-0.3.0-cp37-cp37m-manylinux_2_28_aarch64.whl (4.5 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.28+ ARM64

rocksdict-0.3.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (6.4 MB view hashes)

Uploaded CPython 3.7m macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page