DeployWizard is a powerful CLI tool that automates the deployment of machine learning models as production-ready REST APIs with Docker support. It generates all the necessary code and configuration files to containerize your ML models with FastAPI, making deployment a breeze.
- Multi-Framework Support: Works with scikit-learn, PyTorch, and TensorFlow models
- Production-Ready: Generates Dockerfiles and optimized FastAPI applications
- Environment-Aware: Handles both development and production environments
- Secure by Default: Uses non-root users in containers and secure defaults
- Easy to Use: Simple CLI interface for generating deployment code
- Customizable: Flexible template system for advanced customization
- Tested: Comprehensive test suite with 100% code coverage
-
Create and activate a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install DeployWizard using pip:
pip install deploywizard
-
Verify installation:
deploywizard --version
The init command creates a new deployment project and registers your model in one step:
# Initialize a project with a scikit-learn model
deploywizard init --model path/to/model.pkl --framework sklearn --output-dir my_ml_api
# Initialize with a custom model name
deploywizard init --model path/to/model.pkl --framework sklearn --output-dir my_ml_api --name my_model
# For PyTorch models (full model)
deploywizard init --model path/to/model.pt --framework pytorch --output-dir pytorch_api
# For PyTorch state_dict models (requires model class)
deploywizard init --model path/to/model.pt --framework pytorch --output-dir pytorch_api \
--model-class path/to/model.pyThis will:
- Register your model in the DeployWizard registry
- Create a new directory with a complete API project
- Generate all necessary configuration files
- Print the next steps to run your API
When working with PyTorch models, you have two options depending on how the model was saved:
If you saved the entire model using torch.save(model, 'model.pt'):
deploywizard init --model model.pt --framework pytorch --output-dir pytorch_apiIf you saved just the state dict using torch.save(model.state_dict(), 'model.pt'), you need to provide the model class definition:
-
Create a Python file (e.g.,
model.py) with your model class:import torch import torch.nn as nn class MyModel(nn.Module): def __init__(self, input_size=10, hidden_size=20, output_size=1): super().__init__() self.fc1 = nn.Linear(input_size, hidden_size) self.fc2 = nn.Linear(hidden_size, output_size) self.sigmoid = nn.Sigmoid() def forward(self, x): x = torch.relu(self.fc1(x)) x = self.fc2(x) return self.sigmoid(x)
-
Initialize the project with the model class:
deploywizard init --model model.pt --framework pytorch --output-dir pytorch_api \ --model-class model.py
After initializing your project, navigate to the output directory and start the API:
cd my_ml_api
docker-compose up --buildOnce the containers are running, you can access:
- API: http://localhost:8000
- Interactive API documentation: http://localhost:8000/docs
- Alternative documentation: http://localhost:8000/redoc
Test the API using curl or any HTTP client:
# Health check
curl http://localhost:8000/health
# Expected output: {"status":"healthy"}
# Make predictions (example format)
curl -X POST http://localhost:8000/predict \
-H "Content-Type: application/json" \
-d '{"features": [5.1, 3.5, 1.4, 0.2]}'If you prefer to manage the model registration separately:
# Register a model
deploywizard register model.pkl --name my_model --version 1.0.0 --framework sklearn
# Deploy a registered model
deploywizard deploy --name my_model --output my_api
# Update model metadata
deploywizard update --name my_model --new-version 2.0.0 --description "Improved model"
# Delete a model
deploywizard delete --name old_modelDeployWizard includes a comprehensive test suite. To run the tests:
# Install test dependencies
pip install -e ".[test]"
# Run all tests
pytest -v
# Run tests with coverage report
pytest --cov=deploywizard --cov-report=term-missing
# Run a specific test file
pytest tests/test_cli.py -v-
Model not found
- Ensure the model file exists at the specified path
- Verify the framework is correctly specified
-
PyTorch Model Loading Issues
- For state_dict models, ensure you've provided the
--model-classoption - Verify the model class in the provided file matches the architecture used during training
- Check that all required imports are included in your model class file
- For state_dict models, ensure you've provided the
-
Port already in use
- Stop any containers using port 8000
- Or specify a different port:
docker run -p 8080:8000
-
Docker build fails
- Check your internet connection
- Verify Docker is running
- Check the Docker logs for specific error messages
-
UnicodeDecodeError on Windows
- Ensure your terminal supports UTF-8 encoding
- Set the following environment variable:
set PYTHONUTF8=1
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch for your feature
- Commit your changes with descriptive messages
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with ❤️ using FastAPI and Docker
- Inspired by the need for simple ML model deployment solutions
- Thanks to all contributors who have helped improve this project!