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.5.tar.gz (33.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.5-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastapi_di_chain-0.0.5.tar.gz
Algorithm Hash digest
SHA256 1e8c153d956a71255dd2971c8682a5b11845afef7092fcb8288259d23e56b096
MD5 5cde6cd0330fc76f3b7301c89b042971
BLAKE2b-256 938b866ae652dd1abc0b8403ed8b867f47f318b952ec22fdb8783e8fe7b41c73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_di_chain-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 825745bf6497c9d02adb238a9eea81335272421e47ca6b9a5d215eda2562e843
MD5 7c78a21778b4b8c863529198576f6e4a
BLAKE2b-256 0c65f80a761c3429b05ca11870db24d8db027be92cbadba80a18e2f520245ca7

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