Skip to main content

No project description provided

Project description

fastapi-better-di

Installation

pip install fastapi_better_di

Usage

# routes.py
from fastapi_better_di import APIRouterDI

from custom_types import MyType

api = APIRouterDI()

@api.get("/")
def handler(my_type: MyType):  # <- DI without Depends()
    return {"my_type": my_type.value}
# app.py
from fastapi_better_di import FastAPIDI

from custom_types import MyType

app = FastAPIDI()

# Register types for DI
app.dependency_overrides[MyType] = lambda: MyType(123)

def register_routers():
    from routes import api

    app.include_router(router=api)

register_routers()
  1. See examples

How it works

fastapi-better-di simply patch the handler function and add = Depends(func) as the default argument

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

fastapi-better-di-0.0.2.tar.gz (2.6 kB view hashes)

Uploaded Source

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