Skip to main content

FastAPI Simple Auth

Documentation Status

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

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

Metadata

Release files for fastapi-simple-auth 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-simple-auth 0.0.9
File Size Uploaded Provenance
fastapi_simple_auth-0.0.9.tar.gz 66.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-simple-auth 0.0.9
File Interpreter ABI Platform
fastapi_simple_auth-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 99.8 kB

Release files / fastapi_simple_auth-0.0.9.tar.gz

Download URL fastapi_simple_auth-0.0.9.tar.gz
Size 66.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5efa819a793db4f7c3c30964c5453564b76fc7ae4ffb78cc9af6aee25ecff9f9
BLAKE2b-256 checksum
How to use checksums
bfb5e6e96744fce350887feebdaaf4f2d0c835dfc63338560ce54d5c35f6d7ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Release files / fastapi_simple_auth-0.0.9-py3-none-any.whl

Download URL fastapi_simple_auth-0.0.9-py3-none-any.whl
Size 33.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92f2898839bbb9e56496d5e9d3800d8463ef6251f03a3c562cef053c6a48702c
BLAKE2b-256 checksum
How to use checksums
45eb9788109053a6608b71bd688149625925af24df1e07d6ebdfd6ffea38a519
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Security for fastapi-simple-auth 0.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page