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 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.3.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.3-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastapi_pypendency-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ffabb3af0ed64b825cb2785f5d02bbab118e6044ac1f0d7ac01de45235d4340e
MD5 8e5b7deec3f0388a3efdcffbf32ba6ea
BLAKE2b-256 dfb6744f43836af18afa12ef4391683c6fe9c16f509b284eadd014cbd819b442

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_pypendency-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c2fb5962d086e396a5f5e200c46d71bb1a145c62b62b07b3ae34a1314f78bb1c
MD5 ed00c7308d81965974b51f489c6b995a
BLAKE2b-256 2b8ced8758ade28b92bb1f09a0360e68be3f25d729ce8d05e51b9c89d8e8be0f

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