aimrocks
raw JSON → 0.5.2 verified Mon Apr 27 auth: no python
High-performance Python RocksDB wrapper implemented in Cython, based on facebook/rocksdb. Version 0.5.2 is the latest release, with sporadic updates. Aimed at users needing key-value storage with RocksDB's LSM-tree engine.
pip install aimrocks Common errors
error TypeError: an integer is required (got type str) ↓
cause Passing string instead of bytes for key or value.
fix
Use bytes:
db.put(b'key', b'value'). error ImportError: No module named 'rocksdb' ↓
cause RocksDB C++ library not installed on the system.
fix
Install system RocksDB:
sudo apt-get install librocksdb-dev (Linux) or brew install rocksdb (macOS). error Compilation failed: unable to execute 'x86_64-linux-gnu-gcc' ↓
cause Missing build tools or Python development headers.
fix
Run
apt-get install build-essential python3-dev beforehand. Warnings
gotcha RocksDB must be installed on the system (librocksdb-dev) before pip installing aimrocks. Missing system rocksdb will cause compilation failures. ↓
fix Install RocksDB library: e.g., `apt-get install librocksdb-dev` (Debian/Ubuntu) or `brew install rocksdb` (macOS).
breaking aimrocks 0.5.x changed the namespace from `aimrocks` to `rocksdb`. Older code importing `aimrocks` directly will break. ↓
fix Use `import rocksdb` instead of `import aimrocks`.
gotcha Keys and values must be bytes objects. Passing strings will raise TypeError or silently fail. ↓
fix Always encode strings to bytes: `db.put(b'key', b'value')` or `db.put('key'.encode(), 'value'.encode())`.
Install
pip install aimrocks==0.5.2 Imports
- DB
import rocksdb db = rocksdb.DB('/path/to/db', rocksdb.Options(create_if_missing=True)) - Options wrong
from aimrocks import Optionscorrectfrom rocksdb import Options
Quickstart
import rocksdb
opts = rocksdb.Options()
opts.create_if_missing = True
db = rocksdb.DB('/tmp/test.db', opts)
db.put(b'key', b'value')
print(db.get(b'key'))
db.close()