Skip to content

Pydantic: optional automatic models and a project-wide default schema base class #172

Closed

Description

@JuroOravec

Problem

Citry already accepts Pydantic v1 and v2 models as component schemas: Kwargs, Slots, State, JsData and Events data can each be a BaseModel. But a plain declaration like

class Kwargs:
    title: str
    count: int = 0

is validated by Citry's own rules, and there is no way to say "use Pydantic for every schema in this project", or to give every schema the same Pydantic settings (model_config, for example extra="forbid" or str_strip_whitespace=True) without repeating them on each class.

Proposal

  • A project-wide setting that turns plain schema declarations into Pydantic models automatically (opt-in).
  • A setting for the default base class used for schemas, so a project can supply its own BaseModel subclass with shared model_config. Consider whether this belongs on Citry(...) settings and how it applies to extensions that add their own schemas (one rule for all, not per extension).
  • Decide how a class-level choice overrides the default, and what happens when Pydantic isn't installed (error at startup, not at render).

Related: #129 (form integration from Python classes).

Activity

  1. JuroOravec commented on Oct 28, 2026

    @JuroOravec
    MemberAuthor

    Done in #455 (model_base for dataclass, Pydantic v1 and v2, and NamedTuple) and #461 (Pydantic State).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions