Python bindings for RocksDB
Project description
rocksdb-py
Python bindings for RocksDB written in Rust.
Features
- Get, set, delete, multi get
- Destroy
- Batch write
- Database iterator
- Read options
- Backup DB
Install
To install a wheel from PyPI,
pip install --upgrade rocksdb-py
or if you want to build a wheel, see build.
Usage
Open database
Open a database with default options.
import rocksdbpy
db = rocksdbpy.open_default('/tmp/rocksdb')
Open a database with the specified options.
opts = Option()
opts.create_if_missing(True)
db = rocksdbpy.open('/tmp/rocksdb', opts)
Open a database with TTL compaction filter.
opts = Option()
opts.create_if_missing(True)
db = rocksdbpy.open_with_ttl('/tmp/rocksdb', 5, opts)
Destroy the database and it's files.
rocksdbpy.destroy('/tmp/rocksdb')
Close active database and release lock.
db.close()
Simple read, set and delete
Set records by key and value.
db.set(b'key', b'value')
Get a value associated with a key.
value = db.get(b'key')
Remove existing records by key.
db.delete(b'key')
Batch write, database iterator and flush
Set database entries for list of key and values as a batch.
from rocksdbpy import WriteBatch
batch = WriteBatch()
batch.add(b'first', b'1')
batch.add(b'second', b'2')
db.write(batch)
Extra operations for the batch.
batch.delete(b'first')
batch.clear()
size = batch.len()
Return a heap-allocated iterator over the contents of the database.
iterator = db.iterator()
iterator = db.iterator(mode='end')
iterator = db.iterator(mode='from', key=b'test')
iterator = db.iterator(mode='from', key=b'test', direction=-1)
for key, value in iterator:
print(key, value)
Flush database memtables to SST files on the disk using default options.
db.flush()
Read options
Set database read options.
opts = Option()
opts.create_if_missing(True)
opts.set_max_open_files(10)
opts.set_use_fsync(True)
opts.set_bytes_per_sync(1024 * 1024)
# and more
Backup and Restore
You can create a backup of your database
db.create_backup('/tmp/backup_rocksdb')
Please note, this is NOT A DATABASE! This is a backup, it will need to be restored.
from rocksdbpy import RocksDB
RocksDB.restore_latest_backup('/tmp/backup_rocksdb', '/tmp/new_rocksdb')
opts.create_if_missing(True)
db_restore = rocksdbpy.open('/tmp/new_rocksdb', opts)
Build
You can build PIP package by using maturin. The example below is created for MacOS,
$ git clone https://github.com/trk54ylmz/rocksdb-py.git
$ cd rocksdb-py
$ maturin build
$ pip3 install ./target/wheels/rocksdb_py-0.0.1-cp39-cp39-macosx_11_0_arm64.whl
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rocksdb_py-0.0.7-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fcd646b285201250718bfa6cc3294890acfe17bb2cf8f48a11feadd87e9c07d
|
|
| MD5 |
14be245569bd2c8308abb8381570aa7e
|
|
| BLAKE2b-256 |
a95c7145a0250abf722c4d56090afec1ec09af50b7dc070c5132307ac5dad1d1
|
File details
Details for the file rocksdb_py-0.0.7-cp313-cp313-macosx_13_0_x86_64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp313-cp313-macosx_13_0_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.13, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c772034b1091b9347631b3dcd9ead65a4372b26a652ea3c2a6d048d6e909ae2
|
|
| MD5 |
c5df840b166c7ef0533a8e8575623c52
|
|
| BLAKE2b-256 |
d80745a4bde210556f0be39723e99e6b06a16a68d2cd5b937c4642700095cf62
|
File details
Details for the file rocksdb_py-0.0.7-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0671895860c7d21c2fa0caf94559ca324b4ba102b3a0b55e2d1ca9caf196dc4
|
|
| MD5 |
1e6cc9cbe6d0ff2eca6c6d6fba2d34e3
|
|
| BLAKE2b-256 |
3677ef88a6957573d4340b9d90d8da0c237840ecbc65c23f8fa798ebfae5ae5a
|
File details
Details for the file rocksdb_py-0.0.7-cp312-cp312-macosx_13_0_x86_64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp312-cp312-macosx_13_0_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.12, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31fb4b9de1a0f38f5ace25ee73091850b292bc8a771003e4b40b20d699054d3b
|
|
| MD5 |
32157de8354f0ffe3849a310caa06994
|
|
| BLAKE2b-256 |
5a0d546bd200132cce16ae96868638958716568df991776b9b78de54b4b5b86f
|
File details
Details for the file rocksdb_py-0.0.7-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11c2d78b53b2185a91a4185394cab14cb8c2975d3e80c9440b482e455e32ceef
|
|
| MD5 |
617e8b4c1863173a70b2576272795aad
|
|
| BLAKE2b-256 |
48c273d2ba74029b184ef83b86ca79112cd6f03a4be914777868a48d5a8f60e1
|
File details
Details for the file rocksdb_py-0.0.7-cp311-cp311-macosx_13_0_x86_64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp311-cp311-macosx_13_0_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.11, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2afd47c1d14c6fb5d5a8e45ff12b7b0041aa37ef9a01e443fba30a824500d09
|
|
| MD5 |
657e30d07a42580782a2ba8b6c5d64d9
|
|
| BLAKE2b-256 |
d350428b156c58d48e854fe5c5875276fa3feff60d81b773b2c93a5747d1fd3f
|
File details
Details for the file rocksdb_py-0.0.7-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6f18ed5fe2250878ede0d21cbad37cc20a0ae6f880cb7e052f347d76511571b
|
|
| MD5 |
bb129d2e7551326d8ead45b32bd1575c
|
|
| BLAKE2b-256 |
af84e759c5869c211687b63cc326a6fc0daeabd175ba2e13d0cb53629f6b9922
|
File details
Details for the file rocksdb_py-0.0.7-cp310-cp310-macosx_13_0_x86_64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp310-cp310-macosx_13_0_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.10, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3888859f1d2045b1983a9434cf89722c09d850ac3d6e185e06f5c57e021a04d
|
|
| MD5 |
f1aea19f0670f19a39343062797a69ec
|
|
| BLAKE2b-256 |
bd5c1b735fabd5589bf5fdae308fa63a3e1e182063b2d35f2941b2a3c7e0532c
|
File details
Details for the file rocksdb_py-0.0.7-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.4 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8be31335fa73891ffc68edb3b28adc4976ae355746b08b0fa909ccf44037bc81
|
|
| MD5 |
943d28a225474be2f3afe5ee11752c2a
|
|
| BLAKE2b-256 |
908c479f79b203c6645c0a013020757fc992263fcf16dcbd72047a4a6e6a3b46
|
File details
Details for the file rocksdb_py-0.0.7-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba68baca2ed43fc243c7bfa8211fa6d9177355f0b39bd6b468503fa9672867a8
|
|
| MD5 |
3a056768dc666c6e8079bbfa87a79e46
|
|
| BLAKE2b-256 |
f8427e8f3301d39c480cfa0010e12b2f9cf0abded87aee8994a05d309c0bf24a
|
File details
Details for the file rocksdb_py-0.0.7-cp39-cp39-macosx_13_0_x86_64.whl.
File metadata
- Download URL: rocksdb_py-0.0.7-cp39-cp39-macosx_13_0_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.9, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69517213169c77ce8493f1a656108f1c214d04ce1fb76ad10f48b41ec9bc091e
|
|
| MD5 |
5664b5f56076f6f0d5f450e2401e5e58
|
|
| BLAKE2b-256 |
2282bb015fc71f4f6dc5b0e6275a6cb1e3b6be7def75479d8bea49ec5d46a4e4
|