On-disk Dict With RocksDB (dbm alternative)
Project description
RocksDict
Key-value storage supporting any python object
Abstract
This package enables users to store, query, and delete a large number of key-value pairs on disk.
This is especially useful when the data cannot fit into RAM. If you have hundreds of GBs or many TBs of key-value data to store and query from, this is the package for you.
Installation
This packakge is built for MacOS (x86/arm), Windows 64/32, and Linux x86.
It can be installed from pypi with pip install rocksdict
.
Introduction
Below is a code example that shows how to do the following:
- Create Rdict
- Store something on disk
- Close Rdict
- Open Rdict again
- Check Rdict elements
- Iterate from Rdict
- Batch get
- Delete storage
from rocksdict import Rdict, Options
path = str("./test_dict")
# create a Rdict with default options at `path`
db = Rdict(path)
# storing numbers
db[1.0] = 1
db[1] = 1.0
# very big integer
db["huge integer"] = 2343546543243564534233536434567543
# boolean values
db["good"] = True
db["bad"] = False
# bytes
db["bytes"] = b"bytes"
# store anything
db["this is a list"] = [1, 2, 3]
db["store a dict"] = {0: 1}
# for example numpy array
import numpy as np
import pandas as pd
db[b"numpy"] = np.array([1, 2, 3])
db["a table"] = pd.DataFrame({"a": [1, 2], "b": [2, 1]})
# close Rdict
db.close()
# reopen Rdict from disk
db = Rdict(path)
assert db[1.0] == 1
assert db[1] == 1.0
assert db["huge integer"] == 2343546543243564534233536434567543
assert db["good"] == True
assert db["bad"] == False
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
del db
Rdict.destroy(path, Options())
Supported types:
- key:
int, float, bool, str, bytes
- value:
int, float, bool, str, bytes
and anything that supportspickle
.
Rocksdb Options
Since the backend is implemented using rocksdb, most of rocksdb options are supported:
Example of tuning
from rocksdict import Rdict, Options, SliceTransform, PlainTableFactoryOptions
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
db = Rdict("./some_path", db_options())
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.2.7-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d68660dc2f625408cedb15dc606e9b81827a112856352497f3d39009e3751d4b |
|
MD5 | 3a896c3ae8d4c7bde503648c2b933fd4 |
|
BLAKE2b-256 | 9b0e3a57153809d11a3614b4e1f42bd98971b6b71d30c808ad8359386124227d |
Hashes for rocksdict-0.2.7-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95c6fd128b5d8d0e45781afcd7333767bdc47dfaccba4a06c6ede3449c81d224 |
|
MD5 | aac7de7e53a04de0bf2fd6e64e01f6f3 |
|
BLAKE2b-256 | 825b75839a97317feaaffad2e6abe7bf1c46641b9ed48880805d5a818524c227 |
Hashes for rocksdict-0.2.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c3d58c8a954bdb4d92eb6c89298a8d54191f49b99fd94ac69e3534080c3d9c3 |
|
MD5 | aea8ea00a4c53a6d4789c80d11b46183 |
|
BLAKE2b-256 | de56b62f2d894ec32a174fcaf1c6dc03ed5c2553e548a377965cfd151f3d4b19 |
Hashes for rocksdict-0.2.7-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5336dc59f958b86d7ec17fd55812a9976d925a93e75469dba0cddc12c95940ae |
|
MD5 | 4edf08db2a9d04427f1ffb8dd28d4bbb |
|
BLAKE2b-256 | a769c2bc2e87ad69c584dff12491c421d029417ee93d18ab20645f8e1915bd8a |
Hashes for rocksdict-0.2.7-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b25682df296be2b4e346c4c20ac7c91e38b81083f472940eb3b389b1e4f4284f |
|
MD5 | fba0c7ecade2764094a96ed03b54fe0e |
|
BLAKE2b-256 | 59958b645ebc0fc4c63f569d29c836da349e9c1104ba5613c2f3706b62a576b3 |
Hashes for rocksdict-0.2.7-cp39-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8de9f622c2c18a9dca99ae43b7b71a2dffdaaf59bbe338e9424d5d1b60a1c833 |
|
MD5 | 09bbd8e3fffeab63dd85bbfb64ab59f3 |
|
BLAKE2b-256 | 5043d44ac06afcef716c049e85423d430c6bb0e2771761dad50a6dd1b6a65835 |
Hashes for rocksdict-0.2.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3063f2ae57e93bbee17fc0c6af72ac2adda455922bd1c8e05bebaeb38a8a4783 |
|
MD5 | 52cc6444124c384522e31c6bc07eeaf4 |
|
BLAKE2b-256 | 3a2cd57df0c097300fe9cb86a8a523413fc77a3672eb97ce058c21b6836473d8 |
Hashes for rocksdict-0.2.7-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbc0afd3668f6621e053f8048f4e9ff0c131badd9d0ab0ca490c65c351459a6f |
|
MD5 | e8e4d1c1a95629a6f283e5c79af19b30 |
|
BLAKE2b-256 | de7ad098e8a7c583abef874de5c9affa76077d0443a067fcbeef877c6777928d |
Hashes for rocksdict-0.2.7-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 026412c6850c045bbe6bf16fc519ca3956db6be8e888bdbf9cdffc9dba75a87c |
|
MD5 | 20196d35f7b9137be89d246e4f5c26f5 |
|
BLAKE2b-256 | 07ff1b63d64f0a205278c2b47f86201d5344fc00d61be811574c974a960c02b4 |
Hashes for rocksdict-0.2.7-cp38-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aff4ec1257ee070e53dcd77e852a0200486c6897c67a939f93b5c93ae5d6a64 |
|
MD5 | f775db12a4c3402234dfacf700528fc2 |
|
BLAKE2b-256 | c957d566203ad6e7c55e984989a4951bb293244db4a5e7c7694033cfa691e674 |
Hashes for rocksdict-0.2.7-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65b684c3cf4b796fb6a42291b65eb757ee13b592cc25a22e2b1feb6344a0c8b8 |
|
MD5 | d5e65e09226ab83488bdcff6a463189d |
|
BLAKE2b-256 | 2d84b0a072c01a8e3ebc828551aad2af1eef12146c95789f7541a820cc2bdf9f |
Hashes for rocksdict-0.2.7-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf00236820b995e362cd085c8a6f586e1674e9cc1570e9b9c284f53c3b41bbe6 |
|
MD5 | 556c0177da0533bb71d3648aa275d385 |
|
BLAKE2b-256 | 628c0ce235f48a4f5fe109f0342304bde75d81c07534eb94b39d826a51753611 |
Hashes for rocksdict-0.2.7-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0964e8b0777faf32e3614a7be111ac5633435855e44ddcf8ee186f70bb47e4c6 |
|
MD5 | fd530208f551c73939a8a9bb4981e256 |
|
BLAKE2b-256 | 9239e8e73dd4c09a9c2ccb9ea3a422c6f68cb6e91b8fd96f89cbd8c143b9a61e |
Hashes for rocksdict-0.2.7-cp37-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae3a04deff159efa6de9dc18266ea0a2f0c0fd6d019d00ae0fd8c3f83526eb9e |
|
MD5 | 18e89ed55bcdf12ea5425ddc83297383 |
|
BLAKE2b-256 | 1a43226328f99eec8b160ecddee0854970a02211afc4f212f1803370296323f5 |
Hashes for rocksdict-0.2.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23cabce1fa0f8d74833c6dd671f9bc72c96f37cc74bf8933ec83f399f32b1105 |
|
MD5 | 44b9124a0a54010f2e91a36034166136 |
|
BLAKE2b-256 | 542077c5772d73020879b32f46bb3b53d4f0c6455dfec0c83659cdaf8a836fae |
Hashes for rocksdict-0.2.7-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87a98623f9fbaa0fec1df853bd537f7d696c63a7ef20fe43f30eb51d8cad294c |
|
MD5 | d5adf9573b5de47264a50538025865b2 |
|
BLAKE2b-256 | 5a3afe3cb29d5bb3acd02829060ac6e84e1feff6b725bdb6f5b85485bdd806f4 |
Hashes for rocksdict-0.2.7-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 277e79aa5331252398098c43405f2d0a999dcee73cd1da343f297ad192caa4a8 |
|
MD5 | 08835854f7624567af8eddfa95fc9c0f |
|
BLAKE2b-256 | 50ed3e45bdbd56961b35f0f6da92e7727de99be0d8238f5065f5c93001dddf06 |
Hashes for rocksdict-0.2.7-cp36-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 788ddc85b11f8fde07b3ee9d63da07d3b5c0bdefb5183a60e3377f03ffeccfc2 |
|
MD5 | 8bb38152c1a3249eb1b6235ac0267013 |
|
BLAKE2b-256 | 00bc38f295570df056da9ca2e5e41ea589612c7f2e6398a1dc5a3c77021fc21c |
Hashes for rocksdict-0.2.7-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4e9b64ac114c94fbed8c5971478314e9be5e682266a6ece8076723a8d21c2b8 |
|
MD5 | 144fa6e6f87b3d49cbd00ba8925832d3 |
|
BLAKE2b-256 | 66f8a1fb674c9270c46c5c8972016359d9f867cd86fa7438e872de556b228dd1 |
Hashes for rocksdict-0.2.7-cp36-cp36m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d74e9475cb6f402690d85ff1492fcf4b7827aff3a95ba74b39de68fccbf615b1 |
|
MD5 | 322818e9080b4e055d0be78593991d08 |
|
BLAKE2b-256 | 03a3865d807659798584b6e85034a2037691e847d88352d83de67e84ead12b44 |