mockylla
A lightweight, in-memory mock for the ScyllaDB Python driver.
mockylla allows you to run integration-style tests for code that depends on ScyllaDB without requiring a live cluster.
✨ Key Features
- Drop-in replacement | Patch the
scylla-driverat runtime with a single decorator – no changes to your application code. - Fast & isolated | All state lives in-memory and is reset between tests, ensuring perfect test isolation.
- Inspectable | Helper utilities expose the internal state so you can assert against keyspaces, tables, and rows.
- Pythonic API | Mirrors the real driver's public API to minimise cognitive load and surprises.
- No network dependencies | Works entirely offline; ideal for CI pipelines and contributor development environments.
📦 Installation
pip install mockylla
mockylla supports Python 3.8 → 3.11 and is continuously tested against the latest scylla-driver release.
🚀 Quick Start
from mockylla import mock_scylladb, get_keyspaces
from cassandra.cluster import Cluster
@mock_scylladb
def test_my_app_creates_a_keyspace():
# Arrange – connect to the mocked cluster (no real network I/O!)
cluster = Cluster(["127.0.0.1"])
session = cluster.connect()
# Act – run application logic
session.execute(
"""
CREATE KEYSPACE my_app_keyspace \
WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1}
"""
)
# Assert – inspect mock state
assert "my_app_keyspace" in get_keyspaces()
Tip Place
@mock_scylladbon individual tests or a session-scoped fixture to enable the mock for an entire module.
🏗️ Comprehensive Example
from mockylla import mock_scylladb, get_table_rows
from cassandra.cluster import Cluster
@mock_scylladb
def test_crud():
cluster = Cluster()
session = cluster.connect()
session.execute(
"CREATE KEYSPACE ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}"
)
session.set_keyspace("ks")
session.execute(
"""
CREATE TABLE users (
user_id int PRIMARY KEY,
name text,
email text
)
"""
)
# INSERT
session.execute("INSERT INTO users (user_id, name, email) VALUES (1, 'Alice', 'alice@example.com')")
# SELECT
assert session.execute("SELECT name FROM users WHERE user_id = 1").one().name == "Alice"
# UPDATE
session.execute("UPDATE users SET email = 'alice@new.com' WHERE user_id = 1")
# DELETE
session.execute("DELETE FROM users WHERE user_id = 1")
# Final state check
assert get_table_rows("ks", "users") == []
📚 Examples
Browse the examples/ directory for more focused walkthroughs:
examples/00-basic-usage.md– scaffold a keyspace, table, and CRUD flow with the decorator.examples/01-prepared-statements.md– prepare, bind, and execute statements with tuple or mapping parameters.examples/02-batch-operations.md– mix stringBEGIN BATCHblocks withBatchStatementhelpers and mock batches.examples/03-async-queries.md– exerciseexecute_asyncflows and callbacks without a real cluster.examples/04-introspecting-state.md– inspect keyspaces, tables, UDTs, and rows via the helper utilities.
🔍 Public API
| Function / Decorator | Description |
|---|---|
mock_scylladb |
Context-manages the mock driver by patching cassandra.connection.Connection.factory & Cluster.connect. |
get_keyspaces() |
Return a dict of keyspace names → definition. |
get_tables(keyspace) |
Return a dict of table names → definition. |
get_table_rows(keyspace, table) |
Return the current rows for table as a list[dict]. |
get_types(keyspace) |
Return user-defined types for the keyspace. |
🗂️ Package Structure
The implementation now lives in the mockylla/classes/ package, split into focused modules:
state.py– in-memoryScyllaStateand helpers for inspecting tables, rows, and types.statements.py– prepared/bound/batch statement shims plus placeholder utilities.session.py–MockSession,MockCluster, and async response primitives.metadata.py– lightweight metadata facades mirroring the driver objects.scylladb.py– context manager + decorator that patch the driver and bootstrap state.
The top-level mockylla/__init__.py re-exports the public API unchanged for consumers.
📄 License
mockylla is distributed under the MIT license.
🙌 Acknowledgements
- Inspired by the fantastic
motoproject for AWS. - Built on top of the official
scylla-driverby ScyllaDB.
Metadata
Release files for mockylla 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mockylla-0.5.0.tar.gz | 66.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mockylla-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 107.2 kB
Release files / mockylla-0.5.0.tar.gz
| Download URL | mockylla-0.5.0.tar.gz |
|---|---|
| Size | 66.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
294e4d02d23ffcad32d9261221126355c7c15bfaa9698e43f822f5564c79fc71
|
|
BLAKE2b-256 checksum How to use checksums |
5b59ab5f3351a7aa3b50c40c88e956f2ccabade7e2d166a0ffe80e9d02e2aff8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2025.
Transparency logRelease files / mockylla-0.5.0-py3-none-any.whl
| Download URL | mockylla-0.5.0-py3-none-any.whl |
|---|---|
| Size | 40.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f46a1b82e3c0844792a8b51866657bb1e9a8b217b8f6a1740770cea4a093e7f
|
|
BLAKE2b-256 checksum How to use checksums |
3a26e81e80cefc424353029cc172055ccf825511d763ebb7fa81f8f4ec61fcfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2025.
Transparency log