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.2.tar.gz (32.9 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.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastapi_di_chain-0.0.2.tar.gz
Algorithm Hash digest
SHA256 71eb8a96c554379242100f1ca57792b10a5f3b8e72c5b2deade22b603444f7ae
MD5 da9a1d894d29874db2a13dc44218cf75
BLAKE2b-256 0fc5bf8f91adbc9b3411ddbc405eb62531ba94bc854c21b199c4ae263c39b51e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_di_chain-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 22fdc65c8ed2e9933d293aa639298e1bfcddf428e8d93d68d35408bbe04fef64
MD5 3d27424dbcc409b0bb795d8fc63da8ab
BLAKE2b-256 f7435e16643ba24d08d7d474009680ce6a72b531501bafa761c1de254cb9ee40

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