Package to transform python functions into state of the art REST API
Project description
model2api
Turns your Python functions into microservices REST API in an instant.
Instantly turn your Python functions into production-ready microservices. Deploy and access your services via REST API. model2api
builds on open standards - OpenAPI, JSON Schema, and Python type hints - and is powered by FastAPI, and Pydantic. It cuts out all the pain for productizing and sharing your Python code - or anything you can wrap into a single Python function.
This package is based on opyrator and was fork as the package was relying on older version of FastAPI and Starlette.
Highlights
- Turn functions into production-ready services within seconds.
- Auto-generated HTTP API based on FastAPI.
- Save and share as self-contained executable file or Docker image.
- Instantly deploy and scale for production usage.
- Track and monitor API's call with correlation_id
Getting Started
Installation
Requirements: Python 3.7+.
pip install model2api
Usage
-
A simple compatible function could look like this:
from pydantic import BaseModel class Input(BaseModel): message: str class Output(BaseModel): message: str def hello_world(input: Input) -> Output: """Returns the `message` of the input data.""" return Output(message=input.message)
A compatible function is required to have an
input
parameter and return value based on Pydantic models or an UploadFile. The input and output models are specified via type hints. -
Copy this code to a file, e.g.
model.py
-
Run the HTTP API server from command-line:
model2api model:hello_world
In the output, there's a line that shows where your web service is being served, on your local machine.
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
Hashes for model2api-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73f475c1f2ae60add3998b7fd7073fa9b44c71722ab73e8c686d6d46651e9db3 |
|
MD5 | 08e770809107885e275e76aa96d20e58 |
|
BLAKE2b-256 | 4ee64fa894e5c0b9739ff21cc2158297d54bff1cc0e3c551be031e897f323f31 |