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 -i https://pypi.org/simple

快速开始

交互式模式(推荐)

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.1.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.1-py3-none-any.whl (46.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_cli_generator-0.4.1.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.1.tar.gz
Algorithm Hash digest
SHA256 fea831a3c6b3ed38b55eea62ff89d3af77411cfb57c1f495ad3e3a1ead2cb008
MD5 021c4d83b2591976573cd976aab07725
BLAKE2b-256 603a037386b5bbcb3432c2f45a64bb90b9506fd08e7f883d79885e9187cd921a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_cli_generator-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a10226ebe0ae3506c5028939899bb16a8d4e0f849e108aa7090d94600d0c10c3
MD5 e80fb173b541817cbbb75bd09d7dfaaf
BLAKE2b-256 c5a488e1f632f1168a74d1cd3f976b447a4317278cfb81f6a95a9f452470a845

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