Skip to main content

a FastAPI model generator and Ai model serving

Reason this release was yanked:

Missing library

Project description

FastModelAPI

A lightweight Python package that turns any Ai inference class with a __call__ method into a web service, as long as its inputs and outputs use Pydantic models. Designed for ML inference, it simplifies exposing models without manually defining request and response schemas.

Features

  • Converts a callable class into a FastAPI-based web service
  • Accepts requests as multipart/form-data
  • Supports JSON or streaming responses based on output serializability
  • Built on FastAPI, Pydantic, and Uvicorn

Installation

Since this package is not yet on PyPI, install it manually:

git clone git@github.com:Iito/fastmodel.git
cd fastmodel
pip install .

Usage

Here's an example of exposing an OCR model using pytesseract:

import pytesseract
from PIL.Image import Image
from pydantic import BaseModel, ConfigDict, SkipValidation

class OCRModelInput(BaseModel):
    model_config = ConfigDict(arbitrary_types_allowed=True)
    image: SkipValidation[Image]
    timeout: int = 10

class OCRModelOutput(BaseModel):
    text: str

class OCRModel:
    def __init__(self):
        self.ocr = pytesseract

    def __call__(self, input: OCRModelInput) -> OCRModelOutput:
        pred = self.ocr.image_to_string(input.image)
        return OCRModelOutput(text=pred)

    @staticmethod
    def version():
        return str(pytesseract.get_tesseract_version())

You can try this examples as follow:

  • tesseract must be installed on the host machine.
export PYTHONPATH=`pwd`/examples:$PYTHONPATH
fastmodel serve ocr.OCRModel

Request Example

Send an image for OCR processing using curl:

curl -X POST 'http://localhost:8000/' \
--form 'image=@"/path/to/image"'
--form 'timeout="20"'

Response Example

{
  "status": int,
  "message": str,
  "version": str,
  "text": str
}

Limitations

  • Only works with Uvicorn (Gunicorn is not supported).
  • Single worker only due to the way the server is handled.
  • No customization options yet.

Why This Exists

FastAPI is great with native python types and Pydantic models, but manually defining request and response models is tedious. This package automates that, making it easier to serve ML models without extra boilerplate.

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

fastmodel-0.1.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

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

fastmodel-0.1.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file fastmodel-0.1.0.tar.gz.

File metadata

  • Download URL: fastmodel-0.1.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.16

File hashes

Hashes for fastmodel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0c501c8ab06e07c8a963c48a8627e1182c6387a4215efa5880d5bd66aad0f587
MD5 06e7209c2ced7681b743aa98793dd45c
BLAKE2b-256 5de1b13ef23120ae736f62c900a28634218bf23d0112abc7ccfeee243322cdc7

See more details on using hashes here.

File details

Details for the file fastmodel-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastmodel-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.16

File hashes

Hashes for fastmodel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52b54075a59933db0474437fb0adc664c85ac41a07eb50030ce05e6ec99b3ed7
MD5 80e74c763f90ebfbcba15918f4f983c4
BLAKE2b-256 949727461675adcc12871719b270d3b9818942778fcc46b706a52ce5875fb4b2

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