skillfed

fastapi-utilities

Reusable utilities for FastAPI

fastapi-utilities v0.3.1 140.4K downloads/30d#11,272 on PyPI
Permissive license MIT AGING released

What it is and what it does

fastapi-utilities is a collection of helper functions and decorators for FastAPI applications. It reduces boilerplate by providing task scheduling (via repeat_every and repeat_at decorators), a TTL-aware LRU cache decorator, middleware for logging request timing, and a session manager that wraps SQLAlchemy. The package also includes a CLI tool to scaffold new FastAPI projects.

The package depends on click-spinner, croniter, fastapi, pydantic, and sqlalchemy. It is classified as Alpha and has not been actively maintained for over a year, so some features may not align with the latest FastAPI API changes—the description includes guidance on adapting to newer lifespan patterns. It is suitable for developers seeking quick utilities to avoid writing common patterns, but should be evaluated against current FastAPI best practices before adoption in production.

Use it for:

  • Schedule periodic background tasks (e.g., cleanup, health checks) using @repeat_every or @repeat_at cron decorators within FastAPI startup.
  • Add automatic request timing and performance logging to all endpoints via add_timer_middleware.
  • Cache expensive function results with automatic expiration using @ttl_lru_cache with configurable TTL and size limits.
  • Manage database sessions across requests using FastAPISessionMaker context manager instead of manual get_db patterns.
  • Generate a FastAPI project skeleton quickly using the CLI tool to avoid manual boilerplate setup.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides reusable utilities for FastAPI applications including scheduled task decorators, TTL-based LRU caching, request timing middleware, session management, and a CLI tool for project scaffolding.

Yes, with conditions. The package offers genuine utility for FastAPI developers seeking to reduce boilerplate—particularly task scheduling and caching—and carries no security vulnerabilities. However, the aging maintenance status (507 days since last release) and Alpha classification mean you should verify that features work with your FastAPI version and be prepared to adapt or fork if compatibility issues arise. Best suited for projects where you can tolerate limited upstream support or are willing to maintain patches yourself.

Install

fastapi-utilities on PyPI

pip

pip install fastapi-utilities

uv

uv add fastapi-utilities

poetry

poetry add fastapi-utilities

Installing fastapi-utilities

Before you install

Low friction installation with a pure-Python wheel. Maintenance status is aging—last release was 507 days ago—so expect limited active development and potential compatibility gaps with newer FastAPI versions, though the description notes workarounds for recent FastAPI lifespan changes.

License in practice

MIT license is permissive, allowing use in commercial and private projects with minimal restrictions; attribution is required but no copyleft obligations apply.

Quickstart

pip install fastapi-utilities

from fastapi import FastAPI
from contextlib import asynccontextmanager
from fastapi_utilities import repeat_every

@asynccontextmanager
async def lifespan(app: FastAPI):
    yield

app = FastAPI(lifespan=lifespan)

@repeat_every(seconds=2)
async def scheduled_task():
    print("task")

Requires Python 3.7+; latest FastAPI versions require using asynccontextmanager lifespan pattern instead of deprecated on_event decorator.

Verify before relying

  • Whether repeat_every and repeat_at work reliably with current FastAPI versions beyond the documented workaround.
  • Performance characteristics of ttl_lru_cache under high concurrency or with large datasets.
  • Whether the CLI tool generates projects compatible with modern FastAPI and dependency versions.

Package facts

License MIT (permissive)
Python support supports the current Python release (<4.0,>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies 5 — click-spinner, croniter, fastapi, pydantic, sqlalchemy
Maintenance aging — 507 days since the last release
First released
Downloads 140,447/month — #11,272 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: fastapi_utilities-0.3.1-py3-none-any.whl

Keywords: fastapi, utilities, utils, fastapi-utilities, python, library, framework, web, api

Development Status :: 3 - AlphaFramework :: AsyncIOFramework :: FastAPIIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Internet :: WWW/HTTP :: HTTP ServersTopic :: Internet :: WWW/HTTP :: WSGI :: ApplicationTopic :: Internet :: WWW/HTTP :: WSGI :: ServerTopic :: Software Development :: Libraries :: Python ModulesTopic :: Utilities

Tags

fastapi scheduling decoratorsfastapi cron jobsfastapi middleware utilitiesfastapi session managementfastapi caching ttl lrufastapi boilerplate toolsfastapi repeated tasks
fastapi-addontask-schedulingcaching

More Python Modules packages