python-fastapi-development

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Python/FastAPI Development Workflow

Python/FastAPI 开发工作流

Overview

概述

Specialized workflow for building production-ready Python backends with FastAPI, featuring async patterns, SQLAlchemy ORM, Pydantic validation, and comprehensive API patterns.
这是用于构建生产级Python后端的专用工作流,基于FastAPI,涵盖异步模式、SQLAlchemy ORM、Pydantic验证及全面的API模式。

When to Use This Workflow

何时使用此工作流

Use this workflow when:
  • Building new REST APIs with FastAPI
  • Creating async Python backends
  • Implementing database integration with SQLAlchemy
  • Setting up API authentication
  • Developing microservices
在以下场景使用此工作流:
  • 基于FastAPI构建新的REST API
  • 创建异步Python后端
  • 实现与SQLAlchemy的数据库集成
  • 搭建API认证机制
  • 开发微服务

Workflow Phases

工作流阶段

Phase 1: Project Setup

阶段1:项目搭建

Skills to Invoke

可调用的技能

  • app-builder
    - Application scaffolding
  • python-development-python-scaffold
    - Python scaffolding
  • fastapi-templates
    - FastAPI templates
  • uv-package-manager
    - Package management
  • app-builder
    - 应用脚手架生成
  • python-development-python-scaffold
    - Python项目脚手架
  • fastapi-templates
    - FastAPI模板
  • uv-package-manager
    - 包管理

Actions

操作步骤

  1. Set up Python environment (uv/poetry)
  2. Create project structure
  3. Configure FastAPI app
  4. Set up logging
  5. Configure environment variables
  1. 搭建Python环境(uv/poetry)
  2. 创建项目结构
  3. 配置FastAPI应用
  4. 搭建日志系统
  5. 配置环境变量

Copy-Paste Prompts

可复制粘贴的提示词

Use @fastapi-templates to scaffold a new FastAPI project
Use @python-development-python-scaffold to set up Python project structure
Use @fastapi-templates to scaffold a new FastAPI project
Use @python-development-python-scaffold to set up Python project structure

Phase 2: Database Setup

阶段2:数据库搭建

Skills to Invoke

可调用的技能

  • prisma-expert
    - Prisma ORM (alternative)
  • database-design
    - Schema design
  • postgresql
    - PostgreSQL setup
  • pydantic-models-py
    - Pydantic models
  • prisma-expert
    - Prisma ORM(替代方案)
  • database-design
    - 数据库 schema 设计
  • postgresql
    - PostgreSQL 搭建
  • pydantic-models-py
    - Pydantic 模型

Actions

操作步骤

  1. Design database schema
  2. Set up SQLAlchemy models
  3. Create database connection
  4. Configure migrations (Alembic)
  5. Set up session management
  1. 设计数据库 schema
  2. 搭建SQLAlchemy模型
  3. 创建数据库连接
  4. 配置迁移工具(Alembic)
  5. 搭建会话管理

Copy-Paste Prompts

可复制粘贴的提示词

Use @database-design to design PostgreSQL schema
Use @pydantic-models-py to create Pydantic models for API
Use @database-design to design PostgreSQL schema
Use @pydantic-models-py to create Pydantic models for API

Phase 3: API Routes

阶段3:API路由

Skills to Invoke

可调用的技能

  • fastapi-router-py
    - FastAPI routers
  • api-design-principles
    - API design
  • api-patterns
    - API patterns
  • fastapi-router-py
    - FastAPI 路由
  • api-design-principles
    - API设计原则
  • api-patterns
    - API模式

Actions

操作步骤

  1. Design API endpoints
  2. Create API routers
  3. Implement CRUD operations
  4. Add request validation
  5. Configure response models
  1. 设计API端点
  2. 创建API路由
  3. 实现CRUD操作
  4. 添加请求验证
  5. 配置响应模型

Copy-Paste Prompts

可复制粘贴的提示词

Use @fastapi-router-py to create API endpoints with CRUD operations
Use @api-design-principles to design RESTful API
Use @fastapi-router-py to create API endpoints with CRUD operations
Use @api-design-principles to design RESTful API

Phase 4: Authentication

阶段4:认证机制

Skills to Invoke

可调用的技能

  • auth-implementation-patterns
    - Authentication
  • api-security-best-practices
    - API security
  • auth-implementation-patterns
    - 认证实现
  • api-security-best-practices
    - API安全最佳实践

Actions

操作步骤

  1. Choose auth strategy (JWT, OAuth2)
  2. Implement user registration
  3. Set up login endpoints
  4. Create auth middleware
  5. Add password hashing
  1. 选择认证策略(JWT、OAuth2)
  2. 实现用户注册功能
  3. 搭建登录端点
  4. 创建认证中间件
  5. 添加密码哈希处理

Copy-Paste Prompts

可复制粘贴的提示词

Use @auth-implementation-patterns to implement JWT authentication
Use @auth-implementation-patterns to implement JWT authentication

Phase 5: Error Handling

阶段5:错误处理

Skills to Invoke

可调用的技能

  • fastapi-pro
    - FastAPI patterns
  • error-handling-patterns
    - Error handling
  • fastapi-pro
    - FastAPI进阶模式
  • error-handling-patterns
    - 错误处理模式

Actions

操作步骤

  1. Create custom exceptions
  2. Set up exception handlers
  3. Implement error responses
  4. Add request logging
  5. Configure error tracking
  1. 创建自定义异常
  2. 搭建异常处理器
  3. 实现错误响应
  4. 添加请求日志
  5. 配置错误追踪

Copy-Paste Prompts

可复制粘贴的提示词

Use @fastapi-pro to implement comprehensive error handling
Use @fastapi-pro to implement comprehensive error handling

Phase 6: Testing

阶段6:测试

Skills to Invoke

可调用的技能

  • python-testing-patterns
    - pytest testing
  • api-testing-observability-api-mock
    - API testing
  • python-testing-patterns
    - pytest测试
  • api-testing-observability-api-mock
    - API测试

Actions

操作步骤

  1. Set up pytest
  2. Create test fixtures
  3. Write unit tests
  4. Implement integration tests
  5. Configure test database
  1. 搭建pytest环境
  2. 创建测试夹具
  3. 编写单元测试
  4. 实现集成测试
  5. 配置测试数据库

Copy-Paste Prompts

可复制粘贴的提示词

Use @python-testing-patterns to write pytest tests for FastAPI
Use @python-testing-patterns to write pytest tests for FastAPI

Phase 7: Documentation

阶段7:文档

Skills to Invoke

可调用的技能

  • api-documenter
    - API documentation
  • openapi-spec-generation
    - OpenAPI specs
  • api-documenter
    - API文档生成
  • openapi-spec-generation
    - OpenAPI规范生成

Actions

操作步骤

  1. Configure OpenAPI schema
  2. Add endpoint documentation
  3. Create usage examples
  4. Set up API versioning
  5. Generate API docs
  1. 配置OpenAPI schema
  2. 添加端点文档
  3. 创建使用示例
  4. 搭建API版本控制
  5. 生成API文档

Copy-Paste Prompts

可复制粘贴的提示词

Use @api-documenter to generate comprehensive API documentation
Use @api-documenter to generate comprehensive API documentation

Phase 8: Deployment

阶段8:部署

Skills to Invoke

可调用的技能

  • deployment-engineer
    - Deployment
  • docker-expert
    - Containerization
  • deployment-engineer
    - 部署实施
  • docker-expert
    - 容器化

Actions

操作步骤

  1. Create Dockerfile
  2. Set up docker-compose
  3. Configure production settings
  4. Set up reverse proxy
  5. Deploy to cloud
  1. 创建Dockerfile
  2. 搭建docker-compose环境
  3. 配置生产环境设置
  4. 搭建反向代理
  5. 部署至云端

Copy-Paste Prompts

可复制粘贴的提示词

Use @docker-expert to containerize FastAPI application
Use @docker-expert to containerize FastAPI application

Technology Stack

技术栈

CategoryTechnology
FrameworkFastAPI
LanguagePython 3.11+
ORMSQLAlchemy 2.0
ValidationPydantic v2
DatabasePostgreSQL
MigrationsAlembic
AuthJWT, OAuth2
Testingpytest
分类技术
框架FastAPI
语言Python 3.11+
ORMSQLAlchemy 2.0
验证Pydantic v2
数据库PostgreSQL
迁移工具Alembic
认证JWT, OAuth2
测试pytest

Quality Gates

质量门禁

  • All tests passing (>80% coverage)
  • Type checking passes (mypy)
  • Linting clean (ruff, black)
  • API documentation complete
  • Security scan passed
  • Performance benchmarks met
  • 所有测试通过(覆盖率>80%)
  • 类型检查通过(mypy)
  • 代码检查无问题(ruff, black)
  • API文档完整
  • 安全扫描通过
  • 性能基准达标

Related Workflow Bundles

相关工作流包

  • development
    - General development
  • database
    - Database operations
  • security-audit
    - Security testing
  • api-development
    - API patterns
  • development
    - 通用开发
  • database
    - 数据库操作
  • security-audit
    - 安全测试
  • api-development
    - API模式