Skip to content

A wrapper around FastAPI's Depends function that infers its return type from its input

License

Notifications You must be signed in to change notification settings

jvllmr/fastapi-inferring-depends

Repository files navigation

FastAPI inferring Depends

PyPI version GitHub license PyPI - Downloads Tests

A wrapper around FastAPI's Depends function that infers its return type from its input

Example

from fastapi_inferring_depends import Depends
from fastapi import FastAPI

app = FastAPI()


async def answer_to_everything_dependency():
    return 42


@app.get("/answer")
async def get_answer_to_everything(
    answer_to_everything=Depends(answer_to_everything_dependency),
):
    # type of answer_to_everything is 'int' (inferred from dependency)
    return {"answer": answer_to_everything}

For more examples, look at the test/example file for all supported inferences.

About

A wrapper around FastAPI's Depends function that infers its return type from its input

Resources

License

Stars

Watchers

Forks

Languages