Skip to main content

A FastAPI-based algorithm flow management system with Tortoise ORM and Aerich for database migrations

Project description

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 环境变量设置为指向你的配置文件。

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

algoflow-0.1.0.tar.gz (157.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

algoflow-0.1.0-py3-none-any.whl (133.3 kB view details)

Uploaded Python 3

File details

Details for the file algoflow-0.1.0.tar.gz.

File metadata

  • Download URL: algoflow-0.1.0.tar.gz
  • Upload date:
  • Size: 157.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for algoflow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 92ef92eae9a62ae9a4d9ec64c4ceb3d27ba6fe7c4ef151fcb377cb57eddf25f0
MD5 3f970d5e6867588ac3a3d582db3e8733
BLAKE2b-256 13604ef5669ea015908d2e27d7954834958ea0543caf57027e4c9bb6d9d5b2f4

See more details on using hashes here.

File details

Details for the file algoflow-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: algoflow-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 133.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for algoflow-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec1e6857c44d6d501a1a8a9d056f5e80b7b050953e0cd658224ad19e69e88037
MD5 cca28d3454c53bca2887a9f15d0bd394
BLAKE2b-256 51c2119a321b429253deb3c42bf3e8e6c8d1aefdf20b7260ae5c76fc872d0921

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