A command-line tool for generating FastAPI projects with different architectural patterns
Project description
FastAPI CLI Generator
🚀 A command-line tool for quickly creating FastAPI projects with different architectural patterns.
Features
- 🏗️ Two Architecture Patterns: Functional layered vs Modular architecture
- 🎯 Interactive CLI: User-friendly interface with Chinese support
- 📁 Complete Project Structure: Templates based on best practices
- ⚡ Ready to Use: Generated projects can run immediately
- 🔧 Modern Configuration: Pydantic Settings with type safety and multi-environment support
- 🐳 Docker Ready: Includes Dockerfile and deployment configurations
- 📝 Environment Management: Support for .env and .env.prod with proper priority
Installation
pip install fastapi-cli-generator -i https://pypi.org/simple
Quick Start
Interactive Mode (Recommended)
fastapi-create
Command Line Mode
# Create with specific template
fastapi-create create my-project --template module
fastapi-create create my-project --template function
# List available templates
fastapi-create list-templates
Usage
Basic Usage
# Create project (interactive mode)
fastapi-create my-project
# Specify template type
fastapi-create my-project --template module
fastapi-create my-project --template function
List Available Templates
fastapi-create list-templates
Architecture Patterns
1. Modular Architecture (module) - Recommended
Organize code by business domains, each module contains complete MVC structure:
my-project/
├── src/
│ ├── core/ # 核心配置
│ │ ├── config.py # Pydantic Settings配置
│ │ ├── dependencies.py # 共享依赖项
│ │ └── security.py # 认证和安全
│ ├── modules/ # 业务模块
│ │ ├── auth/ # 认证模块
│ │ ├── users/ # 用户管理
│ │ └── items/ # 项目管理
│ └── shared/ # 共享工具
│ ├── database.py # 数据库连接
│ └── utils.py # 共享工具函数
├── tests/ # 测试文件
├── .env # 开发环境配置
├── .env.prod # 生产环境配置
├── Dockerfile # Docker部署配置
└── requirements.txt
2. Functional Layered Architecture (function)
Organize code by technical layers:
my-project/
├── src/
│ ├── api/v1/endpoints/ # API端点
│ ├── core/ # 核心配置
│ │ └── config.py # Pydantic Settings配置
│ ├── db/repositories/ # 数据库操作
│ ├── models/ # 数据模型
│ ├── services/ # 业务逻辑
│ └── utils/ # 工具函数
├── tests/ # 测试文件
├── .env # 开发环境配置
├── .env.prod # 生产环境配置
├── Dockerfile # Docker部署配置
└── requirements.txt
Configuration Management
Generated projects use Pydantic Settings for type-safe configuration management:
Environment Files Priority
.env- Development environment (default).env.prod- Production environment (higher priority)
Configuration Features
- Type Safety: All settings are properly typed (bool, str, int, etc.)
- Default Values: Sensible defaults for quick start
- Environment Override: Production settings override development ones
- Validation: Automatic validation of configuration values
Example Configuration
# src/core/config.py
class Settings(BaseSettings):
DEBUG_MODE: bool = True
STATIC_DIR: str = "static"
STATIC_URL: str = "/static"
STATIC_NAME: str = "static"
class Config:
env_file = (".env", ".env.prod") # Multiple env files, latter takes priority
Running Generated Projects
# Navigate to your project
cd my-project
# Install dependencies
pip install -r requirements.txt
# Run development server
uvicorn src.main:app --reload
# Or run with custom host/port
uvicorn src.main:app --host 0.0.0.0 --port 8080 --reload
Docker Deployment
# Build image
docker build -t my-project .
# Run container
docker run -d --name my-project -p 8080:20201 my-project
Development
# Clone repository
git clone https://github.com/xukache/fastapi-cli-generator.git
cd fastapi-cli-generator
# Install in development mode
pip install -e .
# Test the CLI
fastapi-create --help
# Run tests
python test_generation.py
License
MIT License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_cli_generator-0.3.0.tar.gz.
File metadata
- Download URL: fastapi_cli_generator-0.3.0.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
378b50f1e84521d8e4be9338910f0f04c8e44e2565f3f33d333f33962c6154f5
|
|
| MD5 |
fa6389d970857645b029137a51cbf9a6
|
|
| BLAKE2b-256 |
e0850d8c723b093b7d37465e0d3e2ab3ec272afa4bcf4c35a21c379482c0691f
|
File details
Details for the file fastapi_cli_generator-0.3.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_cli_generator-0.3.0-py3-none-any.whl
- Upload date:
- Size: 37.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84c95d545112a0d82aae01515e60b2167089d83ad3871f24e9ddf45dba771c90
|
|
| MD5 |
55bf4dabd48294f7265cc4a52b39e648
|
|
| BLAKE2b-256 |
c1c27e4bed1fdb550728297c0b304fe72963083ee91508e75e6161c5c295f336
|