Skip to main content

Pypendency integration with FastAPI

Project description

fastapi-pypendency

Pypendency integration with FastAPI.

Based on

Installation

pip install flask-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.1.tar.gz (3.3 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.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_pypendency-0.1.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.13.0

File hashes

Hashes for fastapi_pypendency-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b45dfbb5e36a713de4a6a51fcbe2bd97ef4ad6b4213543d2d2e8b0f46f7b6334
MD5 c66ee038fac846edfdc4a904d081e3d6
BLAKE2b-256 bf3d3cef105de0980d8e371cf028a486845f71d2acfc0c49014e6c0a9768cbc2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_pypendency-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bfd7f415f6bdb0dbc0e43d5e6365cdd97507ea248d8312e08564af7c3ca71064
MD5 8dc47a24547ea573e4c1b5ec026d4e85
BLAKE2b-256 38c7357bd9fa3c6ad57e8709256219e013fd2224baae17c13c987180876a269d

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