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.mdSao 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
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
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
deffor pure functions,async deffor 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 defhandlers, 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
- Rely on FastAPI's dependency injection system
- Prioritize API performance metrics (response time, latency, throughput)
- 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
Bình luận
- …
Thêm skill từ kho mã này
vite
99kCho agent của bạn hướng dẫn chuyên sâu về Vite, công cụ build nhanh cho ứng dụng web, gồm thiết lập, biến môi trường và hiệu năng.
voicestudio
99kCho agent của bạn tạo giọng nói bằng giọng đã lưu, phiên âm âm thanh và chạy bước lồng tiếng qua ứng dụng VoiceStudio cục bộ.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.