A mock for the ScyllaDB Python driver for testing purposes.
Project description
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") == []
🔍 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. |
📄 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.
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
Built Distribution
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 mockylla-0.2.0.tar.gz.
File metadata
- Download URL: mockylla-0.2.0.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96b3cfa17e053c722fc14be5c27f4a3a18fe13a5a640563596791d74f288223c
|
|
| MD5 |
22a64bc46681de6cd081eab626065605
|
|
| BLAKE2b-256 |
2e7890025739b93862652423410f3e24715d73b5f390c7ca8f7e57d995d62257
|
Provenance
The following attestation bundles were made for mockylla-0.2.0.tar.gz:
Publisher:
pypi_release.yml on GenLogs/mockylla
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mockylla-0.2.0.tar.gz -
Subject digest:
96b3cfa17e053c722fc14be5c27f4a3a18fe13a5a640563596791d74f288223c - Sigstore transparency entry: 253613726
- Sigstore integration time:
-
Permalink:
GenLogs/mockylla@bbab92c879dd83e4503b7a9a8d52c0fd4de70241 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/GenLogs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@bbab92c879dd83e4503b7a9a8d52c0fd4de70241 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mockylla-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mockylla-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0fe4ecf6140eff09231b4d61318f418ff02a004c85617afd0cf2d998756fa3c
|
|
| MD5 |
67c0767e821f998f846ac12028a65392
|
|
| BLAKE2b-256 |
c2549d7e52358fbab910f746da5a5a90ce05f8ceda598190426b0e8dd72443e9
|
Provenance
The following attestation bundles were made for mockylla-0.2.0-py3-none-any.whl:
Publisher:
pypi_release.yml on GenLogs/mockylla
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mockylla-0.2.0-py3-none-any.whl -
Subject digest:
b0fe4ecf6140eff09231b4d61318f418ff02a004c85617afd0cf2d998756fa3c - Sigstore transparency entry: 253613727
- Sigstore integration time:
-
Permalink:
GenLogs/mockylla@bbab92c879dd83e4503b7a9a8d52c0fd4de70241 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/GenLogs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@bbab92c879dd83e4503b7a9a8d52c0fd4de70241 -
Trigger Event:
push
-
Statement type: