FastAPI-Simple-Auth
Simple authentication for FastAPI
Install in two commands, add authentication in three lines, configure to taste.
Links
- FastAPI-Simple-Auth git repository
- FastAPI-Simple-Auth documentation
- Basic theme for FastAPI-Simple-Auth
- Dark theme for FastAPI-Simple-Auth
Features
- Users are stored in any supported SQLAlchemy database (sqlite3, mysql, ...)
- Optional email verification
- User creation
- Password recovery
- Flexible password strength requirements
- Profile page with change password, change email
- Easy to configure via environment / .env
- Custom UI themes!
Installation
pip3 install fastapi-simple-auth
Optionally, configure .env file. Lets set just one very simple config option:
APP_TITLE="My app!"
Initialize database (sqlite3 by default) with command: simpleauth dbupgrade
Example protected app
You should add just three lines to basic "hello world" type of fastapi app.
- Import package
- hook to app with
SimpleAuth(app) - add
user: logged_in_userto protected view
from fastapi import FastAPI
from fastapi_simple_auth import SimpleAuth, logged_in_user
app = FastAPI()
simpleauth = SimpleAuth(app)
@app.get("/")
async def read_users_me(user: logged_in_user) -> str:
return f"Hello {user.username} {user.uuid}"
Now run it.
uvicorn app:app
Open https://localhost:8000/ you will see

Next, you may configure authentication settings for your application.