semvec/pypi-packages huggingface dataset:
fastapi-simple-auth 0.0.9
FastAPI simple authentication
Requires Python: >=3.7

# FastAPI Simple Auth

[![Documentation Status](https://readthedocs.org/projects/fastapi-simple-auth/badge/?version=latest)](https://fastapi-simple-auth.readthedocs.io/en/latest/?badge=latest)



- 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!

1. Import package
2. hook to app with `SimpleAuth(app)`
3. add `user: logged_in_user` to protected view

~~~python
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}"
~~~

![login screenshot](docs/img/login.png)

## 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

~~~shell
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](http://httpie.io/) 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
~~~