FastAPI simple authentication
Project description
FastAPI Simple Auth
- Such a long name! It's hard to type it out.
- Yes, but everything else in this project is simple.
Authentication easy as three lines!
- Import package
- hook to app with
SimpleAuth(app)
- add
user: logged_in_user
to 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}"
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!
Documentation
https://fastapi-simple-auth.readthedocs.io/
Install
pip3 install fastapi-simple-auth
# create/edit .env file
vim .env
simpleauth dbupgrade
Write app in app.py
Start:
uvicorn app:app
Usage
This examples uses httpie because it is very good to craft JSON requests.
# register
http POST http://localhost:8000/auth/users/ username=me@example.com password=secret
# simple auth (session)
http -f POST http://localhost:8000/auth/login username=me@example.com password=secret
# get token
http -f POST http://localhost:8000/auth/token username=me@example.com password=secret
Developer cheatsheet
Alembic cheatsheet
alembic revision --autogenerate -m "some desc"
alembic upgrade head
alembic current
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_simple_auth-0.0.9.tar.gz
(66.0 kB
view details)
Built Distribution
File details
Details for the file fastapi_simple_auth-0.0.9.tar.gz
.
File metadata
- Download URL: fastapi_simple_auth-0.0.9.tar.gz
- Upload date:
- Size: 66.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5efa819a793db4f7c3c30964c5453564b76fc7ae4ffb78cc9af6aee25ecff9f9 |
|
MD5 | 8729200e405a3f9045d2e615694fa14b |
|
BLAKE2b-256 | bfb5e6e96744fce350887feebdaaf4f2d0c835dfc63338560ce54d5c35f6d7ea |
File details
Details for the file fastapi_simple_auth-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: fastapi_simple_auth-0.0.9-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92f2898839bbb9e56496d5e9d3800d8463ef6251f03a3c562cef053c6a48702c |
|
MD5 | 7ff631a728ad93a5b5d1ce4ff5fd57d3 |
|
BLAKE2b-256 | 45eb9788109053a6608b71bd688149625925af24df1e07d6ebdfd6ffea38a519 |