Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eightBEC/fastapi-ml-skeleton
FastAPI Skeleton App to serve machine learning models production-ready.
https://github.com/eightBEC/fastapi-ml-skeleton
fastapi machine-learning model-serving python python3
Last synced: 3 months ago
JSON representation
FastAPI Skeleton App to serve machine learning models production-ready.
- Host: GitHub
- URL: https://github.com/eightBEC/fastapi-ml-skeleton
- Owner: eightBEC
- License: apache-2.0
- Created: 2020-02-15T14:27:08.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-05T23:42:10.000Z (7 months ago)
- Last Synced: 2024-08-01T00:42:32.649Z (6 months ago)
- Topics: fastapi, machine-learning, model-serving, python, python3
- Language: Python
- Size: 938 KB
- Stars: 373
- Watchers: 6
- Forks: 78
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fastapi - FastAPI Model Server Skeleton - Skeleton app to serve machine learning models production-ready. (Projects / Boilerplate)
- awesome-fastapi - FastAPI Model Server Skeleton - Skeleton app to serve machine learning models production-ready. (Projects / Boilerplate)
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.).```bash
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:```python
import uuid
print(str(uuid.uuid4()))
```## Run It
1. Start your app with:
```bash
set -a
source .env
set +a
uvicorn fastapi_skeleton.main:app
```2. Go to [http://localhost:8000/docs](http://localhost:8000/docs).
3. Click `Authorize` and enter the API key as created in the Setup step.
![Authroization](./docs/authorize.png)
4. 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](./docs/sample_payload.png)## Linting
This skeleton code uses isort, mypy, flake, black, bandit for linting, formatting and static analysis.
Run linting with:
```bash
./scripts/linting.sh
```## Run Tests
Run your tests with:
```bash
./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 coveragev.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