File contents Pydantic Models
Create Pydantic models following the multi-model pattern for clean API contracts.
Quick Start
Copy the template from assets/template.py and replace placeholders:
{{ResourceName}} → PascalCase name (e.g., Project)
{{resource_name}} → snake_case name (e.g., project)
Multi-Model Pattern
Model
Purpose
Base
Common fields shared across models
Create
Request body for creation (required fields)
Update
Request body for updates (all optional)
Response
API response with all fields
InDB
Database document with doc_type
camelCase Aliases
class MyModel(BaseModel):
workspace_id: str = Field(..., alias="workspaceId")
created_at: datetime = Field(..., alias="createdAt")
class Config:
populate_by_name = True # Accept both snake_case and camelCase
Optional Update Fields
class MyUpdate(BaseModel):
"""All fields optional for PATCH requests."""
name: Optional[str] = Field(None, min_length=1)
description: Optional[str] = None
Database Document
class MyInDB(MyResponse):
"""Adds doc_type for Cosmos DB queries."""
doc_type: str = "my_resource"
Integration Steps
Create models in src/backend/app/models/
Export from src/backend/app/models/__init__.py
Add corresponding TypeScript types
1 --- 2 name: pydantic-models-py 3 description: Pydantic Models 4 --- 5 # Pydantic Models 6 7 Create Pydantic models following the multi-model pattern for clean API contracts. 8 9 ## Quick Start 10 11 Copy the template from [assets/template.py](assets/template.py) and replace placeholders: 12 - `{{ResourceName}}` → PascalCase name (e.g., `Project`) 13 - `{{resource_name}}` → snake_case name (e.g., `project`) 14 15 ## Multi-Model Pattern 16 17 | Model | Purpose | 18 |-------|---------| 19 | `Base` | Common fields shared across models | 20 | `Create` | Request body for creation (required fields) | 21 | `Update` | Request body for updates (all optional) | 22 | `Response` | API response with all fields | 23 | `InDB` | Database document with `doc_type` | 24 25 ## camelCase Aliases 26 27 ```python 28 class MyModel(BaseModel): 29 workspace_id: str = Field(..., alias="workspaceId") 30 created_at: datetime = Field(..., alias="createdAt") 31 32 class Config: 33 populate_by_name = True # Accept both snake_case and camelCase 34 ``` 35 36 ## Optional Update Fields 37 38 ```python 39 class MyUpdate(BaseModel): 40 """All fields optional for PATCH requests.""" 41 name: Optional[str] = Field(None, min_length=1) 42 description: Optional[str] = None 43 ``` 44 45 ## Database Document 46 47 ```python 48 class MyInDB(MyResponse): 49 """Adds doc_type for Cosmos DB queries.""" 50 doc_type: str = "my_resource" 51 ``` 52 53 ## Integration Steps 54 55 1. Create models in `src/backend/app/models/` 56 2. Export from `src/backend/app/models/__init__.py` 57 3. Add corresponding TypeScript types
ComeOnOliver/skillshub/tree/main/skills/microsoft/skills/pydantic-models-py commit eea53b26ee
Frequently asked questions How do I install the Pydantic Models Py skill? Run npx skillmds@latest add comeonoliver/pydantic-models-py in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Pydantic Models Py skill do? Pydantic Models It is listed under Coding & Dev Tools on SkillMD.
Is Pydantic Models Py safe to use? This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Pydantic Models Py? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Pydantic Models Py free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Pydantic Models Py? ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.