{"id":23710,"library":"fastapi-decorators","title":"fastapi-decorators","description":"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.","status":"active","version":"1.0.20","language":"python","source_language":"en","source_url":"https://github.com/Minibrams/fastapi-decorators","tags":["fastapi","decorators","dependency-injection","utilities"],"install":[{"cmd":"pip install fastapi-decorators","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core dependency; the library is designed to work with FastAPI endpoints.","package":"fastapi","optional":false}],"imports":[{"note":"The exported symbol is lowercase 'depends' (the class is Depends internally but not intended for direct import).","wrong":"from fastapi_decorators import Depends","symbol":"depends","correct":"from fastapi_decorators import depends"}],"quickstart":{"code":"from fastapi import FastAPI, Depends, HTTPException\nfrom fastapi_decorators import depends\n\napp = FastAPI()\n\ndef verify_token(authorization: str = Depends(oauth2_scheme)):\n    if authorization != \"valid_token\":\n        raise HTTPException(status_code=401)\n    return authorization\n\n@app.get(\"/secure\")\n@depends(verify_token)\nasync def secure_endpoint(token: str = Depends(verify_token)):\n    return {\"token\": token}","lang":"python","description":"Create a reusable dependency decorator that extracts a token, then apply it to an endpoint. The dependency is injected as a parameter."},"warnings":[{"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.","message":"The @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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to 1.0.20 or later, or omit explicit `-> None` from dependency functions.","message":"In 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.","severity":"gotcha","affected_versions":"<1.0.20"},{"fix":"Upgrade to 1.0.16 or later, or avoid forward reference annotations in dependency functions.","message":"ForwardRef (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.","severity":"gotcha","affected_versions":"<1.0.16"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure you have fastapi-decorators >=1.0.0 installed. Use `from fastapi_decorators import depends`.","cause":"Older versions of the library had different export names; also possible typo in import path.","error":"ImportError: cannot import name 'depends' from 'fastapi_decorators'"},{"fix":"Use `from fastapi_decorators import depends` and apply it as a decorator: `@depends(some_dependency)`.","cause":"Attempting to use `Depends` (uppercase) from fastapi_decorators instead of the correct lowercase `depends`.","error":"TypeError: 'Depends' object is not callable"},{"fix":"Upgrade to fastapi-decorators >=1.0.16. If that's not possible, replace string annotations with actual type references.","cause":"ForwardRef (string annotation) in the dependency function that was not resolved due to version <1.0.16.","error":"fastapi.exceptions.FastAPIError: Invalid args for response field..."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}