Deployment of a Machine Learning model with FastAPI
Python, FastAPI, REST API, PostgreSQL, SQLAlchemy, Pytest, GitHub Actions, CI/CD, Machine Learning, OpenAPI
Deploying a Machine Learning Model with FastAPI
Context
As part of a Machine Learning Engineering project, I industrialized a Machine Learning model by developing a secure and documented REST API. The objective was to make the model production-ready while applying best practices in software development, automated testing, and continuous deployment.
Objectives
- Deploy a Machine Learning model as a REST API.
- Design a professional project architecture.
- Set up a PostgreSQL database.
- Develop unit and functional tests.
- Automate tests and deployment with a CI/CD pipeline.
- Document the entire project.
Architecture
Client
│
▼
FastAPI
│
▼
Pydantic Validation
│
▼
Machine Learning Model
│
▼
PostgreSQL
(Input / Output / History)
│
▼
Swagger / OpenAPI
Technologies Used
- Python
- FastAPI
- Pydantic
- PostgreSQL
- SQLAlchemy
- Pytest
- pytest-cov
- Git
- GitHub Actions
- Hugging Face Spaces
- Swagger / OpenAPI
Achievements
Model Industrialization
- Deployment of a Machine Learning model via a REST API.
- Automatic validation of incoming data with Pydantic.
- Error management and standardized responses.
- Interactive documentation automatically generated with OpenAPI.
Database
- Creation of a PostgreSQL database.
- Table modeling.
- Recording user requests.
- Prediction historization.
- Full traceability of exchanges between the API and the model.
Tests
Development of a comprehensive validation strategy:
- unit tests
- functional tests
- endpoint validation
- edge case testing
- code coverage measurement with pytest-cov
CI/CD
Automation of the development cycle:
- Git Flow
- GitHub Actions
- automatic test execution
- pre-merge validation
- environment management
- secure secret management
Documentation
- Comprehensive README
- Technical documentation
- API documentation
- Swagger / OpenAPI
- Installation and deployment instructions
Skills Demonstrated
Machine Learning Engineering
- ML Model Deployment
- Model Industrialization
- Prediction API
- Data Validation
Backend
- FastAPI
- REST API
- Pydantic
- Error Handling
- OpenAPI Documentation
Database
- PostgreSQL
- SQLAlchemy
- Relational Modeling
- Prediction Traceability
DevOps
- Git
- GitHub
- GitHub Actions
- CI/CD
- Version Control
- Secret Management
Software Quality
- Pytest
- Unit Tests
- Functional Tests
- Code Coverage
- Software Architecture
Outcome
This project allowed me to transform a Machine Learning model into a production-ready application by developing a robust, tested, and documented REST API. I also implemented best practices in Machine Learning Engineering, DevOps, and continuous integration to ensure the reliability, maintainability, and traceability of the solution.
Skills Acquired
- Python
- FastAPI
- REST API
- Pydantic
- PostgreSQL
- SQLAlchemy
- Machine Learning
- Pytest
- pytest-cov
- Git
- GitHub
- GitHub Actions
- CI/CD
- Swagger
- OpenAPI
- DevOps
- Hugging Face Spaces
- API Documentation
- Software Engineering