Skip to main content

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.

Getting Started

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

  1. 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.

  2. Copy this code to a file, e.g. model.py

  3. Run the HTTP API server from command-line:

    model2api launch-api 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


Download files

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

Source Distribution

model2api-0.0.2.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

model2api-0.0.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file model2api-0.0.2.tar.gz.

File metadata

  • Download URL: model2api-0.0.2.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for model2api-0.0.2.tar.gz
Algorithm Hash digest
SHA256 3fafad8d3a6ccf4ba672d7a4b4116d5b95b2104e75bb654093908ea8e82426f5
MD5 82746cee3f6a44782c1b5662552189c5
BLAKE2b-256 c4543524ae75b7daaada659154babc5ddc6543f4772305c334db2aba18b38da5

See more details on using hashes here.

File details

Details for the file model2api-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: model2api-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for model2api-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8f2b0ba9b3aff23cc8c6b3da09a53114d4b27f6c1272ef87302f3231dd95a1a4
MD5 ea36c0bb019f2cf9f3b46b24bc9acddf
BLAKE2b-256 097f7f5267fefeccdb55f8a4b4d3b6f82aa57bdc6db5cc8d407a6913cd68b17c

See more details on using hashes here.

Supported by

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