需先把 .env.example 复制为 .env 并自行生成 API_KEY,否则鉴权无法通过;启动前必须 source .env 导出环境变量;默认监听 8000 端口,调用前需在 /docs 点 Authorize 填入 API key
fastapi-ml-skeleton
eightBECApache-2.0更新放缓基于 FastAPI 的机器学习模型服务骨架,帮你快速搭出可上生产环境的推理 API,省去从零写服务框架的功夫。
FastAPI Skeleton App to serve machine learning models production-ready.
poetry install
set -a
source .env
set +a
uvicorn fastapi_skeleton.main:appREADME 未说明,仅要求 Python 3.11+ 与 Poetry,未提及 GPU 或显存
基于 FastAPI 的生产级机器学习模型服务骨架,帮你快速搭起带鉴权的 REST 推理接口
基于 FastAPI 的机器学习模型服务骨架,帮你快速搭出可上生产环境的推理 API,省去从零写服务框架的功夫。
核心能力
- 内置房价回归示例模型,可直接跑通推理流程
- 用 .env 中的 API_KEY 做接口鉴权
- 预置 tox 与 linting 脚本,集成 isort、mypy、flake8、black、bandit
- 自带测试脚本,README 称测试覆盖完整
容易踩的坑
- v1.1.0最新正式版2023-12-28 · 2023-12-28 20:44 UTC
Release v.1.1.0
- Updated to Python 3.11
- Added linting script
- Updated to pydantic 2.x
- Added poetry as package manager
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
FastAPI Model Server Skeleton
Serving machine learning models production-ready, fast, easy and secure powered by the great FastAPI by Sebastián Ramírez](https://github.com/tiangolo).
This repository contains a skeleton app which can be used to speed-up your next machine learning project. The code is fully tested and provides a preconfigured tox to quickly expand this sample code.
To experiment and get a feeling on how to use this skeleton, a sample regression model for house price prediction is included in this project. Follow the installation and setup instructions to run the sample model and serve it aso RESTful API.
Requirements
- Python 3.11+
- Poetry
Installation
Install the required packages in your local environment (ideally virtualenv, conda, etc.).
poetry install
Setup
-
Duplicate the
.env.examplefile and rename it to.env -
In the
.envfile configure theAPI_KEYentry. The key is used for authenticating our API. A sample API key can be generated using Python REPL:
import uuid
print(str(uuid.uuid4()))
Run It
- Start your app with:
set -a
source .env
set +a
uvicorn fastapi_skeleton.main:app
- Go to http://localhost:8000/docs.
- Click
Authorizeand enter the API key as created in the Setup step.
- You can use the sample payload from the
docs/sample_payload.jsonfile when trying out the house price prediction model using the API.
Linting
This skeleton code uses isort, mypy, flake, black, bandit for linting, formatting and static analysis.
Run linting with:
./scripts/linting.sh
Run Tests
Run your tests with:
./scripts/test.sh
This runs tests and coverage for Python 3.11 and Flake8, Autopep8, Bandit.
Changelog
v.1.0.0 - Initial release
- Base functionality for using FastAPI to serve ML models.
- Full test coverage
v.1.1.0 - Update to Python 3.11, FastAPI 0.108.0
- Updated to Python 3.11
- Added linting script
- Updated to pydantic 2.x
- Added poetry as package manager