pydantic-models-py
它能做什么
这个工具可以帮你创建有组织的数据结构,用于计算机程序中,特别是系统不同部分之间的通信(比如 API)。它采用一种称为“多模型模式”(Multi-Model Pattern)的方法来定义数据的形态。
适用场景
- ✓当你需要定义创建某项内容时发送的数据格式时。
- ✓当你需要定义更新已有内容时发送的数据格式时。
- ✓当你需要定义以响应形式返回的数据格式时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/pydantic-models-py/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请按照多模型模式,为用户创建一个 Pydantic 模型,包含 name、email 和创建日期(creation date)字段。”
每周 5 个新技能,1 分钟读完。
工作原理
这个工具借助 Pydantic 库定义“模型”,你可以把它们理解为组织数据的蓝图。对于通用数据,它建议使用基础模型;对于创建、更新和响应等场景,则分别使用对应的专用模型。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Pydantic Models
Create Pydantic models following the multi-model pattern for clean API contracts.
Quick Start
Use the inline model patterns below and adapt class names and fields to the actual API contract. Inspect the installed Pydantic version before selecting configuration syntax; these fragments require the imports and application types shown by your project. Do not assume a standalone template file is bundled.
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
When to Use
This skill is applicable to execute the workflow or actions described in the overview.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题
什么是 Pydantic?
Pydantic 是一个 Python 库,它利用类型注解来帮助你校验和组织数据。
什么是“多模型模式”?
这是一种按用途组织数据模型的方法,比如分别用于创建、更新或响应,从而让代码更清晰、更一致。
“camelCase 别名”有什么用?
它让你的模型既能接收 snake_case 格式(如 `workspace_id`)的字段名,也能接收 camelCase 格式(如 `workspaceId`)的字段名,使系统集成更加灵活。
详情
作者的原始描述
Create Pydantic models following the multi-model pattern for clean API contracts.
热度
- GitHub 星标
- 48k
- 排名
- #5542
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。