Skip to main content

「 FastAPI Builder V2 」


💡 fastapi 项目构建器. 一款帮助您快速构建 fastapi 项目的工具.

  fastapi-builder 是一个基于 FastAPI 框架的快速 Web 应用程序开发的工具箱。它提供了一组现成的工具和组件,可以帮助您快速构建具有良好结构和可维护性的 FastAPI Web 应用程序。其目的是提供一个一站式的解决方案,以加速快速原型开发和生产部署。


💬 特性

  • 🔥 一键生成可定制的应用程序模块,支持热更新,并提供完整的 CRUD 接口。

  • 灵感来源于 Django 的项目基础命令。

  • 支持创建可自定义的完整项目结构。

  • 自动生成项目结构,简化初始化过程。

  • 对数据库操作进行封装,简化管理流程。

  • 支持多种数据库,包括 MySQL。

  • 提供 Dockerfile 和 pre-commit 钩子等可选配置。

  • 管理虚拟环境,简化环境搭建和依赖管理。


🎯 TODO

  • 持续完善项目框架代码

  • 持续完善项目文档

  • 优化 requirements.txt

  • 提供英文文档版本

  • 提供 PostgreSQL 数据库支持

  • 提供完整的 run 方法

  • 内置 Alembic 数据迁移管理

  • 提供运行环境检查

  • 提供 FastAPI venv 命令,管理虚拟环境

  • 针对 Linux 和 Mac 环境提供支持

  • 生成 app 时,自动注入到 project 中(路由管理分配)


🚀 快速开始

=> 依赖:Python 3.8+
=> 详细教程:tutorial

安装 fastapi-builder 项目:

pip install fastapi-builder

查看项目版本:

fastapi --version

项目帮助:

fastapi --help
fastapi startproject --help

创建 fastapi 项目:

fastapi startproject [name]

# or 带有交互选择

fastapi startproject [name] --interactive

创建 fastapi 应用:

fastapi startapp [name]

运行 fastapi 项目:

fastapi run

通过访问 http://127.0.0.1:8000/docs 以确保 fastapi 服务正常运行.


📁 项目结构

.
├── alembic/                      - 数据库迁移工具
├── api/                          - web 相关(路由、认证、请求、响应).
│   ├── errors/                   - 定义错误处理方法.
│   │   ├── http_error.py         - http 错误处理方法
│   │   │── validation_error.py   - 验证错误处理方法
│   ├── routes/                   - web routes 路由.
│   │   ├── api.py                - 总路由接口
│   │   └── authentication.py     - 认证相关(登录、注册)路由
├── apps/                         - 子应用.
│   ├── app_user/                 - user 应用.
│   │   ├── api.py                - 提供 user 接口方法
│   │   ├── doc.py                - 提供 user Swagger UI 文档
│   │   ├── field.py              - 提供 user pydantic 验证字段
│   │   ├── model.py              - 提供 user 表模型
│   │   └── schema.py             - 提供 user pydantic 结构模型
│   ├── ...                       - 其他应用.
├── core/                         - 项目核心配置, 如: 配置文件, 事件句柄, 日志.
│   ├── e/                        - 错误处理包.
│   │   ├── __init__.py
│   │   ├── codes.py              - 错误码定义
│   │   └── messages.py           - 错误消息定义
│   ├── .env                      - 配置文件.
│   ├── config.py                 - 解析配置文件, 用于其他文件读取配置.
│   ├── events.py                 - 定义 fastapi 事件句柄.
│   ├── logger.py                 - 定义项目日志方法.
├── db/                           - 数据库相关.
│   ├── base.py                   - 导入所有应用 model.
│   ├── database.py               - sqlalchemy 方法应用.
│   ├── errors.py                 - 数据库相关错误异常.
├── lib/                          - 自定义库
│   ├── jwt.py                    - 用户认证 jwt 方法.
│   ├── security.py               - 加密相关方法.
├── logs/                         - 日志文件目录.
├── middleware/                   - 项目中间件.
│   ├── logger.py                 - 请求日志处理.
├── models/                       - sqlalchemy 基础模型相关
│   ├── base.py                   - sqlalchemy declarative Base 表模型.
│   └── mixins.py                 - mixin 抽象模型定义.
├── schemas/                      - pydantic 结构模型相关.
│   ├── base.py                   - pydantic 结构模型基础类.
│   ├── jwt.py                    - jwt 相关结构模型.
│   ├── response.py               - 响应模型封装.
├── utils/                        - 工具类.
│   ├── dbmanager.py              - 数据库管理服务.
│   ├── docs.py                   - fastapi docs 文档自定义.
├── .flake8                       - pep8 规范.
├── .pre-commit-config.yaml       - pre-commit 配置文件.
├── alembic.ini                   - alembic 数据库迁移工具配置文件.
├── docker-compose.yaml           - docker 配置.
├── Dockerfile                    - dockfile 文件.
├── .fastapi-builder.ini          - fastapi-builder 配置文件.
├── LICENSE                       - 许可证信息.
├── main.py                       - fastapi application 创建和配置.
├── pyproject.toml                - poetry 需求模块信息.
├── README.md                     - 项目说明文档.
├── requirements.txt              - pip 需求模块信息.
└── setup.cfg                     - pre-commit 配置文件.

⚡ 特别感谢

项目配置生成及 questionary 内容基于项目:https://github.com/ycd/manage-fastapi

fastapi 项目基础框架参考:https://github.com/nsidnev/fastapi-realworld-example-app/


🚩 许可证

项目根据麻省理工学院的许可条款授权.

Metadata

Release files for fastapi-builder 2.0.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 fastapi-builder 2.0.0
File Size Uploaded Provenance Actions
fastapi_builder-2.0.0.tar.gz 16.5 MB Without provenance Details for fastapi_builder-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-builder 2.0.0
File Interpreter ABI Platform Actions
fastapi_builder-2.0.0-py3-none-any.whl Python 3 none any Details for fastapi_builder-2.0.0-py3-none-any.whl

Total release size: 16.6 MB

Release files / fastapi_builder-2.0.0.tar.gz

Download URL fastapi_builder-2.0.0.tar.gz
Size 16.5 MB
Tags Source
SHA-256 checksum
How to use checksums
f6e4f991d375c788cfecf420094d17b285738dc22554ed8aba9bd73467157fdc
BLAKE2b-256 checksum
How to use checksums
df8d2da74bbf67398992650e21e39d4028cc5b160f1930e290792b6d0f2b83c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.11.1 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.2 tqdm/4.66.5 importlib-metadata/8.4.0 keyring/25.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.11

Release files / fastapi_builder-2.0.0-py3-none-any.whl

Download URL fastapi_builder-2.0.0-py3-none-any.whl
Size 90.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab59a3a6a328b34e13142f19a37989c4414ccc2f63f268bc91df9ac34c12e32c
BLAKE2b-256 checksum
How to use checksums
68c87e08eac117b2f529ca3ac0d02c0d0d63c31553e32044612416ee096d12d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.11.1 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.2 tqdm/4.66.5 importlib-metadata/8.4.0 keyring/25.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.11

Security for fastapi-builder 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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