Fast Python bindings for the UnQLite embedded NoSQL database.
npx @tessl/cli install tessl/pypi-unqlite@0.9.0Fast Python bindings for UnQLite, a lightweight, embedded NoSQL database and JSON document store. UnQLite provides both key/value storage capabilities and a JSON document store with Jx9 scripting language support, offering ACID transactions, cursors for record traversal, and support for terabyte-sized databases.
pip install unqliteimport unqliteMain database class:
from unqlite import UnQLiteAdditional classes and exceptions:
from unqlite import UnQLiteError, Transaction, Cursor, VM, Collectionimport unqlite
# Create an in-memory database
db = unqlite.UnQLite(':mem:')
# Store and retrieve key-value pairs
db['key'] = 'value'
print(db['key']) # 'value'
# Check if key exists
if 'key' in db:
print("Key exists")
# Iterate over all items
for key, value in db.items():
print(f"{key}: {value}")
# Close database
db.close()
# Use as context manager for automatic cleanup
with unqlite.UnQLite('mydatabase.db') as db:
db['user:1'] = {'name': 'Alice', 'age': 30}
user = db['user:1']UnQLite provides multiple interfaces for different use cases:
The library is built as a Cython extension providing high-performance access to the underlying UnQLite C library, with automatic encoding/decoding between Python objects and database storage formats.
Core database operations for storing, retrieving, and managing key-value pairs. Includes dictionary-style interface, bulk operations, and existence checks.
class UnQLite:
def store(self, key, value): ...
def fetch(self, key): ...
def delete(self, key): ...
def exists(self, key): ...
def append(self, key, value): ...
def update(self, dict values): ...
def __setitem__(self, key, value): ...
def __getitem__(self, key): ...
def __delitem__(self, key): ...
def __contains__(self, key): ...
def keys(self): ...
def values(self): ...
def items(self): ...
def range(self, start_key, end_key, include_end_key=True): ...
def __len__(self): ...
def __iter__(self): ...Database lifecycle management including connection handling, configuration, and bulk operations.
class UnQLite:
def __init__(self, filename=':mem:', flags=UNQLITE_OPEN_CREATE, open_database=True, thread_safe=True): ...
def open(self): ...
def close(self): ...
def flush(self): ...
def __enter__(self): ...
def __exit__(self, exc_type, exc_val, exc_tb): ...ACID transaction support for file-based databases with manual and context manager interfaces.
class UnQLite:
def begin(self): ...
def commit(self): ...
def rollback(self): ...
def transaction(self): ...
def commit_on_success(self, fn): ...
def disable_autocommit(self): ...
class Transaction:
def __enter__(self): ...
def __exit__(self, exc_type, exc_val, exc_tb): ...Efficient database traversal and iteration capabilities for large datasets with positioning and filtering support.
class Cursor:
def reset(self): ...
def seek(self, key, flags=...): ...
def first(self): ...
def last(self): ...
def next_entry(self): ...
def previous_entry(self): ...
def key(self): ...
def value(self): ...
def delete(self): ...
def is_valid(self): ...
def fetch_until(self, stop_key, include_stop_key=True): ...Embedded Jx9 scripting engine for complex database operations and JSON manipulation with variable management.
class VM:
def compile(self): ...
def execute(self): ...
def reset(self): ...
def close(self): ...
def set_value(self, name, value): ...
def get_value(self, name): ...
def set_values(self, dict data): ...
def __setitem__(self, name, value): ...
def __getitem__(self, name): ...High-level document store interface for managing JSON documents with querying, filtering, and schema support.
class Collection:
def create(self): ...
def drop(self): ...
def exists(self): ...
def store(self, record, return_id=True): ...
def fetch(self, record_id): ...
def update(self, record_id, record): ...
def delete(self, record_id): ...
def all(self): ...
def filter(self, filter_fn): ...
def set_schema(self, _schema=None, **kwargs): ...
def get_schema(self): ...Random data generation and library information utilities.
class UnQLite:
def random_string(self, int nbytes): ...
def random_int(self): ...
def lib_version(self): ...Database open flags and configuration constants.
# Database open flags
UNQLITE_OPEN_READONLY: int
UNQLITE_OPEN_READWRITE: int
UNQLITE_OPEN_CREATE: int
UNQLITE_OPEN_EXCLUSIVE: int
UNQLITE_OPEN_TEMP_DB: int
UNQLITE_OPEN_NOMUTEX: int
UNQLITE_OPEN_OMIT_JOURNALING: int
UNQLITE_OPEN_IN_MEMORY: int
UNQLITE_OPEN_MMAP: int
# Cursor positioning flags
UNQLITE_CURSOR_MATCH_EXACT: int
UNQLITE_CURSOR_MATCH_LE: int
UNQLITE_CURSOR_MATCH_GE: intError handling and exception types for database operations.
class UnQLiteError(Exception):
def __init__(self, msg, errno): ...
@property
def errno(self): ...
@property
def error_message(self): ...
def __repr__(self): ...Standard Python exceptions are also used:
KeyError: Raised when accessing non-existent keysMemoryError: Raised when out of memoryNotImplementedError: Raised for unsupported operations