FastAPI simple authentication
Project description
FastAPI Simple Auth
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
- Optional email verification
- User creation
- Password recovery
- Profile page with change password, change email
- Custom UI themes!
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.6.tar.gz
(64.3 kB
view details)
Built Distribution
File details
Details for the file fastapi_simple_auth-0.0.6.tar.gz
.
File metadata
- Download URL: fastapi_simple_auth-0.0.6.tar.gz
- Upload date:
- Size: 64.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.25.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ebbbf14e2ca5c6500ebb8cc4bafe0626a36cc23b815434977d4c90c7758bc70 |
|
MD5 | 63d9ce2b6c244c2102c31c35cea36044 |
|
BLAKE2b-256 | c221450958583c3c540b4ec8e5b0c407492afff8d7660d72a2e536d44b58660a |
File details
Details for the file fastapi_simple_auth-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: fastapi_simple_auth-0.0.6-py3-none-any.whl
- Upload date:
- Size: 32.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.25.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b0d3725e10b23dc40c26f99dbe2d2734048cd7bd17c3d589aaddb6174cbd61e |
|
MD5 | 21322d276625fa4cb7d7a7828262f384 |
|
BLAKE2b-256 | 7528db65393a8b772a0cc955fe03507a6acdbd22b6677abe706cb19643923665 |