Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
/auth-pyPublic archive

Python client implementation for Supabase Auth

License

Notifications You must be signed in to change notification settings

supabase/auth-py

Warning

This repository has been moved to the supabase-py monorepo.

Auth-py

CIPythonVersionCoverage Status

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 or poetry:

Poetry

poetry add supabase_auth

Pip

pip install 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

fromsupabase_authimportSyncGoTrueClientheaders={"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 passworduser=client.sign_up(email="[email protected]", password="*********") # Sign in with email and passworduser=client.sign_in_with_password(email="[email protected]", password="*********") # Sign in with magic linkuser=client.sign_in_with_otp(email="[email protected]") # Sign in with phone numberuser=client.sign_in_with_otp(phone="+1234567890") # Sign in with OAuthuser=client.sign_in_with_oauth(provider="google") # Sign outclient.sign_out() # Get current useruser=client.get_user() # Update user profileuser=client.update_user({"data":{"name": "John Doe"}})

Asynchronous Client

fromsupabase_authimportAsyncGoTrueClientheaders={"apiKey": "my-mega-awesome-api-key", # ... any other headers you might need. } client: AsyncGoTrueClient=AsyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers) asyncdefmain(): # Sign up with email and passworduser=awaitclient.sign_up(email="[email protected]", password="*********") # Sign in with email and passworduser=awaitclient.sign_in_with_password(email="[email protected]", password="*********") # Sign in with magic linkuser=awaitclient.sign_in_with_otp(email="[email protected]") # Sign in with phone numberuser=awaitclient.sign_in_with_otp(phone="+1234567890") # Sign in with OAuthuser=awaitclient.sign_in_with_oauth(provider="google") # Sign outawaitclient.sign_out() # Get current useruser=awaitclient.get_user() # Update user profileuser=awaitclient.update_user({"data":{"name": "John Doe"}}) # Run the async codeimportasyncioasyncio.run(main())

MFA Support

The library includes support for Multi-Factor Authentication:

# List MFA factorsfactors=client.mfa.list_factors() # Enroll a new MFA factorenrolled_factor=client.mfa.enroll({"factor_type": "totp"}) # Challenge and verify MFAchallenge=client.mfa.challenge({"factor_id": "factor_id"}) verified=client.mfa.verify({"factor_id": "factor_id", "code": "123456"}) # Unenroll a factorclient.mfa.unenroll({"factor_id": "factor_id"})

Contributions

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