Skip to main content

Chain FastAPI dependencies without unused Depends!

Project description

fastapi-di-chain

Chain FastAPI dependencies without unused Depends!

Overview

fastapi-di-chain provides a utility to chain FastAPI dependencies in a way that avoids unused Depends parameters, making your dependency injection cleaner, more maintainable and easier to integrade.

Installation

pip install fastapi-di-chain

Usage

Suppose you have several dependencies that you want to chain together:

from fastapi import FastAPI, Depends
from fastapi_di_chain import DependsChain

app = FastAPI()

def my_rate_limiting_dependency() -> None:
    # e.g. checks rate limiting
    pass

def my_authentication_dependency() -> None:
    # e.g. checks that user is authenticated to do a request
    pass

dependency_chain = DependsChain | my_rate_limiting_dependency | my_authentication_dependency

@app.get("/profile", dependencies=[dependency_chain])
def profile() -> dict:
    return {"user": 123}

License

fastapi-di-chain is distributed under the terms of the MIT license. Please see License.md for more information.

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_di_chain-0.0.3.tar.gz (33.2 kB view details)

Uploaded Source

Built Distribution

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

fastapi_di_chain-0.0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_di_chain-0.0.3.tar.gz.

File metadata

  • Download URL: fastapi_di_chain-0.0.3.tar.gz
  • Upload date:
  • Size: 33.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.19

File hashes

Hashes for fastapi_di_chain-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2839f948a264cb49576d27403f09d7223544abc59087c459540d27e7e1cc870b
MD5 00c584edcd05b31f2b28e2aa55a50c25
BLAKE2b-256 6b1938abf16831eac089aeaf104ca616a2b7d062b0e1e607fa0c6e06340d9257

See more details on using hashes here.

File details

Details for the file fastapi_di_chain-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_di_chain-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7b317d8ee49211c8961d53517398305962eef94eee4e1a55ee34a7adbc1d41d2
MD5 69783f11df8d11f760ef1ae00d68f557
BLAKE2b-256 392fc6c8948f6e0962e3d36c2cb8412bf2cc0ac2a89e8dcb012c03acac2b8f5d

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