Skip to main content

A command-line tool for generating FastAPI projects with different architectural patterns

Project description

FastAPI CLI Generator

🚀 快速创建不同架构模式的FastAPI项目的命令行工具

中文文档 | English Documentation

功能特性

  • 🏗️ 两种架构模式: 功能分层架构 vs 模块化架构
  • 🎯 交互式CLI: 友好的中文交互界面
  • 📁 完整项目结构: 基于最佳实践的项目模板
  • 即开即用: 生成的项目可以直接运行

安装

pip install fastapi-cli-generator

快速开始

交互式模式(推荐)

fastapi-create

命令行模式

# 指定模板创建
fastapi-create create my-project --template module
fastapi-create create my-project --template function

# 查看可用模板
fastapi-create list-templates

架构模式

1. 模块化架构 (module) - 推荐

按业务领域组织代码,每个模块包含完整的MVC结构:

my-project/
├── src/
│   ├── core/                 # 核心配置
│   ├── modules/              # 业务模块
│   │   ├── auth/             # 认证模块
│   │   ├── users/            # 用户管理
│   │   └── items/            # 项目管理
│   └── shared/               # 共享工具
├── tests/                    # 测试文件
└── requirements.txt

适用场景:

  • 中大型项目
  • 团队协作开发
  • 需要清晰业务边界的项目

2. 功能分层架构 (function)

按技术层次组织代码:

my-project/
├── src/
│   ├── api/v1/endpoints/     # API端点
│   ├── core/                 # 核心配置
│   ├── db/repositories/      # 数据库操作
│   ├── models/               # 数据模型
│   ├── services/             # 业务逻辑
│   └── utils/                # 工具函数
├── tests/                    # 测试文件
└── requirements.txt

适用场景:

  • 小型项目
  • 学习和原型开发
  • 简单的API服务

使用示例

创建项目

# 交互式创建(推荐)
fastapi-create

# 快速创建模块化项目
fastapi-create create my-api --template module

# 快速创建功能分层项目
fastapi-create create my-api --template function

运行项目

cd my-api
pip install -r requirements.txt
uvicorn src.main:app --reload

访问 http://localhost:8000/docs 查看API文档

开发

# 克隆项目
git clone https://github.com/xukache/fastapi-cli-generator.git
cd fastapi-cli-generator

# 安装开发依赖
pip install -e .

# 测试工具
fastapi-create --help

许可证

MIT License

贡献

欢迎提交Issue和Pull Request!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_cli_generator-0.4.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_cli_generator-0.4.0-py3-none-any.whl (46.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_cli_generator-0.4.0.tar.gz.

File metadata

  • Download URL: fastapi_cli_generator-0.4.0.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for fastapi_cli_generator-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a10e40a7acc011e276f1b4d225a1f49638dee7ba54e84a2690f7e05ee93ed443
MD5 a4dea0d96c5d5a429b7f457a69d3a2ac
BLAKE2b-256 34163fa290e4bac4390095e04b60fd82d3f7b83fc477a60b22db0155e9310b0e

See more details on using hashes here.

File details

Details for the file fastapi_cli_generator-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_cli_generator-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a0ab87c95139a3821f0aa5de1e6888ef0a02756f21ff1025d06fcb2f3d16203
MD5 c971d37120763ed321e7c04cdc658e0b
BLAKE2b-256 dee5c6d2b17adeb81f1375e9cdd2b8d435aface43e66a7bd483bfdf522de1ad7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page