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
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
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
Hashes for rocksdb_py-0.0.2-cp310-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75738688acc02d3898a12ed25a75a0d1de3fca167454e6f81b91792a8df03a8d |
|
MD5 | 70b1b45926e458e2dfbce43da70f3c9e |
|
BLAKE2b-256 | 0bfaae14fd28a4218c7fbc48533b045d38996f14c71addf148678600fcc7e158 |
Hashes for rocksdb_py-0.0.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fe4f6d0f88f5faa914cc1ebca3ea876a27c5fd81cb2fd1493b5df839b8922e9 |
|
MD5 | a22e382583a8869e4f5a17eda9a87b56 |
|
BLAKE2b-256 | 2af1d76a7b14f55236e160086b3dc7c9dae63cdfbde34efd7c831b4469bea8fd |
Hashes for rocksdb_py-0.0.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ccb069884feed4feb805fd3177ef5edf1c7ec3209013610074aa71b3b62c8ff |
|
MD5 | 86891081063b99663a0479ce7900108f |
|
BLAKE2b-256 | 00966e522d32e61c584320c3ddf751ec09c0414fa6a5160668d183efd1232029 |
Hashes for rocksdb_py-0.0.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d2dcdb83522b2d212fda9f9df086c59eb385c76f24b3271e129ab86784fa120 |
|
MD5 | 0dd416739f199db04c918ee189d5b6fd |
|
BLAKE2b-256 | 80012108565eb48aae88ccb2b1989765c5a42b1c332e9362aba61fd611c45de2 |
Hashes for rocksdb_py-0.0.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 573f01cd026652a45c3538986c0669407bde6c0378ec4ea00b50516d74afa0cc |
|
MD5 | d50de7d298ce961387773e1425340b5c |
|
BLAKE2b-256 | daadcf38fdca7c6d1cf0c65dd642dc16e5ad767c249946a0cd5b902489b30588 |
Hashes for rocksdb_py-0.0.2-cp37-none-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed9d13fef91dbfc5c783bc409f2ae0c5d1d963b1556fc08060f0e2b0455da11a |
|
MD5 | b15764d724bcc6229eb56f9bf27e6d8c |
|
BLAKE2b-256 | c2095c3cef86d6f5bed7be7857a864ac3fae03d02cc88565c8de836dccd0eabc |
Hashes for rocksdb_py-0.0.2-cp37-cp37m-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 930e3fdcff45a1ed6e30f927b42b53bef35d7d511260c4bb274861ee8dc0fd69 |
|
MD5 | 66885052c3f426e5e2bb56d896569882 |
|
BLAKE2b-256 | 0228e605002167f9290d4020345177dbba9e737f8da14c43730ffd1d51efca20 |
Hashes for rocksdb_py-0.0.2-1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcc8a10d2c48c5d8cb53508971616adf416ded1488089fb4344df8147c7b5873 |
|
MD5 | 4cec2ff15a8252284813c92594d47dd7 |
|
BLAKE2b-256 | c10c5c01203703d941f97f75bb1e1eff18a0ffe723611405495d5369c256218e |