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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_di_chain-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 c2ee1e506312302d0d6b6d5a0d7bc39a632a92a1940a1ae72c9d3c3d7873ea28
MD5 30d6a35506e87ab08ead6ac39a3d0791
BLAKE2b-256 64cc830a824e5268f8ebb8bd5c12f91491fdfd575777db2ccf3a8de52faa65c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_di_chain-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e906989c99d4631e465be7d53886320fa92a8e2f89c5914648c895980bb13151
MD5 0fbac43a0ce1f4322cb5647e1aa9f9fe
BLAKE2b-256 2e6d68593e29aadfb0038e06e524cf7f3a6df3206bbd4e75750099b2c182624b

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