Python

Python client for ChronDB, a time-traveling key/value database built on Git architecture.

Requirements

  • Python 3.8+

Installation

Install directly from the latest GitHub releasearrow-up-right:

macOS (Apple Silicon):

pip install https://github.com/avelino/chrondb/releases/download/latest/chrondb-latest-py3-none-macosx_14_0_arm64.whl

Linux (x86_64):

pip install https://github.com/avelino/chrondb/releases/download/latest/chrondb-latest-py3-none-manylinux_2_35_x86_64.whl

The 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:

  1. CHRONDB_LIB_PATH — full path to the library file

  2. CHRONDB_LIB_DIR — directory containing the library

  3. Bundled lib/ inside the package

  4. System paths: /usr/local/lib, /usr/lib

Quick Start

API Reference

ChronDB(data_path: str, index_path: str)

Opens a database connection.

Parameter
Type
Description

data_path

str

Path for the Git repository (data storage)

index_path

str

Path for the Lucene index

Raises: ChronDBError if the database cannot be opened.

Implements the context manager protocol (__enter__ / __exit__), calling close() automatically on exit.


put(id, doc, branch=None) -> Dict[str, Any]

Saves a document.

Parameter
Type
Description

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.

Parameter
Type
Description

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.

Parameter
Type
Description

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.

Parameter
Type
Description

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.

Parameter
Type
Description

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.

Parameter
Type
Description

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.

Parameter
Type
Description

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.


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)

Pytest Fixture

Building from Source

Last updated