Kimberlite Python SDK
Status: 🚧 In Progress (Phase 11.2)
Pythonic client library for Kimberlite database.
Installation
pip install kimberlite
Quick Start
Stream Operations
from kimberlite import Client, DataClass
# Connect with context manager
with Client.connect(
addresses=["localhost:5432"],
tenant_id=1,
auth_token="secret"
) as client:
# Create stream
stream_id = client.create_stream("events", DataClass.PHI)
# Append events
events = [b"event1", b"event2", b"event3"]
offset = client.append(stream_id, events)
# Read events
results = client.read(stream_id, from_offset=0, max_bytes=1024)
for event in results:
print(f"Offset {event.offset}: {event.data}")
SQL Queries
from kimberlite import Client, Value
with Client.connect(addresses=["localhost:5432"], tenant_id=1) as client:
# Create table
client.execute("""
CREATE TABLE users (
id BIGINT PRIMARY KEY,
name TEXT,
email TEXT,
active BOOLEAN,
created_at TIMESTAMP
)
""")
# Insert data with parameterized queries
client.execute(
"INSERT INTO users (id, name, email, active, created_at) VALUES ($1, $2, $3, $4, $5)",
[
Value.bigint(1),
Value.text("Alice"),
Value.text("alice@example.com"),
Value.boolean(True),
Value.timestamp(1609459200_000_000_000) # 2021-01-01 UTC
]
)
# Query data
result = client.query(
"SELECT * FROM users WHERE active = $1",
[Value.boolean(True)]
)
for row in result.rows:
id_val = row[result.columns.index('id')]
name_val = row[result.columns.index('name')]
print(f"User {id_val.data}: {name_val.data}")
# Point-in-time query (compliance audit)
from kimberlite.types import Offset
historical_offset = Offset(1000)
historical_result = client.query_at(
"SELECT COUNT(*) FROM users",
[],
historical_offset
)
Features
Stream Operations
- Create and manage event streams
- Append events with automatic batching
- Read events with offset-based pagination
- Type hints for IDE autocomplete
SQL Query Engine
- Core SQL: SELECT (aggregates, GROUP BY/HAVING, UNION, INNER/LEFT JOIN, CTEs, subqueries, window functions), INSERT, UPDATE, DELETE, DDL
- Parameterized queries with type-safe Value objects
- Point-in-time queries (
AT OFFSET) for compliance audits;AS OF TIMESTAMPplanned v0.6 - All SQL types: NULL, BIGINT, TEXT, BOOLEAN, TIMESTAMP
Python Integration
- Context managers for automatic resource cleanup
- Type hints and mypy strict mode support
- Rich exception hierarchy for error handling
- Pythonic API design
Compliance Features
- Query historical state at any log position
- Immutable audit trail
- Data classification (PHI, Non-PHI, De-identified)
Usage Examples
Working with Value Types
from kimberlite import Value
from datetime import datetime
# Create values
null_val = Value.null()
int_val = Value.bigint(42)
text_val = Value.text("Hello, 世界!")
bool_val = Value.boolean(True)
ts_val = Value.timestamp(1609459200_000_000_000)
# From Python datetime
dt = datetime(2024, 1, 1, 12, 0, 0)
ts_from_dt = Value.from_datetime(dt)
# Convert timestamp back to datetime
dt_back = ts_val.to_datetime()
print(dt_back.isoformat()) # "2021-01-01T00:00:00"
CRUD Operations
# CREATE
client.execute("""
CREATE TABLE products (
id BIGINT PRIMARY KEY,
name TEXT,
price BIGINT,
in_stock BOOLEAN
)
""")
# INSERT
client.execute(
"INSERT INTO products (id, name, price, in_stock) VALUES ($1, $2, $3, $4)",
[Value.bigint(1), Value.text("Widget"), Value.bigint(1999), Value.boolean(True)]
)
# UPDATE
client.execute(
"UPDATE products SET price = $1 WHERE id = $2",
[Value.bigint(2499), Value.bigint(1)]
)
# DELETE
client.execute(
"DELETE FROM products WHERE id = $1",
[Value.bigint(1)]
)
# SELECT
result = client.query("SELECT * FROM products WHERE in_stock = $1", [Value.boolean(True)])
for row in result.rows:
print(row)
Compliance Audit Example
from kimberlite.types import Offset
# Record initial state
checkpoint_offset = Offset(client.log_position()) # Hypothetical API
# Make changes
client.execute("UPDATE users SET email = $1 WHERE id = $2", [
Value.text("newemail@example.com"),
Value.bigint(1)
])
# Later: Audit what the state was at checkpoint
historical_result = client.query_at(
"SELECT email FROM users WHERE id = $1",
[Value.bigint(1)],
checkpoint_offset
)
# Returns the old email, proving what the state was at that point in time
Documentation
- API Reference (coming soon)
- Protocol Specification
- SDK Architecture
- Query Examples
Installation (Development)
# Build FFI library
cd ../../
cargo build -p kimberlite-ffi
# Install Python SDK in development mode
cd sdks/python
pip install -e .
Development Status
SDK Implementation:
- ctypes-based FFI wrapper
- Stream operations (create, append, read)
- SQL query engine (SELECT, INSERT, UPDATE, DELETE, DDL)
- Parameterized queries with Value types
- Point-in-time queries (query_at)
- Type hints and mypy strict mode
- Comprehensive unit tests (48+ tests for values, 5+ for queries)
- Integration tests
- Wheel distribution with bundled binaries
- PyPI publishing
Value Type System:
- NULL, BIGINT, TEXT, BOOLEAN, TIMESTAMP
- DateTime conversion helpers
- Equality and hashing support
- Type-safe constructors
Metadata
Release files for kimberlite 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kimberlite-0.9.1-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for kimberlite-0.9.1-py3-none-win_amd64.whl |
| kimberlite-0.9.1-py3-none-manylinux_2_17_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details for kimberlite-0.9.1-py3-none-manylinux_2_17_x86_64.whl |
| kimberlite-0.9.1-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for kimberlite-0.9.1-py3-none-macosx_11_0_arm64.whl |
Total release size: 1.4 MB
Release files / kimberlite-0.9.1-py3-none-win_amd64.whl
| Download URL | kimberlite-0.9.1-py3-none-win_amd64.whl |
|---|---|
| Size | 376.4 kB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0fe828b937bc63638868edfbb4b0a2529f3df2b60e32ea40918f34d5dd54ea19
|
|
BLAKE2b-256 checksum How to use checksums |
3a13ee7f0d459632b6fdd84da8ef3039161f1bbee237282bd18c502fcc91cf81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / kimberlite-0.9.1-py3-none-manylinux_2_17_x86_64.whl
| Download URL | kimberlite-0.9.1-py3-none-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 517.2 kB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
846061ac190fbc4c4d9476a2c97160bafe63dcae6d2a3edaf897427b8e53831c
|
|
BLAKE2b-256 checksum How to use checksums |
91a4385be9781fe188cb02eb2850187db7a7c9e0ed2a91e84685a24f12331076
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / kimberlite-0.9.1-py3-none-macosx_11_0_arm64.whl
| Download URL | kimberlite-0.9.1-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 469.4 kB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ca5bc0f15dbf6a3abba081c6ec1978a92eca13025de8e676c1c3c37df5ec00d3
|
|
BLAKE2b-256 checksum How to use checksums |
00982c8bc99ef7adeb5f8c409e4bd71e0a40dbfcc41ce10184797595bd43ea8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for kimberlite 0.9.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.