Skip to main content

Pypendency integration with FastAPI

Project description

fastapi-pypendency

Pypendency integration with FastAPI.

Based on

Installation

pip install fastapi-pypendency

Usage

Configure your FastAPI app with the Pypendency class:

import os
from fastapi import FastAPI
from fastapi_pypendency import Pypendency


app = FastAPI()

Pypendency(
    app,
    "_dependency_injection",
    [os.path.dirname(os.path.abspath(__file__))],  # ["src"],
)

A sample controller:

# get_user_controller.py
class GetUserController:
    def get(self) -> dict:
        return {"user": "John Doe"}
# _dependency_injection/get_user_controller.yaml
GetUserController:
  fqn: get_user_controller.GetUserController

On your router:

from fastapi import APIRouter
from fastapi import Request
from fastapi_pypendency import ContainerBuilder
from fastapi_pypendency import get_container
from get_user_controller import GetUserController


router = APIRouter(
    prefix="/user",
    tags=["user"],
    dependencies=[],
    responses={404: {"description": "Not found"}},
)

@router.get("/")
def get_user(request: Request):
    container: ContainerBuilder = get_container(request)
    controller: GetUserController = container.get("GetUserController")
    return {"id": controller.get()}

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_pypendency-0.1.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

fastapi_pypendency-0.1.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_pypendency-0.1.2.tar.gz.

File metadata

  • Download URL: fastapi_pypendency-0.1.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for fastapi_pypendency-0.1.2.tar.gz
Algorithm Hash digest
SHA256 566a5f423761b1904f6ec9c07592ef6859e9a26c44499f525076b6dcf005f39e
MD5 f095466f7a9a2ed8137964f4a7a87c22
BLAKE2b-256 6d5ddce0c734c4a23501bbbca422f6d7eaa24dbc29c5492101814df637b40010

See more details on using hashes here.

File details

Details for the file fastapi_pypendency-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_pypendency-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 93a29d8b23d504cf04a35da33a80ad14ad2bd028324a889863867bb56e4e890a
MD5 e94b3d37334bfd52f1977eba52d440b1
BLAKE2b-256 91c266e177a400f796e06e4654ff6e11e4008017ac8fd624ffada2d1b4c2e09a

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