fastapi-decorators
Create decorators for your endpoints using FastAPI dependencies.
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-decoratorsuv
uv add fastapi-decoratorspoetry
poetry add fastapi-decoratorsInstalling 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
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
fast-dependsFastDepends provides a standalone dependency…
permissive · top 5,000 on PyPI
fastapi-injectableEnables FastAPI's Depends() dependency…
permissive · top 15,000 on PyPI
fastapi-versioningAdds API versioning to FastAPI applications by…
permissive · top 15,000 on PyPI
fastapi-cache2Caches FastAPI endpoint and function results…
permissive · top 5,000 on PyPI
decoratorProvides utilities for writing function…
permissive · top 1,000 on PyPI
fastapi-limiterAdds request rate limiting to FastAPI routes…
permissive · top 5,000 on PyPI
uncalled-forProvides async dependency injection for Python…
permissive · top 1,000 on PyPI
essentialsEssentials provides reusable core classes and…
permissive · top 15,000 on PyPI
slowapiAdds rate limiting to Starlette and FastAPI…
permissive · top 1,000 on PyPI
fan-toolsA collection of internal testing utilities,…
permissive · top 15,000 on PyPI