Warning
This repository has been moved to the supabase-py monorepo.
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.
The package can be installed using pip or poetry:
poetry add supabase_authpip install supabase_auth- 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
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.
The library provides both synchronous and asynchronous clients. Here are some examples:
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"}})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())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"})We would be immensely grateful for any contributions to this project.