Python
Python client for ChronDB, auto-generated from the Rust SDK via UniFFI.
Requirements
Python 3.8+
Installation
Install directly from the latest GitHub release:
macOS (Apple Silicon):
pip install https://github.com/avelino/chrondb/releases/download/latest/chrondb-latest-py3-none-macosx_14_0_arm64.whlLinux (x86_64):
pip install https://github.com/avelino/chrondb/releases/download/latest/chrondb-latest-py3-none-manylinux_2_35_x86_64.whlThe wheel already includes the native shared library — no extra configuration needed.
Library path (advanced)
If you need to override the bundled library (e.g., using a custom build), the binding searches in this order:
CHRONDB_LIB_PATH— full path to the library fileCHRONDB_LIB_DIR— directory containing the libraryBundled
lib/inside the packageSystem paths:
/usr/local/lib,/usr/lib
Quick Start
Legacy API (deprecated):
ChronDB("/tmp/data", "/tmp/index")still works but is deprecated. Use the single-path form instead.
API Reference
ChronDB(db_path: str, idle_timeout: float = None)
Opens a database connection using a single directory path. Data and index are stored in subdirectories automatically.
db_path
str
Path for the database (data and index stored inside)
idle_timeout
Optional[float]
Seconds of inactivity before suspending the GraalVM isolate. None (default) keeps it alive for the entire lifetime.
When idle_timeout is set, the GraalVM isolate is automatically closed after the specified seconds of inactivity, freeing CPU and memory. The next operation transparently reopens it. See Idle Timeout for details.
Raises: ChronDBError if the database cannot be opened.
Implements the context manager protocol (__enter__ / __exit__), calling close() automatically on exit.
Legacy: ChronDB(data_path: str, index_path: str, idle_timeout: float = None)
Deprecated. The two-path constructor still works but is deprecated. Use the single-path form above.
data_path
str
Path for the Git repository (data storage)
index_path
str
Path for the Lucene index
idle_timeout
Optional[float]
Seconds of inactivity before suspending the GraalVM isolate
put(id, doc, branch=None) -> Dict[str, Any]
Saves a document.
id
str
Document ID (e.g., "user:1")
doc
Dict[str, Any]
Document data
branch
Optional[str]
Branch name (None for default)
Returns: The saved document as a dictionary.
Raises: ChronDBError on failure.
get(id, branch=None) -> Dict[str, Any]
Retrieves a document by ID.
id
str
Document ID
branch
Optional[str]
Branch name
Returns: The document as a dictionary.
Raises: DocumentNotFoundError if not found, ChronDBError on failure.
delete(id, branch=None) -> bool
Deletes a document by ID.
id
str
Document ID
branch
Optional[str]
Branch name
Returns: True if deleted.
Raises: DocumentNotFoundError if not found, ChronDBError on failure.
list_by_prefix(prefix, branch=None) -> List[Dict[str, Any]]
Lists documents whose IDs start with the given prefix.
prefix
str
ID prefix to match
branch
Optional[str]
Branch name
Returns: List of matching documents (empty list if none).
list_by_table(table, branch=None) -> List[Dict[str, Any]]
Lists all documents in a table.
table
str
Table name
branch
Optional[str]
Branch name
Returns: List of matching documents (empty list if none).
history(id, branch=None) -> List[Dict[str, Any]]
Returns the change history of a document.
id
str
Document ID
branch
Optional[str]
Branch name
Returns: List of history entries (empty list if none).
query(query, branch=None) -> Dict[str, Any]
Executes a query against the Lucene index.
query
Dict[str, Any]
Query in Lucene AST format
branch
Optional[str]
Branch name
Returns: Results dict with keys results, total, limit, offset.
Raises: ChronDBError on failure.
execute(sql, branch=None) -> Dict[str, Any]
Executes a SQL query directly against the database without needing a running server.
sql
str
SQL query string
branch
Optional[str]
Branch name (None for default)
Returns: Result dict with keys type, columns, rows, count.
Raises: ChronDBError on failure.
setup_remote(remote_url) -> Dict[str, Any]
Configures a remote Git repository URL for syncing.
Returns: {"type": "ok", "remote_url": "..."} on success.
Raises: ChronDBError on failure.
push() -> Dict[str, Any]
Pushes local changes to the configured remote repository.
Returns: {"type": "ok", "status": "pushed"} on success, {"type": "ok", "status": "skipped"} if no remote is configured.
Raises: ChronDBError on failure.
pull() -> Dict[str, Any]
Pulls changes from the configured remote repository. Fetches and fast-forwards the local branch.
Returns: {"type": "ok", "status": "pulled|current|skipped|conflict"}.
Raises: ChronDBError on failure.
fetch() -> Dict[str, Any]
Fetches changes from the configured remote without merging.
Returns: {"type": "ok", "status": "fetched|skipped"}.
Raises: ChronDBError on failure.
remote_status() -> Dict[str, Any]
Returns whether a remote repository is configured.
Returns: {"type": "ok", "configured": true|false}.
Raises: ChronDBError on failure.
close()
Closes the database connection and releases native resources. Called automatically when using the context manager.
Document ID Convention
Documents use the format table:id:
Internally, user:123 is stored as user/user_COLON_123.json in the Git repository.
Use list_by_table("user") to retrieve all documents in the user table.
Error Handling
Exception Hierarchy
ChronDBError
Base exception for all ChronDB errors (connection failures, operation errors, native library issues).
DocumentNotFoundError
Raised by get() and delete() when the target document does not exist.
Example
Examples
Full CRUD
Query
History (Time Travel)
SQL Queries
Execute SQL queries directly without needing a running server:
Remote Sync
Idle Timeout (long-running services)
ChronDB loads a GraalVM native-image shared library whose internal threads consume CPU even when no operations are in flight. For long-running services with sporadic database access, use idle_timeout to automatically suspend the isolate when idle:
When to use:
Long-running daemons that write to ChronDB intermittently (e.g., audit logging, MCP servers)
Services where memory/CPU usage matters during idle periods
When NOT to use:
Short-lived scripts (just use
ChronDB(...)without timeout)High-throughput services with constant database access (the isolate would never go idle)
Pytest Fixture
Export & Backup
Export to Directory
Backup & Restore
Building from Source
Last updated
Was this helpful?