Registry / web-framework / fastapi-utils

fastapi-utils

JSON →
library0.8.0pypypi✓ verified 26d ago

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.

pip install fastapi-utils
INSTALL
IMPORT
SIG · FASTAPI-UTILS
F
fastapi-utils
web-frameworkpythonv0.8.0
Install
5.0s avg
Import
—
Disk
56MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.8.0 · 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.910 runs
build_error
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 5.0s · import 0.000s · 56MB
56MB installed
● package 56MB
Code
Verified usage

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

cbv
✓ from fastapi_utils.cbv import cbv
✗ from fastapi_utils.cbv import cbv

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.

from fastapi import FastAPI, Depends, APIRouter from fastapi_utils.cbv import cbv from fastapi_utils.inferring_router import InferringRouter # Still commonly seen, but prefer APIRouter app = FastAPI() router = InferringRouter() # Or APIRouter() for newer FastAPI versions def common_dependency(): return "Shared Data" @cbv(router) class ClassBasedView: # Dependencies shared by all methods in this class shared_data: str = Depends(common_dependency) @router.get("/items/") def read_items(self): return {"message": f"Hello from CBV, shared data: {self.shared_data}"} @router.post("/items/") def create_item(self, item_name: str): return {"message": f"Item '{item_name}' created with shared data: {self.shared_data}"} app.include_router(router) # To run: uvicorn main:app --reload (assuming this code is in main.py)
Debug
Known issues
deprecatedThe `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.
fix
Replace `from fastapi_utils.inferring_router import InferringRouter` with `from fastapi import APIRouter` and use it directly.
affects: >=0.4.4
gotchaWhen 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.
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.
affects: All versions
gotchaFor `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.
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.
affects: FastAPI >=0.68.0
breakingfastapi-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.
fix
Upgrade your Python environment to 3.8 or newer. The current version (0.8.0) requires Python >=3.8.
affects: <0.4.0
Install Issues
1 verified issue
ImportError: cannot import name 'apimodel' from 'fastapi_utils.api_model'All platforms · Python 3.8 · 3.9 · 3.10 · 3.11 →
Upgrade
Version history
0.8.0latest on PyPI · released Nov 11, 2024
Audit
Dependencies
fastapirequiredCore framework the utilities extend.
pydanticrequiredUsed for data validation and settings, required by FastAPI.
sqlalchemyoptionalRequired for `FastAPISessionMaker` functionality.
Agent activity
36 hits · last 30 days
node
31
OpenAI (training)
2
Resources
fastapi-utils — pip install fastapi-utils · libregistry