{"id":4532,"library":"fastapi-utils","title":"FastAPI Utils","description":"FastAPI Utils is a Python library providing reusable utilities for FastAPI applications, including class-based views, repeated tasks, timing middleware, and SQLAlchemy session management. It is currently at version 0.8.0 and releases seem to be quarterly or bi-annually based on recent GitHub activity.","status":"active","version":"0.8.0","language":"en","source_language":"en","source_url":"https://github.com/dmontagu/fastapi-utils","tags":["fastapi","utilities","class-based views","background tasks","scheduling","middleware","sqlalchemy","api development"],"install":[{"cmd":"pip install fastapi-utils","lang":"bash","label":"Basic Install"},{"cmd":"pip install fastapi-utils[session]","lang":"bash","label":"With SQLAlchemy Session Maker"}],"dependencies":[{"reason":"Core framework the utilities extend.","package":"fastapi"},{"reason":"Used for data validation and settings, required by FastAPI.","package":"pydantic","optional":false},{"reason":"Required for `FastAPISessionMaker` functionality.","package":"sqlalchemy","optional":true}],"imports":[{"symbol":"cbv","correct":"from fastapi_utils.cbv import cbv"},{"note":"InferringRouter was deprecated in v0.4.4 as its functionality was integrated into FastAPI's native APIRouter.","wrong":"from fastapi_utils.inferring_router import InferringRouter","symbol":"InferringRouter","correct":"from fastapi.routing import APIRouter"},{"symbol":"repeat_every","correct":"from fastapi_utils.tasks import repeat_every"},{"symbol":"FastAPISessionMaker","correct":"from fastapi_utils.session import FastAPISessionMaker"},{"symbol":"APIModel","correct":"from fastapi_utils.api_model import APIModel"},{"symbol":"APISettings","correct":"from fastapi_utils.settings import APISettings"},{"symbol":"StrEnum","correct":"from fastapi_utils.enums import StrEnum"},{"symbol":"CamelStrEnum","correct":"from fastapi_utils.enums import CamelStrEnum"},{"symbol":"GUID","correct":"from fastapi_utils.guid_type import GUID"}],"quickstart":{"code":"from fastapi import FastAPI, Depends, APIRouter\nfrom fastapi_utils.cbv import cbv\nfrom fastapi_utils.inferring_router import InferringRouter # Still commonly seen, but prefer APIRouter\n\napp = FastAPI()\nrouter = InferringRouter() # Or APIRouter() for newer FastAPI versions\n\ndef common_dependency():\n    return \"Shared Data\"\n\n@cbv(router)\nclass ClassBasedView:\n    # Dependencies shared by all methods in this class\n    shared_data: str = Depends(common_dependency)\n\n    @router.get(\"/items/\")\n    def read_items(self):\n        return {\"message\": f\"Hello from CBV, shared data: {self.shared_data}\"}\n\n    @router.post(\"/items/\")\n    def create_item(self, item_name: str):\n        return {\"message\": f\"Item '{item_name}' created with shared data: {self.shared_data}\"}\n\napp.include_router(router)\n\n# To run: uvicorn main:app --reload (assuming this code is in main.py)","lang":"python","description":"This quickstart demonstrates the use of Class-Based Views (CBV) to group related endpoints and share dependencies, a core feature of fastapi-utils. Methods within the `@cbv` decorated class become endpoints on the included router, and class-level `Depends` declarations are injected as instance attributes."},"warnings":[{"fix":"Replace `from fastapi_utils.inferring_router import InferringRouter` with `from fastapi import APIRouter` and use it directly.","message":"The `InferringRouter` class was deprecated in `fastapi-utils` v0.4.4. Its core functionality for inferring response models is now a built-in feature of `fastapi.APIRouter` in recent FastAPI versions.","severity":"deprecated","affected_versions":">=0.4.4"},{"fix":"Structure your CBV classes to group endpoints with genuinely shared dependencies, or move non-universally required dependencies to the method signature of specific endpoints.","message":"When using `@cbv` (Class-Based Views), any dependencies defined as class attributes will be resolved and injected for *every* endpoint method within that class, even if a specific method doesn't explicitly use `self.dependency_name`. This can lead to unnecessary work if dependencies are expensive and not universally required.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Adapt your application to use `asynccontextmanager` for lifespan events and call your `repeat_every` decorated functions within the `startup` block of the lifespan context. Refer to FastAPI's official documentation on lifespan events.","message":"For `repeat_every` background tasks, if you're using a modern FastAPI version (0.68.0+), `app.on_event(\"startup\")` is deprecated in favor of `asynccontextmanager` for managing application lifespan.","severity":"gotcha","affected_versions":"FastAPI >=0.68.0"},{"fix":"Upgrade your Python environment to 3.8 or newer. The current version (0.8.0) requires Python >=3.8.","message":"fastapi-utils v0.4.0 introduced a breaking change by removing support for Python versions < 3.6.2. Ensure your project runs on Python 3.8+ as per current requirements.","severity":"breaking","affected_versions":"<0.4.0"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}