skillfed

fastapi-decorators

Create decorators for your endpoints using FastAPI dependencies.

fastapi-decorators v1.0.20 148.7K downloads/30d#11,023 on PyPI83
Permissive license MIT License Copyright (c) 2024 Anders Brams Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal… (full text in the JSON record) Active released

What it is and what it does

fastapi-decorators provides a @depends decorator that wraps FastAPI's Depends() mechanism, letting you build reusable decorators that inject dependencies into endpoints without repeating dependency resolution logic. Instead of manually threading FastAPI dependencies through custom decorators, you annotate a function with @depends and use it directly as a decorator on your route handlers.

The package supports three main patterns: simple decorators that run side effects (logging, auditing), decorator factories that accept parameters (rate limiting, authorization scopes), and wrapper decorators that intercept endpoint execution while still accessing injected dependencies (caching, error handling). It integrates directly with FastAPI's dependency system, so decorated endpoints appear correctly in auto-generated API documentation.

Use it for:

  • Build an authentication decorator that checks OAuth2 tokens and raises 401/403 errors without duplicating token resolution logic across routes.
  • Create a rate-limiting decorator factory that accepts max_calls and period parameters and applies them to individual endpoints.
  • Implement a caching decorator that wraps expensive operations and uses a Depends()-injected cache backend to store and retrieve results.
  • Add request logging or audit trails by decorating endpoints to capture request metadata and write to a database via injected Session.
  • Enforce custom response headers or modify responses by decorating endpoints with a decorator that receives the Response object via Depends().

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts functions into FastAPI-compatible decorators that can inject and resolve FastAPI dependencies, eliminating boilerplate when building reusable endpoint decorators.

Yes. The package solves a genuine friction point in FastAPI: building reusable decorators that need access to dependencies. It has no security vulnerabilities, low install friction, permissive licensing, and active maintenance. Use it when you find yourself writing the same dependency-aware decorator logic across multiple endpoints.

Install

fastapi-decorators on PyPI

pip

pip install fastapi-decorators

uv

uv add fastapi-decorators

poetry

poetry add fastapi-decorators

Installing fastapi-decorators

Before you install

Low friction: pure Python wheel with a single runtime dependency on fastapi. Actively maintained with recent commits and a stable beta status.

License in practice

MIT license permits unrestricted use, modification, and distribution with minimal restrictions—suitable for both open-source and commercial projects.

Quickstart

from fastapi import FastAPI, Depends, HTTPException
from fastapi_decorators import depends

@depends
def require_auth(token: str = Depends(lambda: "token")):
    if not token:
        raise HTTPException(status_code=401)

app = FastAPI()

@app.get("/items")
@require_auth
def get_items():
    return {"items": []}

Verify before relying

  • Whether the package handles async endpoint functions and async dependencies correctly in all decorator patterns.
  • Performance overhead of the @depends decorator wrapper compared to direct FastAPI Depends() usage at scale.

Package facts

License MIT License Copyright (c) 2024 Anders Brams Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies 1 — fastapi
Maintenance actively maintained — 137 days since the last release
Last repo commit
First released
Downloads 148,668/month — #11,023 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: fastapi_decorators-1.0.20-py3-none-any.whl

Keywords: decorators, dependencies, dependency, fastapi, middleware

Development Status :: 4 - BetaEnvironment :: Web EnvironmentFramework :: FastAPIIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: InternetTopic :: Internet :: WWW/HTTPTopic :: Internet :: WWW/HTTP :: HTTP ServersTopic :: Software DevelopmentTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Application FrameworksTopic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

fastapi decorator with dependenciesfastapi depends decoratorreusable fastapi endpoint decoratorsfastapi dependency injection decoratorsfastapi decorator factoryfastapi middleware-like decorators
fastapi-extensiondecorator-patterndependency-injection

More Software Development packages