fastapi-ml-skeleton

eightBECApache-2.0更新放缓

基于 FastAPI 的机器学习模型服务骨架,帮你快速搭出可上生产环境的推理 API,省去从零写服务框架的功夫。

FastAPI Skeleton App to serve machine learning models production-ready.

v1.1.0发布于 2023-12-28 20:44 UTC601star92fork同步于 2026-11-07 07:31 UTC

怎么上手

由 README 提炼,执行前请确认
poetry install
set -a
source .env
set +a
uvicorn fastapi_skeleton.main:app
硬件要求按 README 说明

README 未说明,仅要求 Python 3.11+ 与 Poetry,未提及 GPU 或显存

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

基于 FastAPI 的生产级机器学习模型服务骨架,帮你快速搭起带鉴权的 REST 推理接口

基于 FastAPI 的机器学习模型服务骨架,帮你快速搭出可上生产环境的推理 API,省去从零写服务框架的功夫。

核心能力

  • 内置房价回归示例模型,可直接跑通推理流程
  • 用 .env 中的 API_KEY 做接口鉴权
  • 预置 tox 与 linting 脚本,集成 isort、mypy、flake8、black、bandit
  • 自带测试脚本,README 称测试覆盖完整

容易踩的坑

需先把 .env.example 复制为 .env 并自行生成 API_KEY,否则鉴权无法通过;启动前必须 source .env 导出环境变量;默认监听 8000 端口,调用前需在 /docs 点 Authorize 填入 API key

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

1 个版本v1.1.0
  1. 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

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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

    1. Duplicate the .env.example file and rename it to .env

    2. In the .env file configure the API_KEY entry. 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

    1. Start your app with:
    set -a
    source .env
    set +a
    uvicorn fastapi_skeleton.main:app
    
    1. Go to http://localhost:8000/docs.
    2. Click Authorize and enter the API key as created in the Setup step. Authroization
    3. You can use the sample payload from the docs/sample_payload.json file when trying out the house price prediction model using the API. Prediction with example payload

    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