https://github.com/sudohainguyen/cookiecutter-ml-fastapi-template
A Cookiecutter-based code structure template for a simple API to serve ML/DL models using FastAPI.
https://github.com/sudohainguyen/cookiecutter-ml-fastapi-template
cookiecutter fastapi fastapi-template machine-learning
Last synced: 2 months ago
JSON representation
A Cookiecutter-based code structure template for a simple API to serve ML/DL models using FastAPI.
- Host: GitHub
- URL: https://github.com/sudohainguyen/cookiecutter-ml-fastapi-template
- Owner: sudohainguyen
- Created: 2021-05-10T04:16:18.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-09-18T03:31:01.000Z (almost 5 years ago)
- Last Synced: 2025-03-21T06:11:27.137Z (over 1 year ago)
- Topics: cookiecutter, fastapi, fastapi-template, machine-learning
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ML FastAPI template
A Cookiecutter-based code structure template for a simple API to serve ML/DL models using FastAPI.
## Features
- `flake8` for code styling.
- Auto clean code before making commits with `pre-commit`.
- Pre-written Dockerfile.
- Requirements split into multiple files (base, dev, prod).
- Include `pip-chill` which is able to quickly export pip packages cleaner.
- Cookiecutter will generate entire FastAPI project based on given info. The project stucture should include:
- `data`: where ml models or static files stored
- `envs`: env files for dev, staging or prod environment.
- `requirements`: python packages requirements
- `src`: where to put your code
## Run Locally
You can either create a virtual env python or use existing one
Install Cookiecutter
```bash
pip install cookiecutter==1.7.3
```
Clone the project using cookiecutter, while cloning, you need to specify some information such as `project_name` or `short_description`, etc...
```bash
cookiecutter https://github.com/sudohainguyen/ml-fastapi-template
```
Go to the project directory
```bash
cd [your_project_name]
```
Install dependencies
```bash
pip install requirements/dev.txt
```
Install pre-commit hook
```bash
pre-commit install
```
Start the server
```bash
python src/api.py
```
## Deployment
To deploy this project, please use Dockerfile to build image for the API.
```bash
docker build -t [image_name]:[tag] --build-arg PROD .
```
## Running Tests
Recommended to use `pytest` for automation test purposes. All test cases should be placed in `test` folder.
```bash
pytest -s
```
## Contributing
Contributions or suggestions are always welcome! Please feel free to contact me or create new PRs.
## Acknowledgements
Inspired by [cookiecutter-spacy-api](https://github.com/microsoft/cookiecutter-spacy-fastapi) and [topdup](https://github.com/forummlcb/topdup).