FastAPI ML Skeleton 项目教程

FastAPI ML Skeleton 项目教程

fastapi-ml-skeletonFastAPI Skeleton App to serve machine learning models production-ready.项目地址:https://gitcode.com/gh_mirrors/fa/fastapi-ml-skeleton

1. 项目的目录结构及介绍

FastAPI ML Skeleton 项目的目录结构如下:

fastapi-ml-skeleton/
├── docs/
│   └── sample_payload.json
├── fastapi_skeleton/
│   ├── __init__.py
│   └── main.py
├── sample_model/
│   └── __init__.py
├── scripts/
│   ├── linting.sh
│   └── test.sh
├── tests/
│   └── __init__.py
├── .env.example
├── .flake8
├── .gitignore
├── LICENSE
├── MANIFEST.in
├── README.md
├── poetry.lock
├── pyproject.toml
├── setup.cfg
└── tox.ini

目录结构介绍

  • docs/: 包含项目文档和示例 payload 文件。
  • fastapi_skeleton/: 包含 FastAPI 应用的主要代码。
  • sample_model/: 包含示例机器学习模型。
  • scripts/: 包含用于 linting 和测试的脚本。
  • tests/: 包含测试代码。
  • .env.example: 环境变量示例文件。
  • .flake8: Flake8 配置文件。
  • .gitignore: Git 忽略文件配置。
  • LICENSE: 项目许可证。
  • MANIFEST.in: 打包配置文件。
  • README.md: 项目说明文档。
  • poetry.lock: Poetry 依赖锁定文件。
  • pyproject.toml: 项目配置文件。
  • setup.cfg: 安装配置文件。
  • tox.ini: Tox 配置文件。

2. 项目的启动文件介绍

项目的启动文件位于 fastapi_skeleton/main.py。该文件包含 FastAPI 应用的入口点。

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Hello World"}

启动命令

可以使用以下命令启动 FastAPI 应用:

uvicorn fastapi_skeleton.main:app --reload

启动后,可以通过 http://localhost:8000/docs 访问 Swagger UI 文档。

3. 项目的配置文件介绍

pyproject.toml

pyproject.toml 是项目的主要配置文件,包含项目元数据和依赖管理信息。

[tool.poetry]
name = "fastapi-ml-skeleton"
version = "1.0.0"
description = "FastAPI Skeleton App to serve machine learning models production-ready"
authors = ["Your Name <you@example.com>"]
license = "Apache-2.0"

[tool.poetry.dependencies]
python = "^3.8"
fastapi = "^0.68.0"
uvicorn = "^0.15.0"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

.env.example

.env.example 是环境变量示例文件,用于配置应用的环境变量。

# API Key
API_KEY=your_api_key

# Database URL
DATABASE_URL=sqlite:///./test.db

.flake8

.flake8 是 Flake8 配置文件,用于代码风格检查。

[flake8]
max-line-length = 88
ignore = E203, E266, E501, W503

setup.cfg

setup.cfg 是安装配置文件,包含项目打包和安装的相关配置。

[metadata]
name = fastapi-ml-skeleton
version = 1.0.0
description = FastAPI Skeleton App to serve machine learning models production-ready
author = Your Name
author_email = you@example.com
license = Apache-2.0

[options]
packages = find:
install_requires =
    fastapi
    uvicorn

[options.packages

fastapi-ml-skeletonFastAPI Skeleton App to serve machine learning models production-ready.项目地址:https://gitcode.com/gh_mirrors/fa/fastapi-ml-skeleton

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

窦欢露Paxton

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值