Metadata-Version: 2.4
Name: supabase_auth
Version: 3.0.0a2
Summary: Python Client Library for Supabase Auth
Author: Joel Lee
Author-email: Joel Lee <joel@joellee.org>
License-Expression: MIT
License-File: LICENSE
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Operating System :: OS Independent
Requires-Dist: pydantic>=2,<3
Requires-Dist: pyjwt[crypto]>=2.15.1
Requires-Dist: supabase-utils==3.0.0a2
Maintainer: Leonardo Santiago
Maintainer-email: Leonardo Santiago <leonardo.santiago@supabase.io>
Requires-Python: >=3.12
Project-URL: homepage, https://github.com/supabase/supabase-py/tree/main/src/auth
Project-URL: repository, https://github.com/supabase/supabase-py
Project-URL: documentation, https://supabase.com/docs/reference/python/auth-api
Project-URL: changelog, https://github.com/supabase/supabase-py/tree/main/CHANGELOG.md
Description-Content-Type: text/markdown

# supabase_auth

[![CI](https://github.com/supabase/supabase-py/actions/workflows/ci.yml/badge.svg)](https://github.com/supabase/supabase-py/actions/workflows/ci.yml)
[![Python](https://img.shields.io/pypi/pyversions/supabase_auth)](https://pypi.org/project/supabase_auth)
[![Version](https://img.shields.io/pypi/v/supabase_auth?color=%2334D058)](https://pypi.org/project/supabase_auth)

Python client for [Supabase Auth](https://github.com/supabase/auth). Most users
use it through the
[`supabase`](https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md)
package, as `client.auth`.

## Installation

The package needs an HTTP client adapter, for example httpx:

```bash
pip install supabase_auth "supabase_utils[httpx]"
uv add supabase_auth "supabase_utils[httpx]"
```

Use `supabase_utils[aiohttp]` instead to run the async client on aiohttp.

## Differences to the JavaScript client

The API follows
[`@supabase/auth-js`](https://github.com/supabase/supabase-js/tree/master/packages/core/auth-js),
without the browser specific code. Names are snake_case, dates are `datetime`
objects, and errors are raised as subclasses of `AuthError` instead of being
returned next to the data.

## Supabase Service Compatibility

Only the
[latest Supabase Auth release](https://github.com/supabase/auth/releases) is
guaranteed to work. Older releases are supported on a best-effort basis. If you
self-host, upgrade Supabase Auth when you upgrade this SDK.

## Usage

The client takes the URL of the auth service and an HTTP session. Leaving its
context manager closes the session and stops the automatic token refresh.

```python
from httpx import Client
from supabase_auth import (
    SignInWithPassword,
    SignInWithPasswordless,
    SignUpWithPassword,
    SyncSupabaseAuthClient,
    UserAttributes,
)
from supabase_utils.http.adapters.httpx import HttpxSession

with SyncSupabaseAuthClient(
    "https://<project_ref>.supabase.co/auth/v1",
    HttpxSession(Client()),
    headers={"apikey": "your-publishable-key"},
) as client:
    client.sign_up(
        SignUpWithPassword.email("someone@example.com", "a-strong-password")
    )
    client.sign_in_with_password(
        SignInWithPassword.email("someone@example.com", "a-strong-password")
    )

    # Magic link and phone one-time password
    client.sign_in_with_otp(SignInWithPasswordless.email("someone@example.com"))
    client.sign_in_with_otp(SignInWithPasswordless.phone("+1234567890"))

    # OAuth: send the user to the returned URL
    print(client.sign_in_with_oauth("google").url)

    user = client.get_user()
    client.update_user(UserAttributes(data={"name": "John Doe"}))
    client.sign_out()
```

`AsyncSupabaseAuthClient` has the same methods. Create it with an
`AsyncHttpxSession`, use `async with`, and `await` each call:

```python
from httpx import AsyncClient
from supabase_auth import AsyncSupabaseAuthClient
from supabase_utils.http.adapters.httpx import AsyncHttpxSession

async with AsyncSupabaseAuthClient(
    "https://<project_ref>.supabase.co/auth/v1",
    AsyncHttpxSession(AsyncClient()),
    headers={"apikey": "your-publishable-key"},
) as async_client:
    user = await async_client.get_user()
```

## Multi-factor authentication

```python
from supabase_auth import MFAEnroll

factors = client.mfa.list_factors()
factor = client.mfa.enroll(MFAEnroll.totp(friendly_name="My phone"))

challenge = client.mfa.challenge(factor.id)
client.mfa.verify(factor.id, "123456", challenge.id)
# Or both in one call
client.mfa.challenge_and_verify(factor.id, "123456")

client.mfa.unenroll(factor.id)
```

## OAuth 2.1 server consent

When your project acts as an OAuth 2.1 server, your consent page receives an
`authorization_id` query parameter. Show the request and send the user to the
returned URL once they decide.

```python
from supabase_auth import OAuthRedirect

details = client.oauth.get_authorization_details("<authorization_id>")
if isinstance(details, OAuthRedirect):
    redirect_url = details.redirect_url  # The user already consented
else:
    print(f"{details.client.name} requests {details.scope}")
    redirect_url = client.oauth.approve_authorization(
        details.authorization_id
    ).redirect_url

for grant in client.oauth.list_grants():
    client.oauth.revoke_grant(grant.client.id)
```
