Skip to main content

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() raises CqliteError for 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

License

MIT OR Apache-2.0

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cqlite_py-0.11.0.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cqlite_py-0.11.0-cp39-abi3-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.9+Windows x86-64

cqlite_py-0.11.0-cp39-abi3-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ x86-64

cqlite_py-0.11.0-cp39-abi3-manylinux_2_28_aarch64.whl (3.8 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

cqlite_py-0.11.0-cp39-abi3-macosx_11_0_arm64.whl (3.4 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

cqlite_py-0.11.0-cp39-abi3-macosx_10_12_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file cqlite_py-0.11.0.tar.gz.

File metadata

  • Download URL: cqlite_py-0.11.0.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cqlite_py-0.11.0.tar.gz
Algorithm Hash digest
SHA256 f793cfa12d1ca7a3b63530a37bcab8f0dca80b079c9cf021e090ed2d7953e36b
MD5 33a4fed9626884f3e56538edb2b20240
BLAKE2b-256 4d15c86faec36404cf1c6e3c5feabb7275c8fd3e1d4e7ae392c0ce36c6fc8fb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cqlite_py-0.11.0.tar.gz:

Publisher: python-release.yml on pmcfadin/cqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cqlite_py-0.11.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: cqlite_py-0.11.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.7 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

Hashes for cqlite_py-0.11.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 26c4c2911fdc49883f6e263671326f438a34633871eb6656836d4a3c13eed7af
MD5 12f0cafd17bb0febc877b13ebcb3471f
BLAKE2b-256 a761feb2554e7c136c92dd7a8dd7877563e1de91257323f1310d26e22f815ae3

See more details on using hashes here.

Provenance

The following attestation bundles were made for cqlite_py-0.11.0-cp39-abi3-win_amd64.whl:

Publisher: python-release.yml on pmcfadin/cqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cqlite_py-0.11.0-cp39-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cqlite_py-0.11.0-cp39-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 59c9fd37cae60f5884858e2b8c15106bf08fd0921f24eca416c368e0ded8d279
MD5 70a65a46c7282fdb30385c2330226223
BLAKE2b-256 69adc11ff2b1323f62cf561dff69c7c8f680bc1873ab6e69aceff793f3d14335

See more details on using hashes here.

Provenance

The following attestation bundles were made for cqlite_py-0.11.0-cp39-abi3-manylinux_2_28_x86_64.whl:

Publisher: python-release.yml on pmcfadin/cqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cqlite_py-0.11.0-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cqlite_py-0.11.0-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4a2037fd93d5f0756e472ae61f4c77476dc6d05c916568bb07c5160604b83fd3
MD5 ad4b3ba36f3f21413c8358be7d60c16a
BLAKE2b-256 f1a2b1a59eb08b6c2b67cc2d18b78e5fefafbcd65fc16c17a3cce0751cd320d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for cqlite_py-0.11.0-cp39-abi3-manylinux_2_28_aarch64.whl:

Publisher: python-release.yml on pmcfadin/cqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cqlite_py-0.11.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cqlite_py-0.11.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b1052dc2650391a9992aa5365c21087a2e0b5afff6c538cbc379ddda90598a6
MD5 142feede656ae2065ac9a6b376a61157
BLAKE2b-256 5bf79f5516805e222e3a82528ea043d792dbd21f95c2ba13c0afca624b485fd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for cqlite_py-0.11.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: python-release.yml on pmcfadin/cqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cqlite_py-0.11.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for cqlite_py-0.11.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 55ec7035eca94893dd5f20decacbb6f9faec783314b0333dfb54eb277846e0d7
MD5 adcb558322889884988561215dfe4326
BLAKE2b-256 4aa0fb7cadab503e37a58653b08ae0e733f69a6364425cdc00e8135b73941a0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cqlite_py-0.11.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: python-release.yml on pmcfadin/cqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page