Registry / web-framework / fastapi-decorators

fastapi-decorators

JSON →
library1.0.20pypypi✓ verified 91d ago

A utility library for FastAPI that lets you create decorators for endpoints using FastAPI's dependency injection. It provides a @depends decorator that wraps dependencies and preserves type hints, making it easy to reuse common preprocessing logic. Current version: 1.0.20. Released intermittently, with bugfix and compatibility improvements.

pip install fastapi-decorators
INSTALL
IMPORT
SIG · FASTAPI-DECORATORS
F
fastapi-decorators
web-frameworkpythonv1.0.20
Install
3.8s avg
Import
1292ms
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.0.20 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 1.346s · 31.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.8s · import 1.238s · 32MB
30MB installed
● package 30MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

depends
✓ from fastapi_decorators import depends
✗ from fastapi_decorators import Depends
The exported symbol is lowercase 'depends' (the class is Depends internally but not intended for direct import).

Create a reusable dependency decorator that extracts a token, then apply it to an endpoint. The dependency is injected as a parameter.

from fastapi import FastAPI, Depends, HTTPException from fastapi_decorators import depends app = FastAPI() def verify_token(authorization: str = Depends(oauth2_scheme)): if authorization != "valid_token": raise HTTPException(status_code=401) return authorization @app.get("/secure") @depends(verify_token) async def secure_endpoint(token: str = Depends(verify_token)): return {"token": token}
Debug
Known issues
gotchaThe @depends decorator modifies the function signature. If your endpoint has additional dependencies, ensure they are ordered correctly. The wrapped dependency becomes a parameter in the endpoint's signature.
fix
Always include the dependency as a parameter in the endpoint function with Depends() if you need to access its return value; otherwise, the return value is lost.
affects: >=1.0.0
gotchaIn versions before 1.0.20, explicit `-> None` return annotations on the dependency function were not preserved in the wrapped endpoint's signature. This could break type checkers expecting `None` returns.
fix
Upgrade to 1.0.20 or later, or omit explicit `-> None` from dependency functions.
affects: <1.0.20
gotchaForwardRef (string-based) annotations in dependency functions may fail to resolve in versions <1.0.16. This causes a runtime error when FastAPI tries to build the endpoint's OpenAPI schema.
fix
Upgrade to 1.0.16 or later, or avoid forward reference annotations in dependency functions.
affects: <1.0.16
Errors
Common errors & fixes
ImportError: cannot import name 'depends' from 'fastapi_decorators'
Older versions of the library had different export names; also possible typo in import path.
fix
Ensure you have fastapi-decorators >=1.0.0 installed. Use `from fastapi_decorators import depends`.
TypeError: 'Depends' object is not callable
Attempting to use `Depends` (uppercase) from fastapi_decorators instead of the correct lowercase `depends`.
fix
Use `from fastapi_decorators import depends` and apply it as a decorator: `@depends(some_dependency)`.
fastapi.exceptions.FastAPIError: Invalid args for response field...
ForwardRef (string annotation) in the dependency function that was not resolved due to version <1.0.16.
fix
Upgrade to fastapi-decorators >=1.0.16. If that's not possible, replace string annotations with actual type references.
Upgrade
Version history
1.0.20latest on PyPI · released Mar 30, 2026
Audit
Dependencies
fastapirequiredCore dependency; the library is designed to work with FastAPI endpoints.
Agent activity
16 hits · last 30 days
node
14
Amazon
1
Resources
fastapi-decorators — pip install fastapi-decorators · libregistry