UserType
User-Defined Type (UDT) base class and utilities.
User-Defined Type (UDT) support for coodie.
Provides a UserType(BaseModel) base class for declaring Cassandra/ScyllaDB
UDTs using standard Pydantic type annotations.
Example:
from coodie.usertype import UserType
class Address(UserType):
street: str
city: str
zipcode: int
class Settings:
__type_name__ = "address" # optional — defaults to snake_case
keyspace = "my_ks"
- class coodie.usertype.UserType
Bases:
BaseModelBase class for Cassandra/ScyllaDB User-Defined Types.
Subclass this with standard Pydantic field annotations to define a UDT:
class Address(UserType): street: str city: str zipcode: int
- classmethod type_name() str
Return the CQL type name for this UDT.
Uses
Settings.__type_name__if set, otherwise converts the class name to snake_case.
- classmethod sync_type(keyspace: str | None = None) list[str]
Synchronously create or update this UDT in the database.
Recursively syncs any nested UDT dependencies first.
- Returns:
List of CQL statements that were executed.
- async classmethod sync_type_async(keyspace: str | None = None) list[str]
Asynchronously create or update this UDT in the database.
Recursively syncs any nested UDT dependencies first.
- Returns:
List of CQL statements that were executed.
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- coodie.usertype.extract_udt_classes(doc_cls: type) list[type[UserType]]
Return all
UserTypesubclasses used by a Document, topologically sorted.Scans the Document’s type hints for UDT references (direct fields, inside collections, nested UDTs) and returns them in dependency order suitable for sequential
sync_type()calls.