runpod-python icon indicating copy to clipboard operation
runpod-python copied to clipboard

Support Pydantic models

Open danielgafni opened this issue 8 months ago • 0 comments

Is your feature request related to a problem? Please describe. runpod is built on top of FastAPI, yet it currently doesn't support one of FastAPI's main features: automatic serialization/deserialization with Pydantic models.

It would be really useful it such support existed. This would make writing code for RunPod less error-prone, increase type-checking coverage, and simplify migration from existing FastAPI endpoints.

Describe the solution you'd like I would like to be able to write code similar to:

from runpod import EndpointRequest
from pydantic import BaseModel

class MyRequest(BaseModel):
    foo: str

class MyResponse(BaseModel):
    bar: float

def handler(request: EndpointRequest[MyRequest] ) -> MyReponse:
    # type-checkers should recognize this as an instance of MyRequest (with the help of the generic annotation above)
    my_data = request.input
    ...
    return MyReponse(...)

Describe alternatives you've considered Currently there is no clean way of integrating existing FastAPI endpoints to RunPod. They have to be rewritten, and data has to be parsed manually.

danielgafni avatar Jun 06 '24 10:06 danielgafni