Skip to main content

coodie = cassandra+beanie(hoodie)

Project description

coodie logo

coodie

The modern Pydantic-based ODM for Cassandra & ScyllaDB

Cassandra + Beanie (hoodie) = coodie ๐Ÿงฅ

CI Status Docs Coverage PyPI Downloads Python License

๐Ÿ“– Documentation โ€ข ๐Ÿš€ Quick Start โ€ข ๐Ÿค Contributing โ€ข ๐Ÿ“‹ Changelog


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
โšก Sync & Async โ€” coodie.sync for blocking, coodie.aio for asyncio
๐Ÿ”— Chainable QuerySet โ€” .filter() ยท .limit() ยท .order_by()

๐Ÿ”„ Automatic Schema Sync โ€” sync_table() creates & evolves tables
๐Ÿ—๏ธ Batch & LWT โ€” BatchQuery + if_not_exists() support
๐ŸŽฏ Multi-Driver โ€” scylla-driver ยท cassandra-driver ยท acsylla

๐Ÿ” How Does coodie Compare?

Feature coodie beanie cqlengine
Database Cassandra / ScyllaDB MongoDB Cassandra
Schema Definition Pydantic v2 BaseModel Pydantic v2 BaseModel Custom columns.* classes
Type Hints โœ… Native Annotated[] โœ… Native Pydantic โŒ No type hints
Async Support โœ… First-class โœ… First-class โŒ Sync only
Sync Support โœ… coodie.sync โŒ Async only โœ… Sync only
Query API Chainable QuerySet Chainable FindMany Chainable QuerySet
Schema Migration โœ… sync_table() โŒ Manual โœ… sync_table()
LWT (Compare-and-Set) โœ… if_not_exists() N/A โœ… iff()
Batch Operations โœ… BatchQuery โŒ โœ… BatchQuery
Counter Columns โœ… Counter() โŒ โœ… columns.Counter
User-Defined Types โœ… UserType โŒ โœ… UserType
TTL Support โœ… Per-save TTL โŒ โœ… Per-save TTL
Pagination โœ… Token-based PagedResult โœ… Cursor-based โŒ Manual
Multiple Drivers โœ… 3 drivers motor only cassandra-driver only
Polymorphic Models โœ… Discriminator โŒ โŒ
Python Version 3.10+ 3.8+ 3.6+

๐Ÿ“ฆ 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="alice@example.com")
user.save()

# Query
print(User.find(name="Alice").allow_filtering().all())

๐Ÿ’ก Async? Just swap coodie.sync for coodie.aio and add await โ€” that's it!

๐Ÿ“– Usage

Define a Document
from typing import Annotated
from uuid import UUID, uuid4
from pydantic import Field
from coodie import Document, PrimaryKey, ClusteringKey, Indexed

class Product(Document):
    id: Annotated[UUID, PrimaryKey()] = Field(default_factory=uuid4)
    category: Annotated[str, ClusteringKey()] = "general"
    name: str
    brand: Annotated[str, Indexed()] = "Unknown"
    price: float = 0.0

    class Settings:
        name = "products"      # table name (defaults to snake_case class name)
        keyspace = "my_ks"
Async API โ€” coodie / coodie.aio
import asyncio
from coodie import init_coodie
# Product defined above โ€” same field definitions, using coodie.aio.Document

async def main():
    await init_coodie(hosts=["127.0.0.1"], keyspace="my_ks")
    await Product.sync_table()

    p = Product(name="Gadget", brand="Acme", price=9.99)
    await p.save()

    results = await Product.find(brand="Acme").limit(10).all()
    for product in results:
        print(product.name, product.price)

    gadget = await Product.get(id=p.id)
    await gadget.delete()

asyncio.run(main())
Sync API โ€” coodie.sync
from coodie.sync import Document, init_coodie

class Product(Document):
    ...  # same field definitions

init_coodie(hosts=["127.0.0.1"], keyspace="my_ks")
Product.sync_table()

p = Product(name="Widget", price=4.99)
p.save()

results = Product.find(brand="Acme").allow_filtering().all()
one = Product.find_one(name="Widget")
QuerySet Chaining
# Filter, sort, and limit
products = (
    await Product.find()
    .filter(brand="Acme")
    .order_by("price")
    .limit(20)
    .all()
)

# Count
n = await Product.find(brand="Acme").allow_filtering().count()

# Async iteration
async for p in Product.find(brand="Acme"):
    print(p)

# Delete matching rows
await Product.find(brand="Discontinued").allow_filtering().delete()
Field Annotations Reference
Annotation Purpose
PrimaryKey(partition_key_index=0) Partition key column (composite keys via index)
ClusteringKey(order="ASC", clustering_key_index=0) Clustering column
Indexed(index_name=None) Secondary index
Counter() Counter column
Discriminator() Polymorphic model discriminator

๐Ÿ“š Learn More

Resource Link
๐Ÿ“– Full Documentation scylladb.github.io/coodie
๐Ÿš€ Quick Start Guide Installation & Quickstart
๐Ÿ“Š Benchmark History Performance Trends
๐Ÿ”„ Migrating from cqlengine Migration Guide
๐Ÿค Contributing CONTRIBUTING.md
๐Ÿ“‹ Changelog CHANGELOG.md
๐Ÿ› Bug Reports GitHub Issues

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Israel Fruchter

๐Ÿ’ป ๐Ÿค” ๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

This package was created with Cookiecutter and the browniebroke/cookiecutter-pypackage project template.

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

coodie-1.2.0.tar.gz (3.7 MB view details)

Uploaded Source

Built Distribution

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

coodie-1.2.0-py3-none-any.whl (76.5 kB view details)

Uploaded Python 3

File details

Details for the file coodie-1.2.0.tar.gz.

File metadata

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

File hashes

Hashes for coodie-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8fee0fa177973b10bd89ea413dae3e805186b5f0100605cf83c88720e3653d9a
MD5 729430ee63e4d9d53f2762f5f2727076
BLAKE2b-256 63f3166bc30c8660c466e6d1d9f2b977890ea3d7b38a54389654c5300c0fb93b

See more details on using hashes here.

Provenance

The following attestation bundles were made for coodie-1.2.0.tar.gz:

Publisher: ci.yml on scylladb/coodie

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

File details

Details for the file coodie-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: coodie-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 76.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coodie-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed48e50d6b2a9806642af08c60b92a0c1ee2cc411ce1e8a8c48e09f10d3cbe0c
MD5 c63d468551c8f6540e59a83c25bc03c9
BLAKE2b-256 52c2b4801e4db92727809365c2308c1a3686155113632218bcd67a9fe7d30a3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for coodie-1.2.0-py3-none-any.whl:

Publisher: ci.yml on scylladb/coodie

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