Skip to main content

A CLI tool for deploying ML models as production-ready REST APIs

Project description

DeployWizard

Python Version License: MIT Tests Code style: black

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.

Features

  • 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

Installation

  1. Create and activate a virtual environment (recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows use: venv\Scripts\activate
    
  2. Install DeployWizard using pip:

    pip install deploywizard
    
  3. Verify installation:

    deploywizard --version
    

Quick Start

1. Register a Model

# Register a scikit-learn model
deploywizard register iris_model.pkl --name iris_classifier --version 1.0.0 --framework sklearn --description "Iris classifier with 95% accuracy"

# Register a PyTorch model
deploywizard register sentiment_model.pt --name sentiment_analyzer --version 2.1.0 --framework pytorch --description "BERT-based sentiment analysis"

# Register a TensorFlow model
deploywizard register image_model.h5 --name image_classifier --version 3.0.0 --framework tensorflow --description "CNN for image classification"

2. List and Inspect Models

# List all registered models
deploywizard list
# Output:
# ┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
# ┃ Name                ┃ Version ┃ Framework ┃ Description                                      ┃ Registered At ┃
# ┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
# │ test-model          │ 1.0.0   │ sklearn   │ Test model                                       │ 2025-06-23    │
# │ test-model-db0357e8 │ 1.0.0   │ sklearn   │ Test model                                       │ 2025-06-23    │
# │ sklearn_test_model  │ 1.0.0   │ sklearn   │ Logistic regression model trained on 100         │ 2025-06-23    │
# │                     │         │           │ samples, ...                                     │               │
# └─────────────────────┴─────────┴───────────┴──────────────────────────────────────────────────┴───────────────┘

# Get detailed info about a specific model
deploywizard info --name sklearn_test_model
# Output:
# 
# Model Information
#   • Name: sklearn_test_model
#   • Version: 1.0.0
#   • Framework: sklearn
#   • Path: /path/to/test_models/sklearn_model.pkl
#   • Registered: 2025-06-23T12:35:12.495113+00:00
#
# Description:
#   Logistic regression model trained on 100 samples, 4 features and 2 classes.

3. Deploy a Model

# Deploy a specific version of a model
deploywizard deploy --name sklearn_test_model --version 1.0.0 --output sklearn_test_model_api

# For PyTorch models saved as state_dict, provide the model class file
deploywizard deploy --name pytorch_model --model-class path/to/model.py --output pytorch_model_api

# Or deploy the latest version (omitting --version)
deploywizard deploy --name sklearn_test_model --output my_model_api

4. PyTorch Model Deployment

When deploying PyTorch models, you have several options:

  1. Full Model: If you saved the entire model using torch.save(model, 'model.pt'), you can deploy it directly:

    deploywizard deploy --name my_pytorch_model --output pytorch_api
    
  2. State Dictionary: If you saved just the state dict (torch.save(model.state_dict(), 'model.pt')), you need to provide the model class definition:

    deploywizard deploy --name my_pytorch_model --model-class path/to/model.py --output pytorch_api
    

    The model class file should define a PyTorch model that inherits from torch.nn.Module. For example:

    import torch
    import torch.nn as nn
    
    class SimpleTorchModel(nn.Module):
        def __init__(self):
            super().__init__()
            self.fc1 = nn.Linear(input_size, hidden_size)
            self.fc2 = nn.Linear(hidden_size, 1)
            self.sigmoid = nn.Sigmoid()
        
        def forward(self, x):
            x = torch.relu(self.fc1(x))
            x = self.fc2(x)
            return self.sigmoid(x)
    

5. Run the Deployed API

After deploying, navigate to the output directory and start the API:

cd sklearn_test_model_api
docker-compose up --build

Once the containers are up and running, you can access:

  • API: http://localhost:8000
  • Interactive API documentation: http://localhost:8000/docs
  • Alternative documentation: http://localhost:8000/redoc

6. Test the API

You can test the API using curl or any HTTP client:

# Health check
curl http://localhost:8000/health
# Expected output: {"status":"healthy"}

# Make predictions (example for a scikit-learn model)
curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"data": [[5.1, 3.5, 1.4, 0.2]]}'

Testing

DeployWizard 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

Troubleshooting

Common Issues

  1. Model not found

    • Ensure the model file exists at the specified path
    • Verify the framework is correctly specified
  2. PyTorch Model Loading Issues

    • For state_dict models, ensure you've provided the --model-class option
    • 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
  3. Port already in use

    • Stop any containers using port 8000
    • Or specify a different port: docker run -p 8080:8000
  4. Docker build fails

    • Check your internet connection
    • Verify Docker is running
    • Check the Docker logs for specific error messages
  5. UnicodeDecodeError on Windows

    • Ensure your terminal supports UTF-8 encoding
    • Set the following environment variable: set PYTHONUTF8=1

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a new branch for your feature
  3. Commit your changes with descriptive messages
  4. Push to the branch
  5. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deploywizard-0.2.1.23062025.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deploywizard-0.2.1.23062025-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file deploywizard-0.2.1.23062025.tar.gz.

File metadata

  • Download URL: deploywizard-0.2.1.23062025.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for deploywizard-0.2.1.23062025.tar.gz
Algorithm Hash digest
SHA256 03210522e37373962b116673e2303482b141a5a055b1c6f738eec762384ae893
MD5 7dd7e033d7db4ece865fbf164a89dec3
BLAKE2b-256 ad143509aacafc78799663f33eb4b6001958f73fc45deae4dc26d4f27c823f25

See more details on using hashes here.

File details

Details for the file deploywizard-0.2.1.23062025-py3-none-any.whl.

File metadata

File hashes

Hashes for deploywizard-0.2.1.23062025-py3-none-any.whl
Algorithm Hash digest
SHA256 6664a11c84750e73cc165433ecd601c8dc9b16e3f33fd739198a799c1da6b93c
MD5 06c8884f1a1c79f084e8d3603c5b2c5a
BLAKE2b-256 8d9b6d8efa3cb5913d03d0f9951ae4dbc5730670c6da6c3d7770a7f42d560fd4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page