A production-ready machine learning framework
Project description
MLOps-Boilerplate
A production-ready machine learning framework for building, training, deploying, and monitoring ML models at scale.
๐ Features
- Modular Architecture: Clean separation of concerns with data layer, ML components, and applications
- Multiple Data Sources: Built-in connectors for PostgreSQL, MongoDB, AWS S3, Azure Blob Storage
- ML Models: Support for Random Forest, XGBoost, and easy extensibility for custom models
- Data Processing: Complete preprocessing pipeline with feature engineering and scaling
- Cross-Validation: K-Fold and Stratified K-Fold validation with comprehensive metrics
- Experiment Tracking: Integration with MLflow for experiment management
- Configuration Management: Pydantic-based configuration with validation
- Testing: Comprehensive test suite with pytest
- Monitoring: Model performance tracking and data drift detection
- API Server: FastAPI-based REST API for model serving
- Production Ready: Docker support, CI/CD pipelines, and best practices
๐ Table of Contents
- Installation
- Quick Start
- Project Structure
- Usage Examples
- Configuration
- Testing
- API Documentation
- Contributing
- License
๐ง Installation
Install from PyPI (Recommended)
pip install mlops-boilerplate
Create a New Project
After installation, create a new ML project using the template:
# Create a new project
ml-create-project my-ml-project
# Navigate to your project
cd my-ml-project
# Set up virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\\Scripts\\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your configuration
Install from Source (For Development)
# Clone the repository
git clone https://github.com/kython220282/MLOps-Boilerplate.git
cd MLOps-Boilerplate
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\\Scripts\\activate
# Install in development mode
pip install -e .
Install with Docker
docker build -t mlops-boilerplate .
docker run -p 8000:8000 mlops-boilerplate
๐ Quick Start
1. Setup Environment
# Copy environment template
cp .env.example .env
# Edit .env with your configuration
2. Train a Model
# Using CLI
ml-train --config config/training_config.json
# Or with Python
python -m ml_service.applications.training --config config/training_config.json
3. Run Inference
ml-inference --model-path models/model.joblib \\
--input-path data/test.csv \\
--output-path predictions.csv
4. Start API Server
ml-serve --model-path models/model.joblib --port 8000
๐ Project Structure
machine_learning_service/
โโโ ml_service/ # Main package
โ โโโ applications/ # Application entry points
โ โ โโโ training.py # Training CLI application
โ โ โโโ inference.py # Inference CLI application
โ โโโ data_layer/ # Data connectors
โ โ โโโ data_connector.py # Database connectors
โ โ โโโ object_connector.py # Cloud storage connectors
โ โโโ machine_learning/ # ML components
โ โ โโโ data_processor.py # Data preprocessing
โ โ โโโ model.py # Model definitions
โ โ โโโ training_pipeline.py # Training orchestration
โ โ โโโ cross_validator.py # Model validation
โ โโโ config.py # Configuration management
โโโ config/ # Configuration files
โ โโโ training_config.json
โ โโโ training_config.yaml
โโโ tests/ # Test suite
โโโ docs/ # Documentation
โโโ requirements.txt # Dependencies
โโโ setup.py # Package setup
โโโ pyproject.toml # Project configuration
โโโ .env.example # Environment template
โโโ README.md # This file
๐ก Usage Examples
Training with Different Data Sources
From CSV File:
from ml_service.machine_learning.training_pipeline import TrainingPipeline
config = {
"data_source": {"type": "file", "path": "data/train.csv"},
"target_column": "target",
"model": {"type": "random_forest", "n_estimators": 100},
"task_type": "classification"
}
pipeline = TrainingPipeline(config)
metrics = pipeline.run_pipeline()
From Database:
config = {
"data_source": {
"type": "database",
"connector_type": "postgresql",
"connection_config": {
"host": "localhost",
"database": "ml_db"
},
"query": "SELECT * FROM training_data"
},
"target_column": "target"
}
Custom Model Development
from ml_service.machine_learning.model import BaseModel
class CustomModel(BaseModel):
def build_model(self):
# Your model architecture
pass
def train(self, X_train, y_train):
# Training logic
pass
def predict(self, X):
# Prediction logic
pass
Data Processing Pipeline
from ml_service.machine_learning.data_processor import DataProcessor
processor = DataProcessor()
df = processor.load_data("data/train.csv")
X_train, X_test, y_train, y_test = processor.preprocess_pipeline(
df, target_column="target"
)
โ๏ธ Configuration
Training Configuration
Create a JSON or YAML configuration file:
{
"data_source": {
"type": "file",
"path": "data/train.csv"
},
"target_column": "target",
"model": {
"type": "random_forest",
"n_estimators": 100,
"max_depth": 10
},
"data_processing": {
"missing_value_strategy": "mean",
"scaling_method": "standard"
},
"cross_validation": {
"type": "kfold",
"n_splits": 5
}
}
Environment Variables
Set in .env file:
# Database
DB_TYPE=postgresql
DB_HOST=localhost
DB_PORT=5432
# MLflow
MLFLOW_TRACKING_URI=http://localhost:5000
# API
API_HOST=0.0.0.0
API_PORT=8000
๐งช Testing
Run the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=ml_service --cov-report=html
# Run specific test file
pytest tests/test_model.py
# Run with markers
pytest -m unit
pytest -m integration
๐ API Documentation
Start the API server and visit http://localhost:8000/docs for interactive Swagger documentation.
Example API Endpoints
Health Check:
curl http://localhost:8000/health
Make Prediction:
curl -X POST http://localhost:8000/predict \\
-H "Content-Type: application/json" \\
-d '{"features": [1.5, 2.3, 3.1, 4.2, 5.0]}'
๐ค Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Install dev dependencies
pip install -r requirements.txt
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install
# Run code formatting
black ml_service tests
isort ml_service tests
# Run linting
flake8 ml_service tests
mypy ml_service
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- scikit-learn for ML algorithms
- MLflow for experiment tracking
- FastAPI for API framework
- Pydantic for configuration management
๏ฟฝโ๐ป Credits
Created by: Karan
GitHub: @kython220282
Repository: MLOps-Boilerplate
๐ If You Use This Framework
If you use this framework in your projects, please consider:
- โญ Star this repository on GitHub
- ๐ Add credits in your project documentation:
Built with [MLOps-Boilerplate](https://github.com/kython220282/MLOps-Boilerplate) by Karan
- ๐ Link back to this repository
- ๐ฌ Share your project - Open an issue to showcase what you've built!
Your support helps maintain and improve this framework for everyone. Thank you! ๐
๐ Support
For questions and support:
- Create an issue on GitHub
- Email: support@example.com
- Repository: https://github.com/kython220282/MLOps-Boilerplate
Happy Model Building! ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ml_service_framework-0.1.0.tar.gz.
File metadata
- Download URL: ml_service_framework-0.1.0.tar.gz
- Upload date:
- Size: 44.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
341d8f998764aa3847e8dc7866cda8ff81ddbc11a678bd4d4f8d281b44347b70
|
|
| MD5 |
0e5e416a1ab318a3a517338271865bc2
|
|
| BLAKE2b-256 |
18dbeb3e852fb329cc4d4ea06fb815932c90eef811f879fea9c623bacccd31fb
|
File details
Details for the file ml_service_framework-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ml_service_framework-0.1.0-py3-none-any.whl
- Upload date:
- Size: 38.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fa0570877201abe34941c82ce7d5f4e0762021ff9b25b1505c07ff3bcfac666
|
|
| MD5 |
af7ebcf5544e8d3989d93afba95431d4
|
|
| BLAKE2b-256 |
b24735815c228e306c322f3184d8c7a826730caf1f46865ad32740bd268cca2a
|