Skip to main content

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 Distribution

rocksdb_py-0.0.5.tar.gz (54.1 kB view hashes)

Uploaded Source

Built Distributions

rocksdb_py-0.0.5-cp311-none-win_amd64.whl (2.4 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

rocksdb_py-0.0.5-cp311-cp311-manylinux_2_31_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.31+ x86-64

rocksdb_py-0.0.5-cp311-cp311-macosx_11_0_arm64.whl (2.9 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rocksdb_py-0.0.5-cp311-cp311-macosx_10_14_x86_64.whl (3.2 MB view hashes)

Uploaded CPython 3.11 macOS 10.14+ x86-64

rocksdb_py-0.0.5-cp310-none-win_amd64.whl (2.4 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

rocksdb_py-0.0.5-cp310-cp310-manylinux_2_31_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.31+ x86-64

rocksdb_py-0.0.5-cp310-cp310-macosx_11_0_arm64.whl (2.9 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rocksdb_py-0.0.5-cp310-cp310-macosx_10_14_x86_64.whl (3.2 MB view hashes)

Uploaded CPython 3.10 macOS 10.14+ x86-64

rocksdb_py-0.0.5-cp39-none-win_amd64.whl (2.4 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

rocksdb_py-0.0.5-cp39-cp39-manylinux_2_31_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.31+ x86-64

rocksdb_py-0.0.5-cp39-cp39-macosx_11_0_arm64.whl (2.9 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rocksdb_py-0.0.5-cp39-cp39-macosx_10_14_x86_64.whl (3.2 MB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

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