Python bindings for CQLite - read Cassandra 5.0 SSTables locally without a cluster
Project description
cqlite-py
Python bindings for CQLite - a high-performance library for reading Apache Cassandra 5.0 SSTable files locally, without requiring a running Cassandra cluster.
Installation
pip install cqlite-py
Quick Start
import cqlite
# Open a database with schema
with cqlite.open('path/to/sstables', schema='schema.cql') as db:
# Execute queries
for row in db.execute('SELECT * FROM keyspace.table LIMIT 10'):
print(row.to_dict())
Features
- Zero cluster dependency - Read SSTable files directly from disk
- Full CQL type support - All primitive types, collections, UDTs, and frozen types
- Memory-efficient streaming - Iterate over large datasets without loading all rows
- Thread-safe database handles - Safe concurrent access from multiple threads
- Cross-platform - Linux (x86_64, ARM64), macOS (Intel, Apple Silicon), Windows
Supported Platforms
| Platform | Architecture | Status |
|---|---|---|
| Linux | x86_64 | ✅ |
| Linux | ARM64 | ✅ |
| macOS | Intel (x86_64) | ✅ |
| macOS | Apple Silicon | ✅ |
| Windows | x64 | ✅ |
Requirements
- Python 3.9+
- Cassandra 5.0 SSTable files
API Reference
Opening a Database
import cqlite
# Context manager (recommended)
with cqlite.open(data_dir, schema=schema_path) as db:
# use db...
# Manual management
db = cqlite.open(data_dir, schema=schema_path)
# use db...
db.close()
Executing Queries
# Simple query
results = db.execute('SELECT * FROM keyspace.table')
for row in results:
print(row.to_dict())
# With LIMIT
for row in db.execute('SELECT name, age FROM users LIMIT 100'):
print(f"{row['name']}: {row['age']}")
# Access query metadata
print(f"Rows returned: {len(results)}")
print(f"Execution time: {results.execution_time_ms}ms")
print(f"Columns: {[col.name for col in results.columns]}")
Streaming Large Results
For memory-efficient iteration over large datasets:
from cqlite import StreamingConfig
# Configure streaming for memory efficiency
config = StreamingConfig(buffer_size=512, chunk_size=1000)
for row in db.execute_streaming('SELECT * FROM large_table', config=config):
process(row)
# Track progress
iterator = db.execute_streaming('SELECT * FROM large_table')
for row in iterator:
if iterator.rows_received % 10000 == 0:
print(f"Processed {iterator.rows_received} rows")
Configuration Presets
import cqlite
# Built-in presets for common use cases
config = cqlite.memory_optimized() # 256 MB max memory
config = cqlite.performance_optimized() # 4 GB max memory
# Open database with preset configuration
db = cqlite.open('path/to/data', schema='schema.cql', config='memory_optimized')
# Validate custom configuration
custom_config = {'memory': {'max_memory': 536870912}} # 512 MB
cqlite.validate_config(custom_config)
Error Handling
import cqlite
try:
with cqlite.open('path/to/data', schema='schema.cql') as db:
result = db.execute('SELECT * FROM keyspace.table')
for row in result:
print(row.to_dict())
except cqlite.ParseError as e:
print(f"Query syntax error: {e}")
except cqlite.QueryError as e:
print(f"Query execution failed: {e}")
except cqlite.SchemaError as e:
print(f"Schema validation failed: {e}")
except IOError as e:
print(f"File not found: {e}")
except RuntimeError as e:
print(f"Database already closed: {e}")
Exception Hierarchy:
CqliteError (base exception)
├── SchemaError - Schema parsing or validation failures
├── QueryError - Query execution failures
└── ParseError - CQL syntax errors
Built-in exceptions also used:
├── IOError - File system errors
├── ValueError - Invalid configuration
├── RuntimeError - Invalid state (e.g., database closed)
└── MemoryError - Memory allocation failures
Type Conversions
CQL types are automatically converted to Python native types:
| CQL Type | Python Type |
|---|---|
text, varchar |
str |
int, bigint, smallint, tinyint |
int |
float, double |
float |
boolean |
bool |
blob |
bytes |
timestamp |
datetime.datetime |
date |
datetime.date |
time |
datetime.time |
duration |
datetime.timedelta |
uuid, timeuuid |
uuid.UUID |
inet |
ipaddress.IPv4Address or IPv6Address |
decimal |
decimal.Decimal |
varint |
int (arbitrary precision) |
list<T> |
list |
set<T> |
frozenset |
map<K,V> |
dict |
tuple<...> |
tuple |
frozen<T> |
Unwrapped inner type |
| UDT | dict with _type and _keyspace keys |
Write Operations
CQLite v0.9.0 adds write support to the Python bindings. Open the database with
writable=True and a write_dir to enable write operations.
import cqlite
with cqlite.open(
'path/to/sstables',
schema='schema.cql',
writable=True,
write_dir='/tmp/my-writes',
) as db:
# Write rows via CQL INSERT, UPDATE, or DELETE
db.execute(
"INSERT INTO test_basic.simple_table (id, name, age) "
"VALUES (11111111-1111-1111-1111-111111111111, 'Alice', 30)"
)
db.execute(
"UPDATE test_basic.simple_table SET age = 31 "
"WHERE id = 11111111-1111-1111-1111-111111111111"
)
# Flush the in-memory write buffer (memtable) to an SSTable on disk.
# Returns the path to the flushed Data.db file.
path = db.flush_run()
print(f'Flushed to: {path}')
# Run background compaction within a time budget
report = db.maintenance_step(budget_ms=100)
print(f'Merged {report.rows_merged} rows in {report.time_spent_ms:.1f} ms')
if report.pending_compaction:
print('More compaction work available')
# Inspect write statistics
stats = db.write_stats
print(f'Memtable size: {stats.memtable_size_bytes} bytes')
print(f'Total flushed: {stats.total_written_bytes} bytes')
Write API
| Method / Property | Description |
|---|---|
db.execute(cql) |
Execute a CQL INSERT, UPDATE, or DELETE statement |
db.flush_run() |
Flush memtable to SSTable; returns the Data.db path or "" if memtable was empty |
db.maintenance_step(budget_ms) |
Run STCS compaction for up to budget_ms milliseconds; returns MaintenanceReport |
db.write_stats |
WriteStats property: memtable_size_bytes, memtable_row_count, total_written_bytes, l0_sstable_count |
Known Limitations
- Counter columns cannot be written —
execute()raisesCqliteErrorfor counter mutations. - Concurrent queries on the same handle may need a warm-up query first (Issue #311).
See docs/write-support-limitations.md for the full limitations reference.
Resources
- Acceptance Testing Notebook - Interactive examples and validation
- Type Stubs - Complete API type hints for IDE support
- Main Project README - CQLite project overview and documentation
- Write Support Guide - Detailed write documentation
- Issue Tracker - Report bugs or request features
License
MIT OR Apache-2.0
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cqlite_py-0.9.1.tar.gz.
File metadata
- Download URL: cqlite_py-0.9.1.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffdf1d0bec452bfb22cfe90a05b95bd10b8a9c3211473a7cf59350602cf196a7
|
|
| MD5 |
dbb57208538f1d4c3d8816ae0f79eaad
|
|
| BLAKE2b-256 |
f53cae03dd8f3d4f572482c927a019e2455a109e22a7a6e5048679ca2861ed0c
|
Provenance
The following attestation bundles were made for cqlite_py-0.9.1.tar.gz:
Publisher:
python-release.yml on pmcfadin/cqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cqlite_py-0.9.1.tar.gz -
Subject digest:
ffdf1d0bec452bfb22cfe90a05b95bd10b8a9c3211473a7cf59350602cf196a7 - Sigstore transparency entry: 1672515635
- Sigstore integration time:
-
Permalink:
pmcfadin/cqlite@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/pmcfadin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yml@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cqlite_py-0.9.1-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: cqlite_py-0.9.1-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea96e2007fc5cd8a2ea9b3de9f793ffd3bd203b8f971e058b6a163d654612b85
|
|
| MD5 |
ac21318ab0a0338f66c8fa525cfbedc9
|
|
| BLAKE2b-256 |
74eb1f794c26571a041476ea3a85c6139c45af5504ad04ad95be833346f6d0cd
|
Provenance
The following attestation bundles were made for cqlite_py-0.9.1-cp39-abi3-win_amd64.whl:
Publisher:
python-release.yml on pmcfadin/cqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cqlite_py-0.9.1-cp39-abi3-win_amd64.whl -
Subject digest:
ea96e2007fc5cd8a2ea9b3de9f793ffd3bd203b8f971e058b6a163d654612b85 - Sigstore transparency entry: 1672515720
- Sigstore integration time:
-
Permalink:
pmcfadin/cqlite@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/pmcfadin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yml@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cqlite_py-0.9.1-cp39-abi3-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: cqlite_py-0.9.1-cp39-abi3-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89d93fbe4de92d9636abad19f91ce42304ea4e3f29125fc54ec951a1040f7549
|
|
| MD5 |
fcaf965fa495dad76426914527d4d289
|
|
| BLAKE2b-256 |
b82f571cdd66e3431a79e8a2669b07cef5ab5f39b45fa2874c741a991e7bd3fd
|
Provenance
The following attestation bundles were made for cqlite_py-0.9.1-cp39-abi3-manylinux_2_28_x86_64.whl:
Publisher:
python-release.yml on pmcfadin/cqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cqlite_py-0.9.1-cp39-abi3-manylinux_2_28_x86_64.whl -
Subject digest:
89d93fbe4de92d9636abad19f91ce42304ea4e3f29125fc54ec951a1040f7549 - Sigstore transparency entry: 1672515754
- Sigstore integration time:
-
Permalink:
pmcfadin/cqlite@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/pmcfadin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yml@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cqlite_py-0.9.1-cp39-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: cqlite_py-0.9.1-cp39-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc8b641d71687faec10b5bb2149d0a2902c9000d4dd2c46dffdaf0fb6c6e5f15
|
|
| MD5 |
58719165f323d69331a982050634bf2a
|
|
| BLAKE2b-256 |
96542bd3c1cf5f75c1bfcf2a95966ee3b3c42c786214eb6c732390a64b5f4fd8
|
Provenance
The following attestation bundles were made for cqlite_py-0.9.1-cp39-abi3-manylinux_2_28_aarch64.whl:
Publisher:
python-release.yml on pmcfadin/cqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cqlite_py-0.9.1-cp39-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
dc8b641d71687faec10b5bb2149d0a2902c9000d4dd2c46dffdaf0fb6c6e5f15 - Sigstore transparency entry: 1672515864
- Sigstore integration time:
-
Permalink:
pmcfadin/cqlite@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/pmcfadin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yml@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cqlite_py-0.9.1-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: cqlite_py-0.9.1-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.1 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42707a36a7fcdcddd28eea3c00752d83a53e28630f0ae36f0b155e9f28391e0b
|
|
| MD5 |
851cb46df1c5176011a7cb02b95f3d71
|
|
| BLAKE2b-256 |
c3a9b5528513c46d4591121bc46a02631cb92e0228341cc8f96fd6c23539baaa
|
Provenance
The following attestation bundles were made for cqlite_py-0.9.1-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
python-release.yml on pmcfadin/cqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cqlite_py-0.9.1-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
42707a36a7fcdcddd28eea3c00752d83a53e28630f0ae36f0b155e9f28391e0b - Sigstore transparency entry: 1672515689
- Sigstore integration time:
-
Permalink:
pmcfadin/cqlite@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/pmcfadin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yml@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cqlite_py-0.9.1-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: cqlite_py-0.9.1-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.3 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbc6bac099b71c4785374a9edbbb92a7baed8f5d774ccebad16e9dcf1f3fd3fd
|
|
| MD5 |
d51e37e1c33551c271e02f149cf8ed81
|
|
| BLAKE2b-256 |
e423aa945212f961b4f52bea4eea16b2556de3d761198f467a0e2a1ebfe6d307
|
Provenance
The following attestation bundles were made for cqlite_py-0.9.1-cp39-abi3-macosx_10_12_x86_64.whl:
Publisher:
python-release.yml on pmcfadin/cqlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cqlite_py-0.9.1-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
bbc6bac099b71c4785374a9edbbb92a7baed8f5d774ccebad16e9dcf1f3fd3fd - Sigstore transparency entry: 1672515800
- Sigstore integration time:
-
Permalink:
pmcfadin/cqlite@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/pmcfadin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yml@af5750507a4f2e4e40502248f794aba9eb4a28a9 -
Trigger Event:
push
-
Statement type: