Skip to main content

FastAPI 模板

一个用于构建 FastAPI 应用程序的模板项目,包含 Tortoise ORM 和 Aerich 用于数据库迁移。

特性

  • FastAPI、Tortoise ORM、Aerich 和 Pydantic 构建
  • Docker Compose 快速部署
  • Github Actions CI/CD

使用

安装

  1. 克隆仓库:

    git clone https://github.com/chenxingyuu/fastapi_template.git
    cd fastapi-template
    
  2. 创建并激活虚拟环境:

    python -m venv venv
    source venv/bin/activate  # 在 Windows 上使用 `venv\Scripts\activate`
    
  3. 安装依赖项:

    pip install -r requirements.txt
    

迁移

  1. 初始化 Aerich:

    make init
    
  2. 初始化数据库:

    make init-db
    
  3. 创建并应用迁移:

    make migrate
    make upgrade
    
  4. 回滚迁移:

    make downgrade
    

运行

  1. 设置配置文件路径:

    在 Linux 或 macOS 上:

    export CONFIG_FILE_PATH=/path/to/your/config.ini
    

    在 Windows 上:

    set CONFIG_FILE_PATH=C:\path\to\your\config.ini
    
  2. 启动 FastAPI 应用程序:

    uvicorn app.main:app --reload
    
  3. 访问应用程序:

    打开浏览器并访问 http://127.0.0.1:8000。

使用 Docker

  1. 构建 Docker 镜像:

    docker build -t algo-flow:0.1.0 .
    
  2. 运行 Docker 容器:

    docker run -d -p 8000:8000 --name algo-flow-api algo-flow:0.1.0
    
  3. 访问应用程序:

    打开浏览器并访问 http://127.0.0.1:8000。

使用 Docker Compose

  1. 启动服务:

    docker-compose up -d
    
  2. 访问应用程序:

    打开浏览器并访问 http://127.0.0.1:8000。

  3. 停止服务:

    docker-compose down
    

开发

  1. 安装 pre-commit 钩子:

    pre-commit install
    
  2. 运行测试:

    # 运行所有测试
    pytest -v
    # 如果你想生成覆盖率报告,可以使用以下命令:
    pytest --cov-report=html -v
    
  3. 检查代码并格式化:

    pre-commit run --all-file
    
  4. 在开发模式下运行应用程序:

    uvicorn app.main:app --reload
    

配置

配置通过 config.ini 文件进行管理。在运行应用程序之前,请确保将 CONFIG_FILE_PATH 环境变量设置为指向你的配置文件。

Metadata

Release files for algoflow 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 algoflow 0.1.0
File Size Uploaded Provenance Actions
algoflow-0.1.0.tar.gz 157.3 kB Without provenance Details for algoflow-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 290.7 kB

Release files / algoflow-0.1.0.tar.gz

Download URL algoflow-0.1.0.tar.gz
Size 157.3 kB
Tags Source
SHA-256 checksum
How to use checksums
92ef92eae9a62ae9a4d9ec64c4ceb3d27ba6fe7c4ef151fcb377cb57eddf25f0
BLAKE2b-256 checksum
How to use checksums
13604ef5669ea015908d2e27d7954834958ea0543caf57027e4c9bb6d9d5b2f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

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

Download URL algoflow-0.1.0-py3-none-any.whl
Size 133.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec1e6857c44d6d501a1a8a9d056f5e80b7b050953e0cd658224ad19e69e88037
BLAKE2b-256 checksum
How to use checksums
51c2119a321b429253deb3c42bf3e8e6c8d1aefdf20b7260ae5c76fc872d0921
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for algoflow 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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