# Python OAuth libraries

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

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Requests-OAuthlib](#requests-oauthlib) | 278.1M | 1.8K | Mar 2024 | ISC |
| [OAuthlib](#oauthlib) | 273.5M | 3.0K | Oct 2026 | BSD-3-Clause |
| [MSAL](#msal) | 176.6M | Not on GitHub | Sep 2026 | MIT |
| [Authlib](#authlib-library) | 139.8M | Not on GitHub | Nov 2026 | BSD-3-Clause |
| [google-auth-oauthlib](#google-auth-oauthlib) | 124.3M | Not on GitHub | Sep 2026 | Apache-2.0 |
| [django-allauth](#django-allauth) | 7.2M | Not on GitHub | Nov 2026 | MIT |
| [Django OAuth Toolkit](#django-oauth-toolkit) | 6.9M | Not on GitHub | Aug 2026 | BSD-3-Clause |
| [social-auth-core](#social-auth-core) | 6.1M | Not on GitHub | Nov 2026 | BSD-3-Clause |

Downloads: pypi, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[Requests-OAuthlib](#requests-oauthlib) has the most monthly downloads in this comparison, at 278.1M.

## Capabilities

| Library | Legacy OAuth client | Authorization server | Async HTTP client |
| --- | --- | --- | --- |
| [Requests-OAuthlib](#requests-oauthlib) | Yes | No | No |
| [OAuthlib](#oauthlib) | Yes | Yes | No |
| [MSAL](#msal) | No | No | No |
| [Authlib](#authlib-library) | Yes | Yes | Yes |
| [google-auth-oauthlib](#google-auth-oauthlib) | No | No | No |
| [django-allauth](#django-allauth) | Yes | Yes | No |
| [Django OAuth Toolkit](#django-oauth-toolkit) | No | Yes | No |
| [social-auth-core](#social-auth-core) | Yes | No | No |

## Libraries

### Requests-OAuthlib

[GitHub](https://github.com/requests/requests-oauthlib) · [pypi](https://pypi.org/project/requests-oauthlib) · [Docs](https://requests-oauthlib.readthedocs.io/en/latest/api.html)

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
- Capabilities: [From the Requests-OAuthlib docs](https://requests-oauthlib.readthedocs.io/en/latest/api.html)

**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.

**Watch out for**

- **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.

```sh
python -m pip install requests-oauthlib==2.0.0
```

**singingwolfboy/flask-dance** (1.0K stars)

[singingwolfboy/flask-dance](https://github.com/singingwolfboy/flask-dance) 

```python
def login(self):
    log.debug("client_id = %s", self.client_id)
    self.session.redirect_uri = url_for(".authorized", _external=True)
    if self.use_pkce:
        code_verifier = generate_token(length=48)
        code_challenge = self.session._client.create_code_challenge(
            code_verifier=code_verifier,
            code_challenge_method=self.code_challenge_method,
        )
        self.authorization_url_params.update(
            {
                "code_challenge_method": self.code_challenge_method,
                "code_challenge": code_challenge,
            }
        )
        code_verifier_key = f"{self.name}_oauth_code_verifier"
        flask.session[code_verifier_key] = code_verifier
        log.debug("code_verifier = %s", code_verifier)

    url, state = self.session.authorization_url(
        self.authorization_url, state=self.state, **self.authorization_url_params
    )
    state_key = f"{self.name}_oauth_state"
    flask.session[state_key] = state
    log.debug("state = %s", state)
    log.debug("redirect URL = %s", url)
    oauth_before_login.send(self, url=url)
    return redirect(url)
```

[flask_dance/consumer/oauth2.py](https://github.com/singingwolfboy/flask-dance/blob/70f79fd9b633cea7b9742219888fac08069edc22/flask_dance/consumer/oauth2.py#L213-L240) · [More projects using Requests-OAuthlib →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20requests-oauthlib%20for%20login%20redirects%2C%20authorization%20request%20validation%20and%20saved%20token%20refresh&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from requests_oauthlib import OAuth2Session

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

```

From [README.md](https://requests-oauthlib.readthedocs.io/en/latest/api.html)

### OAuthlib

[GitHub](https://github.com/oauthlib/oauthlib) · [pypi](https://pypi.org/project/oauthlib) · [Docs](https://oauthlib.readthedocs.io/en/latest/oauth2/clients/webapplicationclient.html)

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
- Capabilities: [From the OAuthlib docs](https://oauthlib.readthedocs.io/en/latest/oauth2/clients/webapplicationclient.html)

**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.

**Watch out for**

- **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.

```sh
python -m pip install oauthlib==4.0.1
```

**Quickstart**

```python
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)

```

From [web_application.py](https://oauthlib.readthedocs.io/en/latest/oauth2/clients/webapplicationclient.html) · [Find projects using OAuthlib →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20oauthlib%20for%20login%20redirects%2C%20authorization%20request%20validation%20and%20saved%20token%20refresh&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### MSAL

[GitHub](https://github.com/AzureAD/microsoft-authentication-library-for-python) · [pypi](https://pypi.org/project/msal) · [Docs](https://msal-python.readthedocs.io/en/latest/)

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

- Downloads / mo: 176.6M
- Last release: 1.39.0
- License: MIT
- Capabilities: [From the MSAL docs](https://msal-python.readthedocs.io/en/latest/)

```sh
python -m pip install msal==1.39.0
```

**Azure/azure-workload-identity** (345 stars)

[Azure/azure-workload-identity](https://github.com/Azure/azure-workload-identity) 

```python
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))
```

[examples/msal-python/token_credential.py](https://github.com/Azure/azure-workload-identity/blob/6bc89187a92df647064f9d4ffe1bd5413bce6927/examples/msal-python/token_credential.py#L26-L33) · [More projects using MSAL →](https://dashboard.exa.ai/playground/search?q=msal%20GitHub%20projects)

**Quickstart**

```python
from msal import ConfidentialClientApplication

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

```

From [index.html](https://msal-python.readthedocs.io/en/latest/)

### Authlib

[GitHub](https://github.com/authlib/authlib) · [pypi](https://pypi.org/project/authlib) · [Docs](https://docs.authlib.org/en/stable/oauth2/client/http/requests.html)

Builds OAuth and OpenID Connect servers and clients.

- Downloads / mo: 139.8M
- Last release: 1.9.9
- License: BSD-3-Clause
- Capabilities: [From the Authlib docs](https://docs.authlib.org/en/stable/oauth2/client/http/requests.html)

```sh
python -m pip install authlib==1.9.9 requests
```

**authlib/example-oauth2-server** (702 stars)

[authlib/example-oauth2-server](https://github.com/authlib/example-oauth2-server) 

```python
@bp.route("/oauth/authorize", methods=["GET", "POST"])
def authorize():
    user = current_user()
    if not user:
        return redirect(
            url_for("home.home", next=request.script_root + request.full_path)
        )

    try:
        grant = authorization.get_consent_grant(end_user=user)
    except OAuth2Error as error:
        return authorization.handle_error_response(request, error)

    if request.method == "GET":
        return render_template("authorize.html", user=user, grant=grant)

    grant_user = user if "confirm" in request.form else None
    return authorization.create_authorization_response(
        grant=grant, grant_user=grant_user
    )

```

[src/website/routes.py](https://github.com/authlib/example-oauth2-server/blob/48f26d549359d189b1c1e75ade96f14d860a8bd1/src/website/routes.py#L107-L126) · [More projects using Authlib →](https://dashboard.exa.ai/playground/search?q=authlib%20GitHub%20projects)

**Quickstart**

```python
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)

```

From [requests.rst](https://docs.authlib.org/en/stable/oauth2/client/http/requests.html)

### google-auth-oauthlib

[GitHub](https://github.com/googleapis/google-cloud-python) · [pypi](https://pypi.org/project/google-auth-oauthlib) · [Docs](https://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html)

Provides Google authentication.

- Downloads / mo: 124.3M
- Last release: 1.5.0
- License: Apache-2.0
- Capabilities: [From the google-auth-oauthlib docs](https://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html)

```sh
python -m pip install google-auth-oauthlib==1.5.0
```

**burnash/gspread** (7.5K stars)

[burnash/gspread](https://github.com/burnash/gspread) 

```python
def local_server_flow(
    client_config: Mapping[str, Any], scopes: Iterable[str], port: int = 0
) -> OAuthCredentials:
    """Run an OAuth flow using a local server strategy.

    Creates an OAuth flow and runs `google_auth_oauthlib.flow.InstalledAppFlow.run_local_server <https://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html#google_auth_oauthlib.flow.InstalledAppFlow.run_local_server>`_.
    This will start a local web server and open the authorization URL in
    the user's browser.

    Pass this function to ``flow`` parameter of :meth:`~gspread.oauth` to run
    a local server flow.
    """
    flow = InstalledAppFlow.from_client_config(client_config, scopes)
    return flow.run_local_server(port=port)
```

[gspread/auth.py](https://github.com/burnash/gspread/blob/7ca71eaa4658320b89f82f49620dac6891986cdd/gspread/auth.py#L98-L111) · [More projects using google-auth-oauthlib →](https://dashboard.exa.ai/playground/search?q=google-auth-oauthlib%20GitHub%20projects)

**Quickstart**

```python
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)

```

From [flow.py](https://google-auth-oauthlib.readthedocs.io/en/latest/reference/google_auth_oauthlib.flow.html)

### django-allauth

[pypi](https://pypi.org/project/django-allauth) · [Docs](https://docs.allauth.org/en/latest/installation/quickstart.html)

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

- Downloads / mo: 7.2M
- Last release: 65.22.1
- License: MIT
- Capabilities: [From the django-allauth docs](https://docs.allauth.org/en/latest/installation/quickstart.html)

```sh
python -m pip install "django-allauth[socialaccount]==65.22.1"
```

**iMerica/dj-rest-auth** (1.9K stars)

[iMerica/dj-rest-auth](https://github.com/iMerica/dj-rest-auth) 

```python
def get_social_login(self, adapter, app, token, response):
    """
    :param adapter: allauth.socialaccount Adapter subclass.
        Usually OAuthAdapter or Auth2Adapter
    :param app: `allauth.socialaccount.SocialApp` instance
    :param token: `allauth.socialaccount.SocialToken` instance
    :param response: Provider's response for OAuth1. Not used in the
    :returns: A populated instance of the
        `allauth.socialaccount.SocialLoginView` instance
    """
    request = self._get_request()
    social_login = adapter.complete_login(request, app, token, response=response)
    social_login.token = token
    return social_login
```

[dj_rest_auth/registration/serializers.py](https://github.com/iMerica/dj-rest-auth/blob/69ef459bdcd4a4a25121ad2064cc18a6601addb6/dj_rest_auth/registration/serializers.py#L63-L76) · [More projects using django-allauth →](https://dashboard.exa.ai/playground/search?q=django-allauth%20GitHub%20projects)

**Quickstart**

```python
from django.urls import include, path

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

```

From [quickstart.html](https://docs.allauth.org/en/latest/installation/quickstart.html)

### Django OAuth Toolkit

[GitHub](https://github.com/django-oauth/django-oauth-toolkit) · [pypi](https://pypi.org/project/django-oauth-toolkit) · [Docs](https://django-oauth-toolkit.readthedocs.io/en/latest/getting_started.html)

Runs an OAuth authorization server for Django.

- Downloads / mo: 6.9M
- Last release: 3.4.1
- License: BSD-3-Clause
- Capabilities: [From the Django OAuth Toolkit docs](https://django-oauth-toolkit.readthedocs.io/en/latest/getting_started.html)

```sh
python -m pip install django-oauth-toolkit==3.4.1
```

**Quickstart**

```python
from django.urls import include, path

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

```

From [getting_started.rst](https://django-oauth-toolkit.readthedocs.io/en/latest/getting_started.html) · [Find projects using Django OAuth Toolkit →](https://dashboard.exa.ai/playground/search?q=django-oauth-toolkit%20GitHub%20projects)

### social-auth-core

[GitHub](https://github.com/python-social-auth/social-core) · [pypi](https://pypi.org/project/social-auth-core) · [Docs](https://api.github.com/repos/python-social-auth/social-core/contents/social_core/backends/base.py?ref=7.2.0)

Provides social authentication for Python.

- Downloads / mo: 6.1M
- Last release: 7.2.0
- License: BSD-3-Clause
- Capabilities: [From the social-auth-core docs](https://api.github.com/repos/python-social-auth/social-core/contents/social_core/backends/base.py?ref=7.2.0)

```sh
python -m pip install social-auth-core==7.2.0
```

**python-social-auth/social-app-django** (2.1K stars)

[python-social-auth/social-app-django](https://github.com/python-social-auth/social-app-django) 

```python
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)
```

[social_django/views.py](https://github.com/python-social-auth/social-app-django/blob/f88587c894c0114d7f31ad150fd0a4dbc654fa5f/social_django/views.py#L274-L281) · [More projects using social-auth-core →](https://dashboard.exa.ai/playground/search?q=social-auth-core%20GitHub%20projects)

**Quickstart**

```python
from social_core.backends.github import GithubOAuth2

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

```

From [base.py](https://api.github.com/repos/python-social-auth/social-core/contents/social_core/backends/base.py?ref=7.2.0)

## FAQ

### Which Python OAuth library should I use?

[Authlib](#authlib-library) suits applications that need OAuth clients and Flask or Django authorization servers. [Requests-OAuthlib](#requests-oauthlib) suits client code built on Requests. [MSAL](#msal) suits applications that sign users in with Microsoft identity.

### What is django-allauth?

[django-allauth](#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.

### What is MSAL for Python?

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

### What is Authlib?

[Authlib](#authlib-library) builds OAuth and OpenID Connect clients and servers. It offers synchronous clients on Requests and asynchronous clients on HTTPX.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python OAuth libraries Authlib Requests-OAuthlib OAuthLib HTTPX OAuth examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
