Data Schemas (DTOs)
ZodiacCore provides a set of base Pydantic models and types to standardize Data Transfer Objects (DTOs). These mirror our database models to ensure end-to-end consistency.
1. Core Models
CoreModel
The CoreModel is the recommended base class for all your Pydantic models. It comes pre-configured with:
- from_attributes=True: Allows easy conversion from ORM objects (like SQLModel or SQLAlchemy) using Model.model_validate(orm_obj).
2. Standard Schema Mixins
We provide several mixins to match the IntIDModel and UUIDModel found in the database layer.
| Schema | Primary Key | Timestamps |
|---|---|---|
IntIDSchema |
id: int |
created_at, updated_at |
UUIDSchema |
id: UUID |
created_at, updated_at |
Example Usage
3. UTC Datetime Utility
Handling timezones correctly is notoriously difficult. ZodiacCore includes a UtcDatetime type that automatically converts incoming datetime objects to UTC and ensures they are timezone-aware.
from zodiac_core import UtcDatetime
from pydantic import BaseModel
class Event(BaseModel):
# Any incoming datetime will be converted to aware-UTC
happened_at: UtcDatetime
4. API Reference
Base Schemas
UtcDatetime = Annotated[datetime, BeforeValidator(ensure_utc)]
module-attribute
CoreModel
Bases: BaseModel
Base Pydantic model for all Zodiac schemas (DTOs).
Features: - Standard snake_case fields - From attributes enabled (ORM mode)
Source code in zodiac_core/schemas.py
IntIDSchema
Bases: CoreModel, IntIDSchemaMixin, DateTimeSchemaMixin
Base schema for models with an Integer ID and Timestamps. Includes: Core Config + ID + CreatedAt + UpdatedAt.
Source code in zodiac_core/schemas.py
UUIDSchema
Bases: CoreModel, UUIDSchemaMixin, DateTimeSchemaMixin
Base schema for models with a UUID and Timestamps. Includes: Core Config + ID + CreatedAt + UpdatedAt.
Source code in zodiac_core/schemas.py
IntIDSchemaMixin
UUIDSchemaMixin
DateTimeSchemaMixin
Bases: BaseModel
Mixin for models that include standard timestamps.