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.2.tar.gz (31.9 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.2-py3-none-any.whl (43.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_cli_generator-0.4.2.tar.gz
  • Upload date:
  • Size: 31.9 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.2.tar.gz
Algorithm Hash digest
SHA256 cc34b0303fe3a2be04c8c7c53c274cd2e083b178198224bca0ded95f6ecb72f7
MD5 8babdd14778b3f7740dfbabbc0e54c42
BLAKE2b-256 fafa7bcfd6b0f7652d2df95c8c35cf2c5368c5f60817261af6c8519e8951bd7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_cli_generator-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 711d790499fd37c3e051f4fea0a2e4e1d22b5aea58df53fe6836afa725c650f9
MD5 b68aa5370b78db538608db1de9d31adc
BLAKE2b-256 f8fc7101d742bb12b606d88370af0bee90d3e84778ee5fa85d7dab87d06e81ac

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