Registry / web-framework / fastapi-users

fastapi-users

JSON →
library15.0.5pypypi✓ verified 24d ago

FastAPI Users provides ready-to-use and customizable user management for FastAPI applications, including authentication, registration, password reset, and OAuth. It reached maintenance mode with version 15.0.0, meaning it will continue to receive security updates and dependency maintenance but no new features. The current version is 15.0.5.

pip install fastapi-users[sqlalchemy]
INSTALL
IMPORT
SIG · FASTAPI-USERS
F
fastapi-users
web-frameworkpythonv15.0.5
Install
6.1s avg
Import
2193ms
Disk
78MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v15.0.5 · 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.103.915 runs
installs and imports cleanly · install 0.0s · import 2.266s · 78.9MB
glibc
py 3.103.915 runs
installs and imports cleanly · install 6.1s · import 2.120s · 76MB
78MB installed
● package 78MB
Code
Verified usage

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

FastAPIUsers
from fastapi_users import FastAPIUsers
SQLAlchemyUserDatabase
from fastapi_users_db_sqlalchemy import SQLAlchemyUserDatabase
BearerBackend
from fastapi_users.authentication import BearerBackend
CookieBackend
from fastapi_users.authentication import CookieBackend
AuthenticationBackend
from fastapi_users.authentication import AuthenticationBackend
UUIDIDStrategy
from fastapi_users.authentication import JWTStrategy, Strategy, UUIDIDStrategy

This quickstart sets up a basic FastAPI application with user registration, login (using JWT stored in a cookie), and user management endpoints. It uses an in-memory SQLite database with SQLAlchemy for simplicity. Remember to replace the `SECRET` with a strong, environment-variable-managed secret in production.

import uuid from typing import AsyncGenerator from fastapi import Depends, FastAPI from fastapi_users import FastAPIUsers, schemas from fastapi_users.authentication import JWTStrategy, AuthenticationBackend, CookieBackend from fastapi_users_db_sqlalchemy import SQLAlchemyUserDatabase, UUID_ID, SQLAlchemyBaseUserTableUUID from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine from sqlalchemy.orm import sessionmaker, DeclarativeBase DATABASE_URL = "sqlite+aiosqlite:///./test.db" SECRET = "" # For JWT and Cookie backend, replace with os.environ.get('SECRET', '') class Base(DeclarativeBase): pass class User(SQLAlchemyBaseUserTableUUID, Base): pass async def get_async_session() -> AsyncGenerator[AsyncSession, None]: async_engine = create_async_engine(DATABASE_URL) async_session_maker = sessionmaker(async_engine, class_=AsyncSession, expire_on_commit=False) async with async_session_maker() as session: yield session async def create_db_and_tables(): async_engine = create_async_engine(DATABASE_URL) async with async_engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) async def get_user_db(session: AsyncSession = Depends(get_async_session)): yield SQLAlchemyUserDatabase(session, User) def get_jwt_strategy() -> JWTStrategy[User, UUID_ID]: return JWTStrategy(secret=SECRET, lifetime_seconds=3600) auth_backend = AuthenticationBackend( name="jwt", transport=CookieBackend(name="b", lifetime_seconds=3600, secret=SECRET), get_strategy=get_jwt_strategy, ) fastapi_users = FastAPIUsers[User, UUID_ID]( get_user_db, [auth_backend], ) app = FastAPI() @app.on_event("startup") async def on_startup(): await create_db_and_tables() app.include_router( fastapi_users.get_auth_router(auth_backend), prefix="/auth/jwt", tags=["auth"], ) app.include_router( fastapi_users.get_register_router(), prefix="/auth", tags=["auth"], ) app.include_router( fastapi_users.get_users_router(), prefix="/users", tags=["users"], )
Debug
Known issues
gotchaFastAPI Users entered maintenance mode starting with v15.0.0. While security updates and dependency maintenance will continue, no new features are planned. Consider this for long-term project planning.
fix
Be aware of the project's status and ensure existing features meet your requirements before adoption.
affects: >=15.0.0
breakingPython 3.9 and Pydantic v1 support was dropped in v15.0.0. Applications targeting these versions must either upgrade their Python/Pydantic or remain on FastAPI Users v14.x.
fix
Upgrade your project's Python version to 3.10+ and Pydantic to v2+ or pin `fastapi-users` to `<15.0.0`.
affects: >=15.0.0
breakingA CSRF vulnerability fix in v15.0.2 introduced a cookie requirement for OAuth2 flows. This might require additional configuration for cross-domain setups or if the client isn't sending cookies correctly.
fix
Review your OAuth2 setup, especially for cross-domain usage. The cookie parameters for `get_oauth_router` were updated in 15.0.3 to help.
affects: >=15.0.2
breakingThe underlying password hashing library changed from `passlib` to `pwdlib` in v13.0.0. This is a breaking change only if you were using a custom `CryptContext` configuration.
fix
If you used a custom `CryptContext`, you'll need to adapt it to `pwdlib`. Otherwise, existing passwords will still be verified correctly.
affects: >=13.0.0
gotchaThe `fastapi-users` core package only provides the framework. You MUST install a specific database backend (e.g., `fastapi-users[sqlalchemy]`, `fastapi-users[mongodb]`) for persistence.
fix
Always install `fastapi-users` with the appropriate backend extra: `pip install fastapi-users[your_backend_name]`.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'SQLAlchemyBaseUserTableUUID' from 'fastapi_users.db'
This error occurs when the optional SQLAlchemy dependency is not installed.
fix
Install the package with SQLAlchemy support using: pip install 'fastapi-users[sqlalchemy]'
ModuleNotFoundError: No module named 'pkg_resources'
This error occurs when using Python 3.12, as 'pkg_resources' is deprecated and removed.
fix
Downgrade to Python 3.11 or wait for an update that supports Python 3.12.
ImportError: cannot import name 'models' from 'fastapi_users'
This error occurs when there's a circular import, often due to naming a script 'fastapi_users.py'.
fix
Rename your script to avoid conflicts with the 'fastapi_users' module.
ModuleNotFoundError: No module named 'fastapi_users'
This error typically occurs when the `fastapi-users` library, or one of its required database integration packages, has not been installed in your Python environment or the virtual environment is not activated. It can also happen if specific database extras (like `[sqlalchemy]` or `[mongodb]`) were not included during installation.
fix
Ensure you have installed `fastapi-users` with the necessary database integration. For SQLAlchemy, use: `pip install "fastapi-users[sqlalchemy]"`. For other databases, replace `sqlalchemy` with the appropriate extra, e.g., `[mongodb]` or `[tortoise-orm]`.
AttributeError: 'User' object has no attribute 'is_active'
This error means that your custom `User` model, which is used by `fastapi-users`, is missing the `is_active` attribute. The `BaseUser` (or `SQLAlchemyBaseUser`, etc.) classes provided by `fastapi-users` expect certain attributes like `is_active`, `is_superuser`, and `is_verified` to be present on your user model.
fix
Update your custom `User` model to inherit from the correct base user class provided by `fastapi-users` (e.g., `fastapi_users.db.sqlalchemy.SQLAlchemyBaseUser`) and ensure it includes the `is_active`, `is_superuser`, and `is_verified` boolean fields, as well as `email` and `hashed_password`.
Upgrade
Version history
15.0.5latest on PyPI · released Mar 27, 2026
Audit
Dependencies
sqlalchemyoptionalRequired for SQLAlchemy-based user database backend.
mongodboptionalRequired for MongoDB-based user database backend.
tortoise-ormoptionalRequired for Tortoise ORM-based user database backend.
redisoptionalOptional, for advanced features like session storage or OTP via Redis.
pyjwt[crypto]requiredRequired for JWT token handling.
pwdlibrequiredPassword hashing library (replaces passlib as of v13).
Agent activity
42 hits · last 30 days
node
36
OpenAI (training)
1
Resources