--- id: fastapi-decorators version: "1.0.20" 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) license_treatment: permissive maintenance: active --- # fastapi-decorators — Create decorators for your endpoints using FastAPI dependencies. License: permissive · Maintenance: active · Downloads: 148.7K/mo ## 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 above — 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 pip install fastapi-decorators uv add fastapi-decorators 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_current - Install friction: low - Maintenance: active - Downloads: 148.7K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags fastapi decorator with dependencies, fastapi depends decorator, reusable fastapi endpoint decorators, fastapi dependency injection decorators, fastapi decorator factory, fastapi middleware-like decorators, fastapi-extension, decorator-pattern, dependency-injection [View on SkillFed](https://skillfed.io/packages/fastapi-decorators) · [View on PyPI](https://pypi.org/project/fastapi-decorators/)