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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_cli_generator-0.4.3.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.3.tar.gz
Algorithm Hash digest
SHA256 d90905db7b0ddf35a14380055c7712c6e84dd09fbd5dcefabf0eb37249197534
MD5 c024693edef574daf06af46299a34134
BLAKE2b-256 e21b1e7a73e83474588c14e87be77d001ae9cdf338435eeeb91d1c56ac526510

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_cli_generator-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c35aa2c8c1a539011610a785754eb9f9a0ddef8686d7a6b2e894175a50ecb75c
MD5 d74b9479bda52ea5c964fb482f0fb8cf
BLAKE2b-256 d076bc60384ad03297a486972a4d6054a62b171d102054c0a83c86bbce5e17be

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