/////// Personal Notes: Fast API Users is a Python library that provides ready-to-use user authentication and management functionality for FastAPI applications. Think of it as a toolkit that handles all the common user related features you'd typically need to build yourself.
What it does: The library gives you pre-built solutions for standard authentication features like user registration, login/logout, password reset, and email verification. It also supports social login through OAuth2 (like "Sign in with Google" or "Sign in with GitHub").
Key Features: Multiple authentication methods (JWT tokens, session cookies, or database-based auth) Flexible database support (works with SQLAlchemy for SQL databases or MongoDB) Built-in security features like password validation Easy integration with FastAPI's dependency injection system Full OpenAPI/Swagger documentation support
Authentication Routes It automatically creates API endpoints for you, such as:
POST /auth/register - Create new user accounts POST /auth/login - Log users in and get an authentication token POST /auth/logout - End user sessions POST /auth/forgot-password - Request password reset POST /auth/reset-password - Actually reset the password POST /auth/verify - Confirm email addresses
Authentication Strategies You can choose how users prove their identity:
JWT (JSON Web Tokens): Stateless tokens that contain user information, commonly used for APIs and mobile apps Cookie-based: Traditional web session authentication using browser cookies Database tokens: Tokens stored in your database for more control Redis: Fast, in-memory token storage for high-performance needs
Authentication Strategies You can choose how users prove their identity:
JWT (JSON Web Tokens): Stateless tokens that contain user information, commonly used for APIs and mobile apps Cookie-based: Traditional web session authentication using browser cookies Database tokens: Tokens stored in your database for more control Redis: Fast, in-memory token storage for high-performance needs
Database Flexibility It works with different database systems through "adapters":
SQLAlchemy: For traditional SQL databases like PostgreSQL, MySQL, or SQLite Beanie: For MongoDB (a NoSQL database)
OAuth2 / Social Login The library also supports "Sign in with Google/GitHub/Facebook" type flows. It handles the complex OAuth2 protocol for you, including redirecting users to the provider, receiving the authentication callback, and creating or linking user accounts.
Security Built-In Important security features are handled automatically:
Passwords are properly hashed (never stored in plain text) Tokens can have expiration times Email verification to prevent fake signups Password strength validation (you can customize the rules)
Instead of spending time writing all the authentication code from scratchโhandling password hashing, token generation, user verification emails, etc.โyou can use this library to get a complete, secure user management system up and running quickly in your FastAPI project.
Ready-to-use and customizable users management for FastAPI
Note
This project is now in maintenance mode. While we'll continue to provide security updates and dependency maintenance, no new features will be added. We encourage you to explore the project and use it as-is, knowing it will remain stable and secure.
We're currently working on a new Python authentication toolkit that will ultimately supersede FastAPI Users. Stay tuned for updates!
Documentation: https://fastapi-users.github.io/fastapi-users/
Source Code: https://github.com/fastapi-users/fastapi-users
Add quickly a registration and authentication system to your FastAPI project. FastAPI Users is designed to be as customizable and adaptable as possible.
- Extensible base user model
- Ready-to-use register, login, reset password and verify e-mail routes
- Ready-to-use social OAuth2 login flow
- Dependency callables to inject current user in route
- Pluggable password validation
- Customizable database backend
- SQLAlchemy ORM async included
- MongoDB with Beanie ODM included
- Multiple customizable authentication backends
- Transports: Authorization header, Cookie
- Strategies: JWT, Database, Redis
- Full OpenAPI schema support, even with several authentication backends
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
We use Hatch to manage the development environment and production build. Ensure it's installed on your system.
You can run all the tests with:
hatch run testExecute the following command to apply linting and check typing:
hatch run lintYou can serve the documentation locally with the following command:
hatch run docsThe documentation will be available on http://localhost:8000.
This project is licensed under the terms of the MIT license.