Skip to main content

Auth-py

CI Python Version

This is a Python port of the supabase js gotrue client. The current state is that there is a features parity but with small differences that are mentioned in the section Differences to the JS client. As of December 14th, we renamed to repo from gotrue-py to auth-py to mirror the changes in the JavaScript library.

Installation

The package can be installed using pip, uv or poetry:

Pip

pip install supabase_auth

Uv

uv add supabase_auth

Poetry

poetry add supabase_auth

Features

  • Full feature parity with the JavaScript client
  • Support for both synchronous and asynchronous operations
  • MFA (Multi-Factor Authentication) support
  • OAuth and SSO integration
  • Magic link and OTP authentication
  • Phone number authentication
  • Anonymous sign-in
  • Session management with auto-refresh
  • JWT token handling and verification
  • User management and profile updates

Differences to the JS client

It should be noted there are differences to the JS client. If you feel particulaly strongly about them and want to motivate a change, feel free to make a GitHub issue and we can discuss it there.

Firstly, feature pairity is not 100% with the JS client. In most cases we match the methods and attributes of the JS client and api classes, but is some places (e.g for browser specific code) it didn't make sense to port the code line for line.

There is also a divergence in terms of how errors are raised. In the JS client, the errors are returned as part of the object, which the user can choose to process in whatever way they see fit. In this Python client, we raise the errors directly where they originate, as it was felt this was more Pythonic and adhered to the idioms of the language more directly.

In JS we return the error, but in Python we just raise it.

const { data, error } = client.sign_up(...)

The other key difference is we do not use pascalCase to encode variable and method names. Instead we use the snake_case convention adopted in the Python language.

Also, the supabase_auth library for Python parses the date-time string into datetime Python objects. The JS client keeps the date-time as strings.

Usage

The library provides both synchronous and asynchronous clients. Here are some examples:

Synchronous Client

from supabase_auth import SyncGoTrueClient

headers = {
    "apiKey": "my-mega-awesome-api-key",
    # ... any other headers you might need.
}
client: SyncGoTrueClient = SyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)

# Sign up with email and password
user = client.sign_up(email="example@gmail.com", password="*********")

# Sign in with email and password
user = client.sign_in_with_password(email="example@gmail.com", password="*********")

# Sign in with magic link
user = client.sign_in_with_otp(email="example@gmail.com")

# Sign in with phone number
user = client.sign_in_with_otp(phone="+1234567890")

# Sign in with OAuth
user = client.sign_in_with_oauth(provider="google")

# Sign out
client.sign_out()

# Get current user
user = client.get_user()

# Update user profile
user = client.update_user({"data": {"name": "John Doe"}})

Asynchronous Client

from supabase_auth import AsyncGoTrueClient

headers = {
    "apiKey": "my-mega-awesome-api-key",
    # ... any other headers you might need.
}
client: AsyncGoTrueClient = AsyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers)

async def main():
    # Sign up with email and password
    user = await client.sign_up(email="example@gmail.com", password="*********")

    # Sign in with email and password
    user = await client.sign_in_with_password(email="example@gmail.com", password="*********")

    # Sign in with magic link
    user = await client.sign_in_with_otp(email="example@gmail.com")

    # Sign in with phone number
    user = await client.sign_in_with_otp(phone="+1234567890")

    # Sign in with OAuth
    user = await client.sign_in_with_oauth(provider="google")

    # Sign out
    await client.sign_out()

    # Get current user
    user = await client.get_user()

    # Update user profile
    user = await client.update_user({"data": {"name": "John Doe"}})

# Run the async code
import asyncio
asyncio.run(main())

MFA Support

The library includes support for Multi-Factor Authentication:

# List MFA factors
factors = client.mfa.list_factors()

# Enroll a new MFA factor
enrolled_factor = client.mfa.enroll({"factor_type": "totp"})

# Challenge and verify MFA
challenge = client.mfa.challenge({"factor_id": "factor_id"})
verified = client.mfa.verify({"factor_id": "factor_id", "code": "123456"})

# Unenroll a factor
client.mfa.unenroll({"factor_id": "factor_id"})

Contributions

We would be immensely grateful for any contributions to this project.

Metadata

Release files for supabase-auth 2.32.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for supabase-auth 2.32.0
File Size Uploaded
supabase_auth-2.32.0.tar.gz 39.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for supabase-auth 2.32.0
File Interpreter ABI Platform
supabase_auth-2.32.0-py3-none-any.whl Python 3 none any Details

Total release size: 87.7 kB

Release files / supabase_auth-2.32.0.tar.gz

Download URL supabase_auth-2.32.0.tar.gz
Size 39.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c68ea37b7bc61292b1d85390315c5c62756253fc9ab5613108b86f7534c72cf0
BLAKE2b-256 checksum
How to use checksums
1c8b7f3958dce7f23196b1dbe93d7178aab14082b792c3b142e9622ba45f2294
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.2

Release files / supabase_auth-2.32.0-py3-none-any.whl

Download URL supabase_auth-2.32.0-py3-none-any.whl
Size 48.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da3ede5e2976bf4d6b11c0ae5bc8f0f6612175bbb194aba2994dcce2629de86f
BLAKE2b-256 checksum
How to use checksums
05a5b5c2b2ea7e2877e0994b5816592914cf7b414dba53b22af733fb0629361a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.8.2

Release history Release notifications | RSS feed

This release

2.32.0 This release

2 release files

2.30.1

2 release files

2.29.0

2 release files

2.28.3

2 release files

2.28.2

2 release files

2.28.1

2 release files

2.28.0

2 release files

2.27.2

2 release files

2.27.0

2 release files

2.26.0

2 release files

2.25.1

2 release files

2.23.0

2 release files

2.22.4

2 release files

2.22.3

2 release files

2.22.2

2 release files

2.22.1

2 release files

2.20.0

2 release files

2.19.0

2 release files

2.12.2

2 release files

2.12.0

2 release files

2.11.4

2 release files

2.11.3

2 release files

2.11.2

2 release files

2.11.1

2 release files

2.11.0

2 release files

2.9.3

2 release files

2.9.2

2 release files

2.9.1

2 release files

2.9.0

2 release files

2.8.1

2 release files

2.8.0

2 release files

2.7.0

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.5

2 release files

2.5.4

2 release files

2.5.3

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.4

2 release files

2.4.3

2 release files

2.4.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page