Python authentication libraries

Updated Nov 2026

Python authentication libraries verify who a user is through passwords, sessions, tokens, or sign-in with an outside identity provider. A web framework extension stores the signed-in user in a session cookie or a signed token. These libraries let web apps and APIs sign users in without writing password and token handling from scratch.

Popularity

Authlib has the most monthly downloads in this comparison, at 137.9M.

LibraryMonthly downloadsStarsLast releaseLicense
Authlib
137.9M
5.5KNov 2026BSD-3-Clause
Flask-Login
18.6M
3.7KOct 2023MIT
Simple JWT
8.4M
4.3KJul 2025MIT
django-allauth
7.2M
10.4KNov 2026MIT
Django OAuth Toolkit
6.8M
3.3KAug 2026BSD-2-Clause
social-auth-app-django
5.9M
2.1KNov 2026BSD-3-Clause
django-otp
5.7M
629Oct 2026Unlicense
Flask-JWT-Extended
5.2M
1.6KMay 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Builds OAuth and OpenID Connect servers and clients.

Downloads / mo
137.9M
Stars
5.5K
Last release
1.9.9
License
BSD-3-Clause

Quickstart

From index.html
$ pip install Authlib requests
from authlib.integrations.requests_client import OAuth2Session

with OAuth2Session("example-client-id", "example-client-secret", scope="user:email") as client:
    uri, state = client.create_authorization_url("https://github.com/login/oauth/authorize")
    print(uri)

Authlib examples

From open-source projects on GitHub
@app.get("/login/huggingface")
async def oauth_login(request: fastapi.Request):
    """Endpoint that redirects to HF OAuth page."""
    # Define target (where to redirect after login)
    redirect_uri = _generate_redirect_uri(request)
    return await oauth.huggingface.authorize_redirect(request, redirect_uri)  # type: ignore

Manages user authentication and sessions for Flask.

Downloads / mo
18.6M
Stars
3.7K
Last release
0.6.3
License
MIT

Quickstart

From README.md
$ pip install flask-login
import flask
import flask_login

app = flask.Flask(__name__)
app.secret_key = "super secret string"  # Change this!

login_manager = flask_login.LoginManager()
login_manager.init_app(app)

Flask-Login examples

From open-source projects on GitHub

Adds JSON Web Token authentication to Django REST Framework.

Downloads / mo
8.4M
Stars
4.3K
Last release
5.5.1
License
MIT

Quickstart

From getting_started.rst
$ pip install djangorestframework-simplejwt
from django.urls import path
from rest_framework_simplejwt.views import TokenObtainPairView

urlpatterns = [
    path("api/token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
]

Simple JWT examples

From open-source projects on GitHub
def jwt_encode(user):
    from dj_rest_auth.app_settings import api_settings

    JWTTokenClaimsSerializer = api_settings.JWT_TOKEN_CLAIMS_SERIALIZER

    refresh = JWTTokenClaimsSerializer.get_token(user)
    return refresh.access_token, refresh

Provides integrated Django account registration, management, and authentication.

Downloads / mo
7.2M
Stars
10.4K
Last release
65.22.1
License
MIT

Strengths

  • Combines local and social login. Use local accounts and external identities in the same account system.
  • Supports passkeys and recovery codes. Add the MFA extra for passkeys, authenticator codes, and recovery codes.

Limitations

  • Rate limits need shared storage. Use a shared cache to enforce limits across application workers.
  • IP limits need proxy configuration. Configure trusted proxies so rate limits use the correct client address.

Quickstart

From urls.py
$ pip install django-allauth
from django.urls import include, path

urlpatterns = [path("accounts/", include("allauth.urls"))]

django-allauth examples

From open-source projects on GitHub

Django OAuth Toolkit

Runs an OAuth authorization server inside Django.

Downloads / mo
6.8M
Stars
3.3K
Last release
3.4.1
License
BSD-2-Clause

Quickstart

From README.md
$ pip install django-oauth-toolkit
from django.urls import include, path

urlpatterns = [
    path("o/", include("oauth2_provider.urls", namespace="oauth2_provider")),
]

social-auth-app-django

Integrates Python Social Auth with Django.

Downloads / mo
5.9M
Stars
2.1K
Last release
8.1.0
License
BSD-3-Clause

Quickstart

From django.rst
$ pip install social-auth-app-django
from django.urls import include, path

urlpatterns = [
    path("", include("social_django.urls", namespace="social")),
]

social-auth-app-django examples

From open-source projects on GitHub

Adds two-factor authentication with one-time passwords to Django.

Downloads / mo
5.7M
Stars
629
Last release
1.7.5
License
Unlicense

Quickstart

From models.py
$ pip install django-otp
from django.conf import settings

settings.configure(
    SECRET_KEY="example-only",
    INSTALLED_APPS=["django.contrib.auth", "django.contrib.contenttypes", "django_otp", "django_otp.plugins.otp_hotp"],
    DATABASES={"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}},
    USE_TZ=True,
)
import django
django.setup()
from django.core.management import call_command
from django.contrib.auth import get_user_model
from django_otp.plugins.otp_hotp.models import HOTPDevice

call_command("migrate", verbosity=0)
user = get_user_model().objects.create_user(username="example")
device = HOTPDevice.objects.create(user=user, key=b"12345678901234567890".hex(), tolerance=0)
print(device.verify_token(755224))

django-otp examples

From open-source projects on GitHub

Flask-JWT-Extended

Adds JWT support to Flask.

Downloads / mo
5.2M
Stars
1.6K
Last release
4.7.4
License
MIT

Quickstart

From basic_usage.html
$ pip install flask-jwt-extended
from flask import Flask
from flask_jwt_extended import JWTManager, create_access_token

app = Flask(__name__)
app.config["JWT_SECRET_KEY"] = "super-secret"  # Local example only; replace this key.
JWTManager(app)

with app.app_context():
    token = create_access_token(identity="example")
    print(token)

Flask-JWT-Extended examples

From open-source projects on GitHub

FAQ

Flask-Login suits Flask apps that manage their own user sessions. django-allauth suits Django sites that need registration and social sign-in. Authlib suits apps that act as OAuth or OpenID Connect clients or servers.

django-allauth provides account registration, email verification, and social sign-in for Django in one package.

Flask-Login manages the signed-in user's session and protects views that require login. Token-based APIs use Flask-JWT-Extended instead.

Authlib integrates with Starlette and FastAPI for OAuth and OpenID Connect sign-in. API routes check tokens through FastAPI security dependencies.

Authlib builds OAuth and OpenID Connect clients and servers in Python. It integrates with Flask, Django, Starlette, and the requests and HTTPX clients.

For coding agents

Found your authentication library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official