GoTrue Python Client

2.12.4 · active · verified Thu Apr 09

The `gotrue` Python client is the official library for interacting with Supabase Auth (GoTrue), allowing Python applications to manage users, sessions, and authentication flows. It's a key component of the broader `supabase-py` client. Currently at version 2.12.4, the library maintains an active release cadence with frequent updates for bug fixes and new features.

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize the `GoTrueClient` and perform a user sign-up operation. Remember to replace placeholder URLs and keys with your actual Supabase project details, typically loaded from environment variables. Error handling for `GoTrueAPIError` is crucial for robust applications.

import os
from gotrue import GoTrueClient, GoTrueAPIError

# Initialize with your Supabase URL and (anon or service_role) key
SUPABASE_URL = os.environ.get('SUPABASE_URL', 'YOUR_SUPABASE_URL')
SUPABASE_ANON_KEY = os.environ.get('SUPABASE_ANON_KEY', 'YOUR_SUPABASE_ANON_KEY')

try:
    client = GoTrueClient(
        url=f"{SUPABASE_URL}/auth/v1",
        headers={
            "apikey": SUPABASE_ANON_KEY
        }
    )

    # Example: Sign up a new user
    email = "test@example.com"
    password = "verysecretpassword"
    
    response = client.sign_up(email=email, password=password)
    print(f"Sign-up successful: {response.user.id}")

    # You can also sign in existing users
    # response = client.sign_in(email=email, password=password)
    # print(f"Sign-in successful: {response.session.access_token}")

except GoTrueAPIError as e:
    print(f"GoTrue API Error: {e.message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →