coodieο
The modern Pydantic-based ODM for Cassandra & ScyllaDB
Define your data models as Python classes, and coodie handles schema synchronization, serialization, and query building β with both sync and async APIs.
β¨ Feature Highlightsο
|
𧬠Pydantic v2 Models β full type-checking & validation |
π Automatic Schema Sync β |
π¦ Installationο
pip install coodie
Choose a driver extra for your cluster:
pip install "coodie[scylla]" # ScyllaDB / Cassandra (recommended)
pip install "coodie[cassandra]" # Cassandra via cassandra-driver
pip install "coodie[acsylla]" # Async-native via acsylla
π Quick Startο
1. Start a local ScyllaDB (or use an existing cluster):
docker run --name scylla -d -p 9042:9042 scylladb/scylla --smp 1
# Wait for it to be ready (~30s), then create a keyspace
docker exec -it scylla cqlsh -e \
"CREATE KEYSPACE IF NOT EXISTS my_ks
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};"
2. Install coodie:
pip install "coodie[scylla]"
3. Write your first script:
from coodie.sync import Document, init_coodie
from coodie.fields import PrimaryKey
from pydantic import Field
from typing import Annotated
from uuid import UUID, uuid4
# Connect
init_coodie(hosts=["127.0.0.1"], keyspace="my_ks")
# Define a model
class User(Document):
id: Annotated[UUID, PrimaryKey()] = Field(default_factory=uuid4)
name: str
email: str
class Settings:
name = "users"
# Sync schema & insert
User.sync_table()
user = User(name="Alice", email="[email protected]")
user.save()
# Query
print(User.find(name="Alice").allow_filtering().all())
π‘ Async? Just swap
coodie.syncforcoodie.aioand addawaitβ thatβs it!
π How Does coodie Compare?ο
Feature |
coodie |
beanie |
cqlengine |
|---|---|---|---|
Database |
Cassandra / ScyllaDB |
MongoDB |
Cassandra |
Schema Definition |
Pydantic v2 |
Pydantic v2 |
Custom |
Type Hints |
β
Native |
β Native Pydantic |
β No type hints |
Async Support |
β First-class |
β First-class |
β Sync only |
Sync Support |
β
|
β Async only |
β Sync only |
Query API |
Chainable |
Chainable |
Chainable |
Schema Migration |
β
|
β Manual |
β
|
LWT (Compare-and-Set) |
β
|
N/A |
β
|
Batch Operations |
β
|
β |
β
|
Counter Columns |
β
|
β |
β
|
User-Defined Types |
β
|
β |
β
|
TTL Support |
β Per-save TTL |
β |
β Per-save TTL |
Pagination |
β
Token-based |
β Cursor-based |
β Manual |
Multiple Drivers |
β 3 drivers |
motor only |
cassandra-driver only |
Polymorphic Models |
β
|
β |
β |
Python Version |
3.10+ |
3.8+ |
3.6+ |