# Quick-API
Turn a Model into an API in One Line
Quick-API is a Python library that wraps saved machine learning models (like `.pkl`, `.h5`, `.joblib` files) in a simple REST API using FastAPI with just one line of code.
## Features
- 🚀 **One-line API creation** - Turn any saved model into a REST API instantly
- 🔄 **Auto data conversion** - Automatically handles JSON to NumPy array conversion
- 📊 **Multiple model formats** - Supports scikit-learn, TensorFlow/Keras, PyTorch models
- ⚡ **FastAPI powered** - Built on FastAPI for high performance and automatic documentation
- 🔍 **Automatic endpoint discovery** - Creates `/predict` endpoint automatically
- 📝 **Interactive docs** - Get Swagger UI documentation out of the box
- 🛡️ **Input validation** - Built-in request validation and error handling
## Installation
```bash
pip install ml-quick-api
```
## Quick Start
### 1. Basic Usage
```python
from quick_api import create_api
# Turn your model into an API with one line
api = create_api("path/to/your/model.pkl")
# Run the API
api.run()
```
### 2. Advanced Usage
```python
from quick_api import create_api
# Create API with custom configuration
api = create_api(
model_path="models/my_classifier.pkl",
host="0.0.0.0",
port=8080,
title="My ML API",
description="A custom machine learning API",
version="1.0.0"
)
# Run with custom settings
api.run(reload=True, workers=4)
```
### 3. Using the API
Once your API is running, you can make predictions:
```bash
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{"data": [[1.0, 2.0, 3.0, 4.0]]}'
```
Or visit `http://localhost:8000/docs` for interactive Swagger documentation.
## Supported Model Types
- **Scikit-learn models** (`.pkl`, `.joblib`)
- **TensorFlow/Keras models** (`.h5`, `.keras`, saved_model format)
- **PyTorch models** (`.pt`, `.pth`)
- **Custom models** with predict method
## API Endpoints
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/predict` | POST | Make predictions with your model |
| `/health` | GET | Check API health status |
| `/info` | GET | Get model information |
| `/docs` | GET | Interactive API documentation |
## Examples
### Scikit-learn Example
```python
import joblib
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from quick_api import create_api
# Train and save a model
X, y = make_classification(n_samples=1000, n_features=4)
model = RandomForestClassifier()
model.fit(X, y)
joblib.dump(model, "classifier.pkl")
# Create API
api = create_api("classifier.pkl")
api.run()
```
### TensorFlow Example
```python
import tensorflow as tf
from quick_api import create_api
# Assuming you have a saved TensorFlow model
api = create_api("path/to/model.h5")
api.run()
```
## Configuration Options
```python
api = create_api(
model_path="model.pkl", # Path to your model file
host="localhost", # Host to run the API on
port=8000, # Port to run the API on
title="Quick-API", # API title
description="ML Model API", # API description
version="1.0.0", # API version
input_shape=None, # Expected input shape (auto-detected)
preprocess_func=None, # Custom preprocessing function
postprocess_func=None, # Custom postprocessing function
)
```
## CLI Usage
Quick-API also provides a command-line interface:
```bash
# Basic usage
quick-api serve model.pkl
# With custom options
quick-api serve model.pkl --host 0.0.0.0 --port 8080 --title "My API"
```
## Development
```bash
# Clone the repository
git clone https://github.com/yourusername/quick-api.git
cd quick-api
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black quick_api/
# Type checking
mypy quick_api/
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Changelog
### v0.1.0
- Initial release
- Support for scikit-learn, TensorFlow, and PyTorch models
- FastAPI-based REST API
- Automatic documentation
- CLI interface
Raw data
{
"_id": null,
"home_page": "https://github.com/AbhishekNair050/quick-api",
"name": "ml-quick-api",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Your Name",
"author_email": "abhishek.naiir@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d1/76/a02afe493a1a9b70b3ed0484c380f1d7f626ee1b18d42ed5413cc3859f7d/ml-quick-api-0.1.1.tar.gz",
"platform": null,
"description": "# Quick-API\r\n\r\nTurn a Model into an API in One Line\r\n\r\nQuick-API is a Python library that wraps saved machine learning models (like `.pkl`, `.h5`, `.joblib` files) in a simple REST API using FastAPI with just one line of code.\r\n\r\n## Features\r\n\r\n- \ud83d\ude80 **One-line API creation** - Turn any saved model into a REST API instantly\r\n- \ud83d\udd04 **Auto data conversion** - Automatically handles JSON to NumPy array conversion\r\n- \ud83d\udcca **Multiple model formats** - Supports scikit-learn, TensorFlow/Keras, PyTorch models\r\n- \u26a1 **FastAPI powered** - Built on FastAPI for high performance and automatic documentation\r\n- \ud83d\udd0d **Automatic endpoint discovery** - Creates `/predict` endpoint automatically\r\n- \ud83d\udcdd **Interactive docs** - Get Swagger UI documentation out of the box\r\n- \ud83d\udee1\ufe0f **Input validation** - Built-in request validation and error handling\r\n\r\n## Installation\r\n\r\n```bash\r\npip install ml-quick-api\r\n```\r\n\r\n## Quick Start\r\n\r\n### 1. Basic Usage\r\n\r\n```python\r\nfrom quick_api import create_api\r\n\r\n# Turn your model into an API with one line\r\napi = create_api(\"path/to/your/model.pkl\")\r\n\r\n# Run the API\r\napi.run()\r\n```\r\n\r\n### 2. Advanced Usage\r\n\r\n```python\r\nfrom quick_api import create_api\r\n\r\n# Create API with custom configuration\r\napi = create_api(\r\n model_path=\"models/my_classifier.pkl\",\r\n host=\"0.0.0.0\",\r\n port=8080,\r\n title=\"My ML API\",\r\n description=\"A custom machine learning API\",\r\n version=\"1.0.0\"\r\n)\r\n\r\n# Run with custom settings\r\napi.run(reload=True, workers=4)\r\n```\r\n\r\n### 3. Using the API\r\n\r\nOnce your API is running, you can make predictions:\r\n\r\n```bash\r\ncurl -X POST \"http://localhost:8000/predict\" \\\r\n -H \"Content-Type: application/json\" \\\r\n -d '{\"data\": [[1.0, 2.0, 3.0, 4.0]]}'\r\n```\r\n\r\nOr visit `http://localhost:8000/docs` for interactive Swagger documentation.\r\n\r\n## Supported Model Types\r\n\r\n- **Scikit-learn models** (`.pkl`, `.joblib`)\r\n- **TensorFlow/Keras models** (`.h5`, `.keras`, saved_model format)\r\n- **PyTorch models** (`.pt`, `.pth`)\r\n- **Custom models** with predict method\r\n\r\n## API Endpoints\r\n\r\n| Endpoint | Method | Description |\r\n|----------|--------|-------------|\r\n| `/predict` | POST | Make predictions with your model |\r\n| `/health` | GET | Check API health status |\r\n| `/info` | GET | Get model information |\r\n| `/docs` | GET | Interactive API documentation |\r\n\r\n## Examples\r\n\r\n### Scikit-learn Example\r\n\r\n```python\r\nimport joblib\r\nfrom sklearn.ensemble import RandomForestClassifier\r\nfrom sklearn.datasets import make_classification\r\nfrom quick_api import create_api\r\n\r\n# Train and save a model\r\nX, y = make_classification(n_samples=1000, n_features=4)\r\nmodel = RandomForestClassifier()\r\nmodel.fit(X, y)\r\njoblib.dump(model, \"classifier.pkl\")\r\n\r\n# Create API\r\napi = create_api(\"classifier.pkl\")\r\napi.run()\r\n```\r\n\r\n### TensorFlow Example\r\n\r\n```python\r\nimport tensorflow as tf\r\nfrom quick_api import create_api\r\n\r\n# Assuming you have a saved TensorFlow model\r\napi = create_api(\"path/to/model.h5\")\r\napi.run()\r\n```\r\n\r\n## Configuration Options\r\n\r\n```python\r\napi = create_api(\r\n model_path=\"model.pkl\", # Path to your model file\r\n host=\"localhost\", # Host to run the API on\r\n port=8000, # Port to run the API on\r\n title=\"Quick-API\", # API title\r\n description=\"ML Model API\", # API description\r\n version=\"1.0.0\", # API version\r\n input_shape=None, # Expected input shape (auto-detected)\r\n preprocess_func=None, # Custom preprocessing function\r\n postprocess_func=None, # Custom postprocessing function\r\n)\r\n```\r\n\r\n## CLI Usage\r\n\r\nQuick-API also provides a command-line interface:\r\n\r\n```bash\r\n# Basic usage\r\nquick-api serve model.pkl\r\n\r\n# With custom options\r\nquick-api serve model.pkl --host 0.0.0.0 --port 8080 --title \"My API\"\r\n```\r\n\r\n## Development\r\n\r\n```bash\r\n# Clone the repository\r\ngit clone https://github.com/yourusername/quick-api.git\r\ncd quick-api\r\n\r\n# Install in development mode\r\npip install -e \".[dev]\"\r\n\r\n# Run tests\r\npytest\r\n\r\n# Format code\r\nblack quick_api/\r\n\r\n# Type checking\r\nmypy quick_api/\r\n```\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## Changelog\r\n\r\n### v0.1.0\r\n- Initial release\r\n- Support for scikit-learn, TensorFlow, and PyTorch models\r\n- FastAPI-based REST API\r\n- Automatic documentation\r\n- CLI interface\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Turn a Model into an API in One Line",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/AbhishekNair050/quick-api"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ae639a87c9c9805ee6d9da04ae653a19cf01a2d3023019b1bfe391efafd543e8",
"md5": "6e6bf5d155289b7acdbf8c8490e12058",
"sha256": "e304a7b38eb07cd31b8c662572414c60e149252c4bedbf77c82b1056da4f7ca4"
},
"downloads": -1,
"filename": "ml_quick_api-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6e6bf5d155289b7acdbf8c8490e12058",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 13312,
"upload_time": "2025-08-11T04:06:14",
"upload_time_iso_8601": "2025-08-11T04:06:14.673538Z",
"url": "https://files.pythonhosted.org/packages/ae/63/9a87c9c9805ee6d9da04ae653a19cf01a2d3023019b1bfe391efafd543e8/ml_quick_api-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d176a02afe493a1a9b70b3ed0484c380f1d7f626ee1b18d42ed5413cc3859f7d",
"md5": "29536e108decf0218811e58a363751f2",
"sha256": "3b449385bbfe2023234c5555ead868c229be411776e79abed8dfeb13ab333a6a"
},
"downloads": -1,
"filename": "ml-quick-api-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "29536e108decf0218811e58a363751f2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 17632,
"upload_time": "2025-08-11T04:06:16",
"upload_time_iso_8601": "2025-08-11T04:06:16.004068Z",
"url": "https://files.pythonhosted.org/packages/d1/76/a02afe493a1a9b70b3ed0484c380f1d7f626ee1b18d42ed5413cc3859f7d/ml-quick-api-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-11 04:06:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "AbhishekNair050",
"github_project": "quick-api",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "fastapi",
"specs": [
[
">=",
"0.68.0"
]
]
},
{
"name": "uvicorn",
"specs": [
[
">=",
"0.15.0"
]
]
},
{
"name": "pydantic",
"specs": [
[
">=",
"1.8.0"
]
]
},
{
"name": "numpy",
"specs": [
[
">=",
"1.19.0"
]
]
},
{
"name": "scikit-learn",
"specs": [
[
">=",
"0.24.0"
]
]
},
{
"name": "joblib",
"specs": [
[
">=",
"1.0.0"
]
]
}
],
"lcname": "ml-quick-api"
}