Python OAuth libraries

Updated Nov 2026

Python OAuth libraries implement the OAuth and OpenID Connect flows that let an application act for a user at another service. A client library sends the user to the provider's consent page and exchanges the returned code for tokens. These libraries let apps and AI agents call third-party APIs with a user's permission.

Popularity

Requests-OAuthlib has the most monthly downloads in this comparison, at 278.1M.

LibraryMonthly downloadsStarsLast releaseLicense
Requests-OAuthlib
278.1M
1.8KMar 2024ISC
OAuthlib
273.5M
3.0KOct 2026BSD-3-Clause
MSAL
176.6M
Not on GitHubSep 2026MIT
Authlib
139.8M
Not on GitHubNov 2026BSD-3-Clause
google-auth-oauthlib
124.3M
Not on GitHubSep 2026Apache-2.0
django-allauth
7.2M
Not on GitHubNov 2026MIT
Django OAuth Toolkit
6.9M
Not on GitHubAug 2026BSD-3-Clause
social-auth-core
6.1M
Not on GitHubNov 2026BSD-3-Clause
Downloads: pypi, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Features compared

LibraryLegacy OAuth clientAuthorization serverAsync HTTP client
Requests-OAuthlibBuilt-inUnsupportedUnsupported
OAuthlibBuilt-inBuilt-inUnsupported
MSALUnsupportedUnsupportedUnsupported
AuthlibBuilt-inBuilt-inBuilt-in
google-auth-oauthlibUnsupportedUnsupportedUnsupported
django-allauthBuilt-inBuilt-inUnsupported
Django OAuth ToolkitUnsupportedBuilt-inUnsupported
social-auth-coreBuilt-inUnsupportedUnsupported
Built-inNot supported

Libraries and code examples

Requests-OAuthlib

Adds OAuth request signing and token workflows to the Requests session interface.

Downloads / mo
278.1M
Stars
1.8K
Last release
2.0.0
License
ISC

Strengths

  • Extends the Requests session interface. Generate authorization URLs, exchange codes, and call protected resources with OAuth2Session.
  • Refreshes and saves tokens automatically. Configure token_updater and the refresh endpoint to persist renewed credentials.

Limitations

  • Refresh timing needs accurate expiry. Supply accurate expires_in values so the session can detect expired tokens.
  • Refreshed tokens need a saver. Provide token_updater or catch TokenUpdated and persist the returned credentials.

Quickstart

From README.md
$ python -m pip install requests-oauthlib==2.0.0
from requests_oauthlib import OAuth2Session

client = OAuth2Session(client_id, redirect_uri=redirect_uri, scope=scopes)
authorization_url, state = client.authorization_url(authorization_endpoint)

Requests-OAuthlib examples

From open-source projects on GitHub

Implements OAuth protocol logic independently of a particular HTTP library or web framework.

Downloads / mo
273.5M
Stars
3.0K
Last release
4.0.1
License
BSD-3-Clause

Strengths

  • Fits different transports and frameworks. Connect OAuth protocol logic to the application’s chosen transport and server.
  • Supports authorization-server implementations. Use provider endpoints with application-specific validators and persistence.

Limitations

  • Servers need custom validation storage. Implement RequestValidator methods against the application’s storage backend.
  • Token-body helpers cannot enforce HTTPS. Enforce HTTPS in the transport that sends generated token request bodies.

Quickstart

From web_application.py
$ python -m pip install oauthlib==4.0.1
from oauthlib.oauth2 import WebApplicationClient

client = WebApplicationClient(client_id)
authorization_url = client.prepare_request_uri(authorization_endpoint, redirect_uri=redirect_uri, scope=scopes, state=state)

Authenticates users with Microsoft Azure so an app can access the Microsoft Cloud.

Downloads / mo
176.6M
Last release
1.39.0
License
MIT

Quickstart

From index.html
$ python -m pip install msal==1.39.0
from msal import ConfidentialClientApplication

app = ConfidentialClientApplication(client_id, authority=authority, client_credential=client_secret)
result = app.acquire_token_for_client(scopes=scopes)

MSAL examples

From open-source projects on GitHub
def get_token(self, *scopes, **kwargs):
    # get the token using the application
    token = self.app.acquire_token_for_client(list(scopes))
    if 'error' in token:
        raise Exception(token['error_description'])
    expires_on = time.time() + token['expires_in']
    # return an access token with the token string and expiration time
    return AccessToken(token['access_token'], int(expires_on))

Builds OAuth and OpenID Connect servers and clients.

Downloads / mo
139.8M
Last release
1.9.9
License
BSD-3-Clause

Quickstart

From requests.rst
$ python -m pip install authlib==1.9.9 requests
from authlib.integrations.requests_client import OAuth2Session

client = OAuth2Session(client_id, client_secret, redirect_uri=redirect_uri)
authorization_url, state = client.create_authorization_url(authorization_endpoint)

Authlib examples

From open-source projects on GitHub

google-auth-oauthlib

Provides Google authentication.

Downloads / mo
124.3M
Last release
1.5.0
License
Apache-2.0

Quickstart

From flow.py
$ python -m pip install google-auth-oauthlib==1.5.0
from google_auth_oauthlib.flow import InstalledAppFlow

flow = InstalledAppFlow.from_client_secrets_file("client_secrets.json", scopes=scopes)
credentials = flow.run_local_server(port=0)

google-auth-oauthlib examples

From open-source projects on GitHub

django-allauth

Handles Django authentication, registration, account management, and social account sign-in.

Downloads / mo
7.2M
Last release
65.22.1
License
MIT

Quickstart

From quickstart.html
$ python -m pip install "django-allauth[socialaccount]==65.22.1"
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 for Django.

Downloads / mo
6.9M
Last release
3.4.1
License
BSD-3-Clause

Quickstart

From getting_started.rst
$ python -m pip install django-oauth-toolkit==3.4.1
from django.urls import include, path

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

social-auth-core

Provides social authentication for Python.

Downloads / mo
6.1M
Last release
7.2.0
License
BSD-3-Clause

Quickstart

From base.py
$ python -m pip install social-auth-core==7.2.0
from social_core.backends.github import GithubOAuth2

backend = GithubOAuth2(strategy=strategy, redirect_uri=redirect_uri)
authorization_url = backend.auth_url()

social-auth-core examples

From open-source projects on GitHub
def _complete(request, backend, *args, **kwargs):
    _discard_session_partial_of_other_user(request)
    kwargs.update(
        user=request.user,
        redirect_name=REDIRECT_FIELD_NAME,
        request=request,
    )
    return do_complete(request.backend, _do_login, *args, **kwargs)

FAQ

Authlib suits applications that need OAuth clients and Flask or Django authorization servers. Requests-OAuthlib suits client code built on Requests. MSAL suits applications that sign users in with Microsoft identity.

django-allauth is a set of Django apps for sign-up, account management, and social login with many providers. An optional module turns it into an OpenID Connect identity provider.

MSAL acquires and caches tokens for users and apps on the Microsoft identity platform. It handles Microsoft-specific flows rather than arbitrary OAuth providers.

Authlib builds OAuth and OpenID Connect clients and servers. It offers synchronous clients on Requests and asynchronous clients on HTTPX.

For coding agents

Found your OAuth 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