{"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":"python","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":[{"wrong":"from fastapi_utils.cbv import cbv","symbol":"cbv","correct":"from fastapi_utils.cbv import cbv"}],"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,"search_vec":"'0.8.0':33 'activ':48 'annual':43 'api':60 'applic':14 'background':55 'base':18,44,53 'bi':42 'bi-annu':41 'class':17,52 'class-bas':16,51 'current':30 'develop':61 'fastapi':1,3,13,49 'github':47 'includ':15 'librari':8 'manag':27 'middlewar':23,58 'provid':9 'python':7 'quarter':39 'recent':46 'releas':35 'repeat':20 'reusabl':10 'schedul':57 'seem':36 'session':26 'sqlalchemi':25,59 'task':21,56 'time':22 'util':2,4,11,50 'version':32 'view':19,54","created_at":"2026-04-12T13:56:40.915274+00:00","updated_at":"2026-04-15T17:38:55.619671+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmpifvltm7z/venv/lib/python3.12/site-packages/fastapi_utils/__init__.py\", line 4, in <module>\n    from .cbv_base import Api, Resource, set_responses, take_init_parameters\n  File \"/tmp/tmpifvltm7z/venv/lib/python3."},"ecosystem":"pypi","meta_description":"fastapi-utils — utilities for FastAPI · pip install fastapi-utils · from fastapi_utils.api_model import APIModel · from fastapi_utils.cbv import cbv · APIModel is Pydantic BaseModel with camelCase","install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.8.0","cli_name":"","cli_version":null,"type":"library","homepage":"https://fastapiutils.github.io/fastapi-utils/","github":"https://github.com/dmontagu/fastapi-utils","docs":"https://fastapiutils.github.io/fastapi-utils/","changelog":null,"pypi":"https://pypi.org/project/fastapi-utils/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["web-framework","database","observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-08-30","next_check":"2026-07-10","install_tag":null}}