pydantic-models-py
microsoft/skills
Pydantic v2 を使用した Python アプリケーションにおいて、クリーンな API 契約を実現するために、Base、Create、Update、Response、InDB の各バリアントを含むマルチモデルパターンに従って Pydantic モデルを作成します。
...すべて拡張しますPydanticモデル
クリーンなAPI契約のために、マルチモデルパターンに従ってPydanticモデルを作成します。
クイックスタート
assets/template.pyからテンプレートをコピーし、プレースホルダーを置き換えます:
{{ResourceName}}→ PascalCase名(例:Project){{resource_name}}→ snake_case名(例:project)
マルチモデルパターン
| モデル | 目的 |
|---|---|
| `Base` | モデル間で共有される共通フィールド |
| `Create` | 作成時のリクエストボディ(必須フィールド) |
| `Update` | 更新時のリクエストボディ(すべてオプション) |
| `Response` | 全フィールドを含むAPIレスポンス |
| `InDB` | `doc_type`を含むデータベースドキュメント |
camelCaseエイリアス
class MyModel(BaseModel):
workspace_id: str = Field(..., alias="workspaceId")
created_at: datetime = Field(..., alias="createdAt")
class Config:
populate_by_name = True # snake_caseとcamelCaseの両方を受け入れる
オプションの更新フィールド
class MyUpdate(BaseModel):
"""PATCHリクエストのためにすべてのフィールドがオプションです。"""
name: Optional[str] = Field(None, min_length=1)
description: Optional[str] = None
データベースドキュメント
class MyInDB(MyResponse):
"""Cosmos DBクエリのdoc_typeを追加します。"""
doc_type: str = "my_resource"
統合手順
src/backend/app/models/にモデルを作成するsrc/backend/app/models/__init__.pyからエクスポートする- 対応するTypeScript型を追加する
---
name: pydantic-models-py
description: Create Pydantic models following the multi-model pattern with Base, Create, Update, Response, and InDB variants for clean API contracts in Python applications using Pydantic v2.
license: MIT
---
# Pydantic Models
Create Pydantic models following the multi-model pattern for clean API contracts.
## Quick Start
Copy the template from [assets/template.py](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
```python
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
```python
class MyUpdate(BaseModel):
"""All fields optional for PATCH requests."""
name: Optional[str] = Field(None, min_length=1)
description: Optional[str] = None
```
## Database Document
```python
class MyInDB(MyResponse):
"""Adds doc_type for Cosmos DB queries."""
doc_type: str = "my_resource"
```
## Integration Steps
1. Create models in `src/backend/app/models/`
2. Export from `src/backend/app/models/__init__.py`
3. Add corresponding TypeScript types
すべてのファイル
0件のファイルpydantic-models-pyをインストール
スキルファイルをダウンロードして、.claude/skills/ ディレクトリに展開してください。
ZIPをダウンロードリポジトリをクローンし、スキルファイルをプロジェクトにコピーしてください。
git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-python/skills/pydantic-models-py # Copy SKILL.md to your .claude/skills/ directory
コピー





家
