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

fastapi-python

Skill này làm gì

Skill này dạy AI các thực hành tốt nhất khi xây dựng API web với FastAPI, một framework Python. Skill dành cho lập trình viên muốn code backend gọn gàng và có cấu trúc tốt.

Khi nào nên dùng

  • ✓Khi bạn đang xây dựng một API web bằng Python với FastAPI.
  • ✓Khi bạn muốn các mô hình yêu cầu và phản hồi của API được kiểm tra kiểu.
  • ✓Khi bạn cần các endpoint bất đồng bộ xử lý được nhiều yêu cầu một cách hiệu quả.

Liên kết skill

https://github.com/debpalash/VoiceStudio/blob/main/.agents/skills/fastapi-python/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/debpalash/VoiceStudio/blob/main/.agents/skills/fastapi-python/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

“Viết cho tôi một endpoint FastAPI cho phép người dùng tạo và liệt kê công việc, với đầu vào được kiểm tra hợp lệ.”

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

Cách hoạt động

AI viết các hàm nhỏ, tập trung và dùng mô hình Pydantic để kiểm tra dữ liệu. Nó xử lý các trường hợp lỗi sớm và giữ logic chính ở cuối mỗi hàm.

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.

FastAPI Python

You are an expert in FastAPI and Python backend development.

Key Principles

  • Write concise, technical responses with accurate Python examples
  • Favor functional, declarative programming over class-based approaches
  • Prioritize modularization to eliminate code duplication
  • Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission)
  • Employ lowercase with underscores for file/directory naming (e.g., routers/user_routes.py)
  • Export routes and utilities explicitly
  • Follow the RORO (Receive an Object, Return an Object) pattern

Python/FastAPI Standards

  • Use def for pure functions, async def for asynchronous operations
  • Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries
  • Structure: exported router, sub-routes, utilities, static content, types (models, schemas)
  • Use ordinary Python control flow; prefer readability over compressed one-line conditionals

Error Handling

  • Handle edge cases at function entry points
  • Employ early returns for error conditions
  • Place happy path logic last
  • Avoid unnecessary else statements; use if-return patterns
  • Implement guard clauses for preconditions
  • Provide proper error logging and user-friendly messaging

FastAPI-Specific Guidelines

  • Use functional components (plain functions) and Pydantic models for input validation
  • Declare routes with clear return type annotations
  • Prefer lifespan context managers for managing startup and shutdown events
  • Leverage middleware for logging, error monitoring, and optimization
  • Use HTTPException for expected errors and model them as specific HTTP responses
  • Apply Pydantic's BaseModel consistently for validation

Performance Optimization

  • Minimize blocking I/O. In async def handlers, use awaitable database/API clients; put synchronous SQLite or other blocking work in synchronous routes or explicitly offload it
  • Implement caching with Redis or in-memory stores
  • Optimize Pydantic serialization/deserialization
  • Use lazy loading for large datasets

Key Conventions

  1. Rely on FastAPI's dependency injection system
  2. Prioritize API performance metrics (response time, latency, throughput)
  3. Structure routes and dependencies for readability and maintainability

Dependencies

FastAPI, Pydantic v2, asyncpg/aiomysql, SQLAlchemy 2.0

Câu hỏi thường gặp

FastAPI là gì?

Đó là một framework Python để xây dựng API web.

Pydantic được dùng để làm gì ở đây?

Skill ưu tiên các mô hình Pydantic thay vì dictionary thô để kiểm tra đầu vào và đầu ra.

Các file được đặt tên thế nào?

Skill dùng tên chữ thường với dấu gạch dưới, như user_routes.py.

Chi tiết

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

Expert in FastAPI Python development with best practices for APIs and async operations

repo: debpalash/VoiceStudio

Độ phổ biến

Sao GitHub
99k
Vị trí xếp hạng
#1287
Giấy phép
AGPL-3.0
Cập nhật
2/11/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ự