Typing stubs for Authlib
This is a type stub package for the Authlib library, providing static type checking for Authlib code. As part of the typeshed project, it's automatically released up to once a day. This version of types-Authlib aims to provide accurate annotations for Authlib==1.6.9. [9, 8, 23]
Warnings
- gotcha The `types-authlib` package provides only type stubs and does not install `Authlib` itself. For effective type checking and runtime functionality, you must install both `Authlib` (e.g., `pip install Authlib`) and `types-authlib`.
- breaking The `types-authlib` package is specifically versioned to target a particular `Authlib` runtime library release (e.g., `types-Authlib==1.6.9.x` provides stubs for `Authlib==1.6.9`). Mismatches between the installed `types-authlib` version and the `Authlib` version can lead to type checking errors or unannotated code.
- gotcha As `types-authlib` is part of the `typeshed` project, its stubs are automatically released and updated frequently. These updates can sometimes introduce minor changes that might cause new type checker warnings or errors, even if the underlying `Authlib` library has not changed. [8]
- breaking `types-authlib` requires Python `>=3.10`. Using it with older Python versions will result in installation failures or compatibility issues. Note that `Authlib` itself dropped Python 2 support with version 1.0.0.
- breaking Authlib itself has undergone significant API changes in major versions (e.g., 0.12, 0.14, 1.0, 1.1) related to grant systems, removal of built-in SQLAlchemy integration, and JOSE module renames. If you upgrade Authlib, ensure you also update `types-authlib` to a compatible version to avoid numerous type checking errors. [1, 2, 4, 5]
Install
-
pip install types-authlib
Imports
- OAuth
from authlib.integrations.flask_client import OAuth
- AuthorizationServer
from authlib.integrations.flask_oauth2 import AuthorizationServer
- JsonWebToken
from authlib.jose import JsonWebToken
Quickstart
import os
from flask import Flask
from authlib.integrations.flask_client import OAuth
# NOTE: For actual use, configure these securely from environment variables
# or a configuration management system, not hardcoded.
CLIENT_ID = os.environ.get('GOOGLE_CLIENT_ID', 'your-google-client-id')
CLIENT_SECRET = os.environ.get('GOOGLE_CLIENT_SECRET', 'your-google-client-secret')
app = Flask(__name__)
app.config.update({
'SECRET_KEY': 'very-secret-key-for-session',
'GOOGLE_CLIENT_ID': CLIENT_ID,
'GOOGLE_CLIENT_SECRET': CLIENT_SECRET
})
oauth = OAuth(app)
oauth.register(
name='google',
client_id=app.config['GOOGLE_CLIENT_ID'],
client_secret=app.config['GOOGLE_CLIENT_SECRET'],
access_token_url='https://oauth2.googleapis.com/token',
authorize_url='https://accounts.google.com/o/oauth2/auth',
api_base_url='https://www.googleapis.com/oauth2/v1/',
client_kwargs={'scope': 'openid email profile'}
)
print("Authlib OAuth client registered for Google. ")
print("This example demonstrates type-checked setup, but does not run a server.")
print("Run a type checker like MyPy on this file after installing types-authlib.")