API Reference
This page summarizes the public Python API exposed by pyrex-rocksdb.
PyRocksDB
PyRocksDB(path, options=None, read_only=False) opens a RocksDB database that
uses the default column family.
Methods:
put(key: bytes, value: bytes, write_options=None) -> Noneget(key: bytes, read_options=None) -> bytes | Nonedelete(key: bytes, write_options=None) -> Nonewrite(write_batch: PyWriteBatch, write_options=None) -> Nonewrite_columnar_batch(keys, values, *, write_options=None, on_null="error") -> Nonenew_iterator(read_options=None) -> PyRocksDBIteratorget_options() -> PyOptionsclose() -> None
write_columnar_batch accepts Arrow binary/string arrays or list[bytes] /
tuple[bytes] fallback inputs. It validates lengths and nulls before writing
and applies all rows through one native RocksDB WriteBatch.
PyRocksDBExtended
PyRocksDBExtended extends PyRocksDB with column-family management.
Methods:
put_cf(cf_handle, key: bytes, value: bytes, write_options=None) -> Noneget_cf(cf_handle, key: bytes, read_options=None) -> bytes | Nonedelete_cf(cf_handle, key: bytes, write_options=None) -> Nonelist_column_families() -> list[str]create_column_family(name: str, cf_options=None) -> ColumnFamilyHandledrop_column_family(cf_handle) -> Noneget_column_family(name: str) -> ColumnFamilyHandle | Nonenew_cf_iterator(cf_handle, read_options=None) -> PyRocksDBIteratordefault_cfreturns the default column-family handle.
PyWriteBatch
PyWriteBatch accumulates write operations that are applied atomically with
PyRocksDB.write.
Methods:
put(key: bytes, value: bytes) -> Noneput_cf(cf_handle, key: bytes, value: bytes) -> Nonedelete(key: bytes) -> Nonedelete_cf(cf_handle, key: bytes) -> Nonemerge(key: bytes, value: bytes) -> Nonemerge_cf(cf_handle, key: bytes, value: bytes) -> Noneclear() -> None
TransactionDB
TransactionDB(path, options=None, transaction_db_options=None) opens a
RocksDB database with pessimistic transaction support.
Methods:
put(key: bytes, value: bytes, write_options=None) -> Noneget(key: bytes, read_options=None) -> bytes | Nonedelete(key: bytes, write_options=None) -> Nonewrite(write_batch: PyWriteBatch, write_options=None) -> Nonebegin_transaction(write_options=None, transaction_options=None) -> Transactiontransaction(write_options=None, transaction_options=None) -> Transactionget_options() -> PyOptionsget_transaction_db_options() -> TransactionDBOptionsclose() -> None
transaction() is an alias for begin_transaction() intended for context
manager usage. Transaction context managers require an explicit commit();
they roll back automatically if still active on exit.
Transaction
Transaction represents one active RocksDB transaction.
Methods and properties:
put(key: bytes, value: bytes) -> Noneget(key: bytes, read_options=None) -> bytes | Noneget_for_update(key: bytes, read_options=None, exclusive=True, do_validate=True, read_value=True) -> bytes | Nonedelete(key: bytes) -> Nonewrite(write_batch: PyWriteBatch) -> Nonecommit(write_options=None) -> Nonerollback() -> Noneset_snapshot() -> Nonenew_iterator(read_options=None) -> PyTransactionIteratoris_active -> bool
Transaction reads see prior writes in the same transaction. write accepts
existing PyWriteBatch objects for default column-family put and
delete operations.
get_for_update reads and tracks a key for transaction conflict checking. Set
read_value=False to lock or track the key without fetching the value; the
method returns None in that mode.
PyTransactionIterator
Transaction iterators traverse the transaction view and can be used for prefix or range scans by seeking to the lower bound and stopping in Python.
Methods:
valid() -> boolseek_to_first() -> Noneseek_to_last() -> Noneseek(key: bytes) -> Nonenext() -> Noneprev() -> Nonekey() -> bytes | Nonevalue() -> bytes | Nonecheck_status() -> None
PyRocksDBIterator
Iterators traverse keys in RocksDB byte order.
Methods:
valid() -> boolseek_to_first() -> Noneseek_to_last() -> Noneseek(key: bytes) -> Nonenext() -> Noneprev() -> Nonekey() -> bytes | Nonevalue() -> bytes | Nonecheck_status() -> None
Options
PyOptions configures database open options and column-family defaults.
Common properties and methods:
create_if_missingerror_if_existsmax_open_fileswrite_buffer_sizecompressionmax_background_jobscf_write_buffer_sizecf_compressionincrease_parallelism(total_threads)optimize_for_small_db()use_block_based_bloom_filter(bits_per_key=10.0)
WriteOptions configures write operations.
Properties:
syncdisable_wal
ReadOptions configures read operations.
Properties:
fill_cacheverify_checksums
TransactionDBOptions configures transaction-capable database open options.
Properties:
transaction_lock_timeoutdefault_lock_timeoutmax_num_locksnum_stripes
TransactionOptions configures each transaction.
Properties:
set_snapshotlock_timeoutexpirationdeadlock_detect
CompressionType
The CompressionType enum exposes RocksDB compression choices, including
kNoCompression, kSnappyCompression, kLZ4Compression, and kZSTD.
Exceptions
RocksDBException is raised for RocksDB operational errors, closed database
usage, invalid column-family handles, and read-only write attempts.
More specific subclasses are exposed for callers that need retry or recovery policy:
RocksDBConflictErrorRocksDBTimeoutErrorRocksDBBusyErrorRocksDBCorruptionErrorRocksDBIOErrorRocksDBInvalidArgumentError
Capabilities
has_transactions is True when the installed build exposes the
transaction API.