Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)48k · #5542

pydantic-models-py

Skill này làm gì

Công cụ này giúp tạo các cấu trúc dữ liệu có tổ chức để dùng trong chương trình máy tính, đặc biệt cho giao tiếp giữa các phần của hệ thống (như API). Nó dùng một mẫu gọi là “Multi-Model Pattern” để định nghĩa dữ liệu nên có dạng thế nào.

Khi nào nên dùng

  • ✓Khi định nghĩa cách dữ liệu được gửi để tạo mới một thứ.
  • ✓Khi định nghĩa cách dữ liệu được gửi để cập nhật một thứ đã có.
  • ✓Khi định nghĩa cách dữ liệu được trả về như một phản hồi.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/pydantic-models-py/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/pydantic-models-py/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Tạo một model Pydantic cho người dùng với các trường tên, email và ngày tạo, theo mẫu multi-model.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ dùng thư viện Pydantic để định nghĩa các “model”, tức bản thiết kế để tổ chức dữ liệu. Nó gợi ý dùng base model cho dữ liệu chung và các model riêng cho việc tạo mới, cập nhật và phản hồi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

  1. Create models in src/backend/app/models/
  2. Export from src/backend/app/models/__init__.py
  3. 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.
Câu hỏi thường gặp

Pydantic là gì?

Pydantic là thư viện Python giúp kiểm tra và tổ chức dữ liệu bằng chú thích kiểu (type annotations).

“Multi-Model Pattern” là gì?

Đó là cách tổ chức các model dữ liệu cho các mục đích khác nhau, như tạo mới, cập nhật hoặc phản hồi, để đảm bảo rõ ràng và nhất quán.

“camelCase Aliases” dùng để làm gì?

Chúng cho phép model nhận tên trường ở cả định dạng snake_case (như `workspace_id`) và camelCase (như `workspaceId`), giúp tích hợp linh hoạt hơn.

Chi tiết

Mô tả gốc của tác giả

Create Pydantic models following the multi-model pattern for clean API contracts.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#5542
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự