Skip to main content

fastapp-cli

FastAPI 项目脚手架:一条命令生成完整、可直接运行的 FastAPI 工程。

fastapp create my-server

特性

  • 分层架构:api / schemas / crud / services / models 分层,内置泛型 CRUD / Service 基类
  • 开箱即用的工程能力:统一响应 / 异常体系、TraceID 中间件、loguru 日志、pydantic-settings 多环境配置
  • 分页 CRUD + 过滤:基于 fastapi-pagination 与 fastapi-filter 的完整示例(/api/v1/items)
  • Celery 骨架:默认 redis broker,本地无 redis 时启动自动降级 memory:// 并告警
  • Alembic 迁移:接入 SQLModel.metadata,含 autogenerate 过滤钩子
  • 优雅降级:MySQL 缺席不阻塞启动,/api/v1/health 返回 database: up/down
  • 工程化配套:Makefile、scripts/、pre-commit、ruff + mypy + pytest 配置全套
  • 可选部署文件:--pm2 / --docker 按需生成

安装

# uv tool(推荐)
uv tool install fastapp-cli

# 或 pipx
pipx install fastapp-cli

# 或一次性使用
uvx fastapp create demo

使用

fastapp create <project_name> [options]
参数 默认 说明
project_name 必填 项目名;小写字母/数字/连字符,如 my-server
--description 交互提问 项目描述
--pm2 / --no-pm2 交互提问 是否生成 pm2.config.json
--docker / --no-docker 交互提问 是否生成 Dockerfile
--python 3.12 目标 Python 版本(写入 .python-version)
--author git config user.name 作者署名
--force 关 目标目录已存在时覆盖重建
--no-git 关 跳过 git init

全部关键项通过 flag 提供时零交互:

fastapp create my-server --description "demo" --no-pm2 --no-docker

生成完成后:

cd my-server && uv sync
make dev        # 访问 /api/v1/docs

生成项目依赖

fastapi、sqlmodel、alembic、celery[redis]、fastapi-pagination、fastapi-filter、loguru、pydantic-settings 等,dev 组含 pytest / ruff / mypy / pre-commit。

开发 fastapp-cli 自身

uv sync --group dev
uv run pytest          # 单元 + 冒烟测试
uv run ruff check .

发布

uv build     # 构建 sdist + wheel(模板随包发布)
uv publish   # 发布到 PyPI

版本策略:v0.1.0 起,语义化版本。

Metadata

Release files for fastapp-cli 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapp-cli 0.1.0
File Size Uploaded
fastapp_cli-0.1.0.tar.gz 83.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapp-cli 0.1.0
File Interpreter ABI Platform
fastapp_cli-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 142.8 kB

Release files / fastapp_cli-0.1.0.tar.gz

Download URL fastapp_cli-0.1.0.tar.gz
Size 83.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2c2122b61b045516b3acb4fd6de44e95de05b3c9e061e5f8e515cefcbbb843e8
BLAKE2b-256 checksum
How to use checksums
9de7eff22d7e460c7bc73a0da9cccac21c44abe8f1d2ccc943bb535415ed6964
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / fastapp_cli-0.1.0-py3-none-any.whl

Download URL fastapp_cli-0.1.0-py3-none-any.whl
Size 59.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3658cd9e547ee7132fe238da7034cd9d5458c49c7099dca8aad52c17de1d849
BLAKE2b-256 checksum
How to use checksums
f78382bcc1eea7ddd8017c41bcf7fe2b2b1040efc6afe7ee2b2f2bb5a82ff2cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page