Rocksdb Python Binding
Project description
RocksDict
Key-value storage supporting any python object
Introduction
This library has two purposes.
- As an on-disk key-value storage solution for Python.
- 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 (withPickle
). -
Raw mode (
options=Options(raw_mode=True)
), which allows storing onlybytes
.
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)
New Feature Since v0.3.3
Loading Options from RocksDict Path.
Load Options and add A New ColumnFamily
from rocksdict import Options, Rdict
path = str("./rocksdict_path")
opts, cols = Options.load_latest(path)
opts.create_missing_column_families(True)
cols["bytes"] = Options()
self.test_dict = Rdict(path, options=opts, column_families=cols)
Reopening RocksDB Reads DB Options Automatically
import shutil
from rocksdict import Rdict, Options, SliceTransform, PlainTableFactoryOptions
import os
def db_options():
opt = Options()
# create table
opt.create_if_missing(True)
# config to more jobs
opt.set_max_background_jobs(os.cpu_count())
# configure mem-table to a large value (256 MB)
opt.set_write_buffer_size(0x10000000)
opt.set_level_zero_file_num_compaction_trigger(4)
# configure l0 and l1 size, let them have the same size (1 GB)
opt.set_max_bytes_for_level_base(0x40000000)
# 256 MB file size
opt.set_target_file_size_base(0x10000000)
# use a smaller compaction multiplier
opt.set_max_bytes_for_level_multiplier(4.0)
# use 8-byte prefix (2 ^ 64 is far enough for transaction counts)
opt.set_prefix_extractor(SliceTransform.create_max_len_prefix(8))
# set to plain-table for better performance
opt.set_plain_table_factory(PlainTableFactoryOptions())
return opt
# create DB
db = Rdict("./some_path", db_options())
db[0] = 1
db.close()
# automatic reloading all options on reopening
db = Rdict("./some_path")
assert db[0] == 1
# destroy
db.close()
Rdict.destroy("./some_path")
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
sequential read
random read
Large Value: 100 kb value
sequetial insertion
sequential read
random read
Limitations
Currently, do not support merge operation and custom comparator.
Full Documentation
Contribution
This project is still in an early stage of development. People are welcome to add tests, benchmarks and new features.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for rocksdict-0.3.5-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a085b52b49e799b496a6c92bb7cb1988fcf48da185dd83fc9040bf47325b04c |
|
MD5 | 786fd452cedf7e9c1051de86f1543ac3 |
|
BLAKE2b-256 | d66e2e3b8e3d77f2ee02948443bc71f428e92e2458931c60036da8272caec528 |
Hashes for rocksdict-0.3.5-cp311-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca7b5df80d589ec51bdeb12c2fb49d3c090281df025ef5d88928875337a29f69 |
|
MD5 | 8a7a438f469509f96a48da1aafe5491d |
|
BLAKE2b-256 | f6155c64bf71db4648bb0c4f93c27df6e9c24e07c08548bbac584481fd97534a |
Hashes for rocksdict-0.3.5-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c23d54ff3397b0f866180cda96d50458b95cf5b12287302fe63a011e82e7616 |
|
MD5 | 3862bd52b697b58b7d5358f2ee96d7a0 |
|
BLAKE2b-256 | d351c3a62e25bfe6e6d1173699e49f3131488a5c42e0e62c317a3d7642796a06 |
Hashes for rocksdict-0.3.5-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e3f3a281c98043f3f00e41bb85b44733707c27d6c288ad7f33f9c580db10480 |
|
MD5 | 1d1bfe9f8cdc0be2c138549c6f0eb7e7 |
|
BLAKE2b-256 | c7ab45b4a731de3daf182664e49ede93c837bd9fb97b16b87b7247387fe7c3b3 |
Hashes for rocksdict-0.3.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b2875d60706de522259001a60dfa00a8a4366c9ef3dcf3eb38c4ab2208ac5d6 |
|
MD5 | f677621140c32a83d32294d67df8d6eb |
|
BLAKE2b-256 | b9484627fc1fcc50108c57be09cf048b2cabe204dbc35b7c64b0a427d072d374 |
Hashes for rocksdict-0.3.5-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aab989be1f3605dbec5a19ddccf6d29219e891288521a75e41f2625f920f5d9e |
|
MD5 | 3bb3fa55f64e748b9fa88b6762647e9a |
|
BLAKE2b-256 | 38b0176bec29e26581b5f34bed77da03b83a86c1b55b79264e8bcc354e0265f4 |
Hashes for rocksdict-0.3.5-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fc7c9333170557c8f9a5cac1ca149f989b76042401595500ec2af5acc7fe381 |
|
MD5 | b62791eaca6444fb7dc91a66bf9b3cee |
|
BLAKE2b-256 | 908aed6dedcd5d39554deaebf7e1787cc51e9a9a1bfd2bf4e84d9498811de82b |
Hashes for rocksdict-0.3.5-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68cc92a30e51948b9fca3febdce692d70a5eb60aaf54c1e51e2e75a754415317 |
|
MD5 | 7952e7002f2cf6aac42c7cb7e253c601 |
|
BLAKE2b-256 | a71be52d38a091723417b7734dfc45205e86224104984c71584b9692660a387c |
Hashes for rocksdict-0.3.5-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5b18bec9a43b826ce5c20405d479638a53d668e19882c9746da9638b4f78a50 |
|
MD5 | 1ce1719360fae1341617eae1432d69db |
|
BLAKE2b-256 | 763f6e4b790ebf0ee1e009f7a4cd2c584de217fd73f77f19952af2cc89ee8d5b |
Hashes for rocksdict-0.3.5-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c3a9b93a5e63ebe08d7e3e13a058ad78b7d3301d5acf6230131e66163c75d39 |
|
MD5 | 89652a22fe9f7cbd0bccb4d0cd884662 |
|
BLAKE2b-256 | f6241e963d197dcd8cbac30d490fe1cd30631475c126de9ffabd36e130152fab |
Hashes for rocksdict-0.3.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45c013c0b9560fda896f8d62aa99f4ba99827ad7b0f76ded796c504df839912b |
|
MD5 | 59d113c67af74a8649e2dcef90e19a74 |
|
BLAKE2b-256 | bd7f6b5fe076ef118ce4da76b69a36c2ed7f1bf9b5f5973ead5ad5fe158f286e |
Hashes for rocksdict-0.3.5-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de51f8a07b245e6eded8ebd59153a65b60ae854676b61d81b104cf1e7134024c |
|
MD5 | 0c8155afff4a3c64506ed869df3445e4 |
|
BLAKE2b-256 | 437ff3d49293ce6c06027872ddd6a5aae7f88a682000ade2918ec2b721fb5679 |
Hashes for rocksdict-0.3.5-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 523bbda529839df671593092ba03067c13e5366ce2b7f7fd1d7f6466a37558bc |
|
MD5 | 8383dbc80d765b2a9d655c16c408a0f9 |
|
BLAKE2b-256 | dd197a8f0c04cc4593e9e550bc08f8cf34a6590cf46da1aed8026368c4ddaecd |
Hashes for rocksdict-0.3.5-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b95522fd690b68578f22dfc0aab645caf7a99d83670367ee840248f63225ee56 |
|
MD5 | 4ba711c3656fa81b6616b88dbd963a07 |
|
BLAKE2b-256 | 2e59d0dc1dab754206bb972c038b631c1a6624bf03aa4738f2b034686e6a58c8 |
Hashes for rocksdict-0.3.5-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02bee8d83d00a0df6f7f5a02f3bc047a7fd1acb6570511f680ad44997fa97b91 |
|
MD5 | efc507a234a739a91198c37304f4c324 |
|
BLAKE2b-256 | 187ab84a89797c0f358522ece51ed18d7e0721658e011fba538123b4d96e33b6 |
Hashes for rocksdict-0.3.5-cp39-cp39-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c509921f86f9ff6cfa96be115faa651708cd11d4d6cff85b4e2a6ee52011901 |
|
MD5 | 9a15e1e7736561b8ae019b79e1bc6d83 |
|
BLAKE2b-256 | 14f157b8f5d4eb0aef895e8c79c62e5c21a5d5d6a99cef2d1eab2c9369caa69e |
Hashes for rocksdict-0.3.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60c73c25235c2b3cb8b9dbac8c86fa2b1cc2ba1c7e9eaac6e2b99b2d01744ba9 |
|
MD5 | e9aa6998d2eb36602619f479b95aaefa |
|
BLAKE2b-256 | 80f91cf7941db197182f785743375125a2670442dd452ff3bd9ac91aab3a318e |
Hashes for rocksdict-0.3.5-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96a3cb556abc06833b6fa2e7c4452af5312f19759df6f6643c4dc4cf819e270e |
|
MD5 | 9a7008246b7ca78419509092320fb2d9 |
|
BLAKE2b-256 | 7bb3b22e1819bbe0ea58a7fb1d3c1564e3e4a1174806549dc098f6590bce03f5 |
Hashes for rocksdict-0.3.5-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 274e9742d57f112d10fb672658d9fc95f0e261884a0dea09af3ac8ca9f05a8f0 |
|
MD5 | 06493607795b10bb61ef7cd1c4bb5708 |
|
BLAKE2b-256 | 8f926c292a586ea19d86359d342c2353beec1ab664bdc0fe18a5e5340bf88aaa |
Hashes for rocksdict-0.3.5-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c7f6de33b453536af0debefa6986150f06ebbe160687e18530287a5f7943b4f |
|
MD5 | 5bc2605e557710227b45996dc1c94008 |
|
BLAKE2b-256 | acaaea345b08bd77256bbd6d2512ff8a7ca565fd8923445ff5f256c9d360f6a7 |
Hashes for rocksdict-0.3.5-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29ddc56d68f84ffa166664ff5906e7bafe1e927494f231822c493ca15e60b06e |
|
MD5 | 0b69bdedacddf1eb791bafc88e18ded0 |
|
BLAKE2b-256 | 152c228ada2cb7698d93960c3886a145690df1ab8e9e4b15acf486e3ee53523c |
Hashes for rocksdict-0.3.5-cp38-cp38-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e834e8665c6d5e26750a6b9c0ae25377f9303543ccd9a5c00bf22e1687dd8af4 |
|
MD5 | 21b59bc69873bcf0b0c51bfd3f68588b |
|
BLAKE2b-256 | 6e6ea271c63fb663761ea3b53ada79ce7d386fb211e782a62b4cce8289ce050b |
Hashes for rocksdict-0.3.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c4302e7e2eadfc7f16d3c91b8b2542816d36f35a51bf88c7f83607b2cbb797f |
|
MD5 | 2d58facb109096454448c8200b81a637 |
|
BLAKE2b-256 | 63a1d10afb390baa3fb0650e4ac67d5bfa3a33223484b7523cb986d0c5ee0a93 |
Hashes for rocksdict-0.3.5-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c92afd754532f8634fa16fff8187851de7326501429ee680f7058b1b4387653 |
|
MD5 | e5f1aa43cb84034bf173f20bef2cfff3 |
|
BLAKE2b-256 | 3e94dd0d16429a09a24dcd1f5c03119aae13e6c69a295bdcd8a805bba86f977f |
Hashes for rocksdict-0.3.5-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e9ff5e7f2e0f9480f74be3b3690489dfe4e957e9dda1636fb3e91679440bd12 |
|
MD5 | c45804cb0120c9d5bad80120ac055dac |
|
BLAKE2b-256 | 828f6ac82c945c6ded2901e45f84b2e8c4ffbb295178729f648d2459a454bb88 |
Hashes for rocksdict-0.3.5-cp37-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a6d78ca75b6faf9331336ab33fc0c311ccfe8bbe98afd75ff54c2fc500fd0b1 |
|
MD5 | f086c37cd61c88476e3537379ac6d4ea |
|
BLAKE2b-256 | a92a333f422471d0180bed05abf67ffacd011457b0f0f9a7828585f48747aa9d |
Hashes for rocksdict-0.3.5-cp37-cp37m-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b69dadb325d2b8846a1b85b13507e107ae5354419def11ee7314ad36f52a30a |
|
MD5 | 0c1875bea55452da9a2c0fd39c6008cb |
|
BLAKE2b-256 | 146d1914bdf37aa7a57e118ae03207420de154012f0cb7c147c8f87096fc04d1 |
Hashes for rocksdict-0.3.5-cp37-cp37m-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8769635a59db155f2a5d6ce4e624a4bd05a9c88281f486a629c5321243bec3af |
|
MD5 | 4fddaf5b6f4cbf50422219d3dbd6dea0 |
|
BLAKE2b-256 | ffa639d77df7fedcc2f44b0583701770a2e03a87a64016f98b4b52eac46b2bf2 |
Hashes for rocksdict-0.3.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a6cae900f197922a23114f518eeee6261e798e953ee400c549f912602a2d9bc |
|
MD5 | a545ca02b221aa29a9fd93fe529c0776 |
|
BLAKE2b-256 | 55a57784d50f63840c2e7bf269fbbc7bf5dca36af8d874887e2afe9867aca4ee |
Hashes for rocksdict-0.3.5-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4a3dda682a4a5368753c788f868a039257bb444933fb023e01fd2718abad93d |
|
MD5 | 9ccf793474429c2a0b229f20f8db2583 |
|
BLAKE2b-256 | 76155c77f6dd5d71e51ba3b112596385344e8cf204d511babe6b7fe720b4b927 |