Supabase Reference (Python) # Python Reference You can initialize a new Supabase client using the `create_client()` method. The Supabase client is your entrypoint to the rest of the Supabase functionality and is the easiest way to interact with everything we offer within the Supabase ecosystem. ## Examples ### create_client() ```python import os from supabase import create_client, Client url: str = os.environ.get("SUPABASE_URL") key: str = os.environ.get("SUPABASE_KEY") supabase: Client = create_client(url, key) ``` ### With timeout option ```python import os from supabase import create_client, Client from supabase.client import ClientOptions url: str = os.environ.get("SUPABASE_URL") key: str = os.environ.get("SUPABASE_KEY") supabase: Client = create_client( url, key, options=ClientOptions( postgrest_client_timeout=10, storage_client_timeout=10, schema="public", ) ) ``` # Python Reference Fetch data: select() ## Examples ### Getting your data ```python response = ( supabase.table("planets") .select("*") .execute() ) ``` ### Selecting specific columns ```python response = ( supabase.table("planets") .select("name") .execute() ) ``` ### Query referenced tables ```python response = ( supabase.table("orchestral_sections") .select("name, instruments(name)") .execute() ) ``` ### Query referenced tables through a join table ```python response = ( supabase.table("users") .select("name, teams(name)") .execute() ) ``` ### Query the same referenced table multiple times ```python response = ( supabase.table("messages") .select("content,from:sender_id(name),to:receiver_id(name)") .execute() ) ``` ### Filtering through referenced tables ```python response = ( supabase.table("orchestral_sections") .select("name, instruments(*)") .eq("instruments.name", "guqin") .execute() ) ``` ### Querying referenced table with count ```python response = ( supabase.table("orchestral_sections") .select("*, instruments(count)") .execute() ) ``` ### Querying with count option ```python response = ( supabase.table("planets") .select("*", count="exact") .execute() ) ``` ### Querying JSON data ```python response = ( supabase.table("users") .select("id, name, address->city") .execute() ) ``` ### Querying referenced table with inner join ```python response = ( supabase.table("instruments") .select("name, orchestral_sections!inner(name)") .eq("orchestral_sections.name", "woodwinds") .execute() ) ``` ### Switching schemas per query ```python response = ( supabase.schema("myschema") .table("mytable") .select("*") .execute() ) ``` # Python Reference Create data: insert() ## Examples ### Create a record ```python response = ( supabase.table("planets") .insert({"id": 1, "name": "Pluto"}) .execute() ) ``` ### Bulk create ```python try: response = ( supabase.table("characters") .insert([ {"id": 1, "name": "Frodo"}, {"id": 2, "name": "Sam"}, ]) .execute() ) return response except Exception as exception: return exception ``` # Python Reference Modify data: update() ## Examples ### Updating your data ```python response = ( supabase.table("instruments") .update({"name": "piano"}) .eq("id", 1) .execute() ) ``` ### Updating JSON data ```python response = ( supabase.table("users") .update({"address": {"street": "Melrose Place", "postcode": 90210}}) .eq("address->postcode", 90210) .execute() ) ``` # Python Reference Upsert data: upsert() ## Examples ### Upsert your data ```python response = ( supabase.table("instruments") .upsert({"id": 1, "name": "piano"}) .execute() ) ``` ### Bulk Upsert your data ```python response = ( supabase.table("instruments") .upsert([{"id": 1, "name": "piano"}, {"id": 2, "name": "guitar"}]) .execute() ) ``` ### Upserting into tables with constraints ```python response = ( supabase.table("users") .upsert( {"id": 42, "handle": "saoirse", "display_name": "Saoirse"}, on_conflict="handle", ) .execute() ) ``` # Python Reference Delete data: delete() ## Examples ### Delete records ```python response = ( supabase.table("countries") .delete() .eq("id", 1) .execute() ) ``` ### Delete multiple records ```python response = ( supabase.table("countries") .delete() .in_("id", [1, 2, 3]) .execute() ) ``` # Python Reference Postgres functions: rpc() You can call Postgres functions as _Remote Procedure Calls_, logic in your database that you can execute from anywhere. Functions are useful when the logic rarely changes—like for password resets and updates. ```sql create or replace function hello_world() returns text as $$ select 'Hello world'; $$ language sql; ``` ## Examples ### Call a Postgres function without arguments ```python response = ( supabase.rpc("hello_world") .execute() ) ``` ### Call a Postgres function with arguments ```python response = ( supabase.rpc("echo", { "say": "👋" }) .execute() ) ``` ### Bulk processing ```python response = ( supabase.rpc("add_one_each", {"arr": [1, 2, 3]}) .execute() ) ``` ### Call a Postgres function with filters ```python response = ( supabase.rpc("list_stored_planets") .eq("id", 1) .single() .execute() ) ``` ### Call a read-only Postgres function ```python response = ( supabase.rpc("hello_world", get=True) .execute() ) ``` # Python Reference Using Filters Filters allow you to only return rows that match certain conditions. Filters can be used on `select()`, `update()`, `upsert()`, and `delete()` queries. If a Postgres function returns a table response, you can also apply filters. ## Examples ### Applying Filters ```python # Correct response = ( supabase.table("instruments") .select("name, section_id") .eq("name", "flute") .execute() ) # Incorrect response = ( supabase.table("instruments") .eq("name", "flute") .select("name, section_id") .execute() ) ``` ### Chaining ```python response = ( supabase.table("instruments") .select("name, section_id") .gte("octave_range", 3) .lt("octave_range", 7) .execute() ) ``` ### Conditional chaining ```python filterByName = None filterOctaveLow = 3 filterOctaveHigh = 7 query = supabase.table("instruments").select("name, section_id") if filterByName: query = query.eq("name", filterByName) if filterAgeLow: query = query.gte("octave_range", filterOctaveLow) if filterAgeHigh: query = query.lt("octave_range", filterOctaveHigh) response = query.execute() ``` ### Filter by values within JSON column ```python response = ( supabase.table("users") .select("*") .eq("address->postcode", 90210) .execute() ) ``` ### Filter Foreign Tables ```python response = ( supabase.table("orchestral_sections") .select("name, instruments!inner(name)") .eq("instruments.name", "flute") .execute() ) ``` # Python Reference eq() Match only rows where `column` is equal to `value`. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .eq("name", "Earth") .execute() ) ``` # Python Reference neq() Match only rows where `column` is not equal to `value`. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .neq("name", "Earth") .execute() ) ``` # Python Reference gt() Match only rows where `column` is greather than `value`. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .gt("id", 2) .execute() ) ``` # Python Reference gte() Match only rows where `column` is greater than or equal to `value`. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .gte("id", 2) .execute() ) ``` # Python Reference lt() Match only rows where `column` is less than `value`. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .lt("id", 2) .execute() ) ``` # Python Reference lte() Match only rows where `column` is less than or equal to `value`. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .lte("id", 2) .execute() ) ``` # Python Reference like() Match only rows where `column` matches `pattern` case-sensitively. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .like("name", "%Ea%") .execute() ) ``` # Python Reference ilike() Match only rows where `column` matches `pattern` case-insensitively. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .ilike("name", "%ea%") .execute() ) ``` # Python Reference is_() Match only rows where `column` IS `value`. ## Examples ### Checking for nullness, True or False ```python response = ( supabase.table("planets") .select("*") .is_("name", "null") .execute() ) ``` # Python Reference in_() Match only rows where `column` is included in the `values` array. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .in_("name", ["Earth", "Mars"]) .execute() ) ``` # Python Reference contains() Only relevant for jsonb, array, and range columns. Match only rows where `column` contains every element appearing in `value`. ## Examples ### On array columns ```python response = ( supabase.table("issues") .select("*") .contains("tags", ["is:open", "priority:low"]) .execute() ) ``` ### On range columns ```python response = ( supabase.table("reservations") .select("*") .contains("during", "[2000-01-01 13:00, 2000-01-01 13:30)") .execute() ) ``` ### On `jsonb` columns ```python response = ( supabase.table("users") .select("*") .contains("address", {"postcode": 90210}) .execute() ) ``` # Python Reference contained_by() Only relevant for jsonb, array, and range columns. Match only rows where every element appearing in `column` is contained by `value`. ## Examples ### On array columns ```python response = ( supabase.table("classes") .select("name") .contained_by("days", ["monday", "tuesday", "wednesday", "friday"]) .execute() ) ``` ### On range columns ```python response = ( supabase.table("reservations") .select("*") .contained_by("during", "[2000-01-01 00:00, 2000-01-01 23:59)") .execute() ) ``` ### On `jsonb` columns ```python response = ( supabase.table("users") .select("name") .contained_by("address", {}) .execute() ) ``` # Python Reference range_gt() Only relevant for range columns. Match only rows where every element in `column` is greater than any element in `range`. ## Examples ### With `select()` ```python response = ( supabase.table("reservations") .select("*") .range_gt("during", ["2000-01-02 08:00", "2000-01-02 09:00"]) .execute() ) ``` # Python Reference range_gte() Only relevant for range columns. Match only rows where every element in `column` is either contained in `range` or greater than any element in `range`. ## Examples ### With `select()` ```python response = ( supabase.table("reservations") .select("*") .range_gte("during", ["2000-01-02 08:30", "2000-01-02 09:30"]) .execute() ) ``` # Python Reference range_lt() Only relevant for range columns. Match only rows where every element in `column` is less than any element in `range`. ## Examples ### With `select()` ```python response = ( supabase.table("reservations") .select("*") .range_lt("during", ["2000-01-01 15:00", "2000-01-01 16:00"]) .execute() ) ``` # Python Reference range_lte() Only relevant for range columns. Match only rows where every element in `column` is less than any element in `range`. ## Examples ### With `select()` ```python response = ( supabase.table("reservations") .select("*") .range_lte("during", ["2000-01-01 14:00", "2000-01-01 16:00"]) .execute() ) ``` # Python Reference range_adjacent() Only relevant for range columns. Match only rows where `column` is mutually exclusive to `range` and there can be no element between the two ranges. ## Examples ### With `select()` ```python response = ( supabase.table("reservations") .select("*") .range_adjacent("during", ["2000-01-01 12:00", "2000-01-01 13:00"]) .execute() ) ``` # Python Reference overlaps() Only relevant for array and range columns. Match only rows where `column` and `value` have an element in common. ## Examples ### On array columns ```python response = ( supabase.table("issues") .select("title") .overlaps("tags", ["is:closed", "severity:high"]) .execute() ) ``` ### On range columns ```python response = ( supabase.table("reservations") .select("*") .overlaps("during", "[2000-01-01 12:45, 2000-01-01 13:15)") .execute() ) ``` # Python Reference text_search() Only relevant for text and tsvector columns. Match only rows where `column` matches the query string in `query`. ## Examples ### Text search ```python response = ( supabase.table("texts") .select("content") .text_search( "content", "'eggs' & 'ham'", options={"config": "english"}, ) .execute() ) ``` ### Basic normalization ```python response = ( supabase.table("quotes") .select("catchphrase") .text_search( "catchphrase", "'fat' & 'cat'", options={"type": "plain", "config": "english"}, ) .execute() ) ``` ### Full normalization ```python response = ( supabase.table("quotes") .select("catchphrase") .text_search( "catchphrase", "'fat' & 'cat'", options={"type": "phrase", "config": "english"}, ) .execute() ) ``` ### Websearch ```python response = ( supabase.table("quotes") .select("catchphrase") .text_search( "catchphrase", "'fat or cat'", options={"type": "websearch", "config": "english"}, ) .execute() ) ``` # Python Reference match() Match only rows where each column in `query` keys is equal to its associated value. Shorthand for multiple `.eq()`s. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .match({"id": 2, "name": "Earth"}) .execute() ) ``` # Python Reference not_() Match only rows which doesn't satisfy the filter. `not_` expects you to use the raw PostgREST syntax for the filter values. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .not_.is_("name", "null") .execute() ) ``` # Python Reference or_() ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("name") .or_("id.eq.2,name.eq.Mars") .execute() ) ``` ### Use `or` with `and` ```python response = ( supabase.table("planets") .select("name") .or_("id.gt.3,and(id.eq.1,name.eq.Mercury)") .execute() ) ``` ### Use `or` on referenced tables ```python response = ( supabase.table("orchestral_sections") .select("name, instruments!inner(name)") .or_("book_id.eq.1,name.eq.guqin", reference_table="instruments") .execute() ) ``` # Python Reference filter() ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .filter("name", "in", '("Mars","Tatooine")') .execute() ) ``` ### On a foreign table ```python response = ( supabase.table("orchestral_sections") .select("name, instruments!inner(name)") .filter("instruments.name", "eq", "flute") .execute() ) ``` # Python Reference Using Modifiers Filters work on the row level—they allow you to return rows that only match certain conditions without changing the shape of the rows. Modifiers are everything that don't fit that definition—allowing you to change the format of the response (e.g., returning a CSV string). Modifiers must be specified after filters. Some modifiers only apply for queries that return rows (e.g., `select()` or `rpc()` on a function that returns a table response). ## Examples # Python Reference order() Order the query result by `column`. ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .order("name", desc=True) .execute() ) ``` ### On a foreign table ```python response = ( supabase.table("orchestral_sections") .select("name, instruments(name)") .order("name", desc=True, foreign_table="instruments") .execute() ) ``` ### Order parent table by a referenced table ```python response = ( supabase.table("instruments") .select("name, section:orchestral_sections(name)") .order("section(name)", desc=False) ) ``` # Python Reference limit() ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("name") .limit(1) .execute() ) ``` ### On a foreign table ```python response = ( supabase.table("orchestral_sections") .select("name, instruments(name)") .limit(1, foreign_table="instruments") .execute() ) ``` # Python Reference range() ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("name") .range(0, 1) .execute() ) ``` ### On a foreign table ```python response = ( supabase.table("orchestral_sections") .select("name, instruments(name)") .range(0, 1, foreign_table="instruments") .execute() ) ``` # Python Reference single() ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("name") .limit(1) .single() .execute() ) ``` # Python Reference maybe_single() ## Examples ### With `select()` ```python response = ( supabase.table("planets") .select("*") .eq("name", "Earth") .maybe_single() .execute() ) ``` # Python Reference csv() ## Examples ### Return data as CSV ```python response = ( supabase.table("planets") .select("*") .csv() .execute() ) ``` # Python Reference Using Explain For debugging slow queries, you can get the [Postgres `EXPLAIN` execution plan](https://www.postgresql.org/docs/current/sql-explain.html) of a query using the `explain()` method. This works on any query, even for `rpc()` or writes. Explain is not enabled by default as it can reveal sensitive information about your database. It's best to only enable this for testing environments but if you wish to enable it for production you can provide additional protection by using a `pre-request` function. Follow the [Performance Debugging Guide](/docs/guides/database/debugging-performance) to enable the functionality on your project. ## Examples ### Get the execution plan ```python response = ( supabase.table("planets") .select("*") .explain() .execute() ) ``` ### Get the execution plan with analyze and verbose ```python response = ( supabase.table("planets") .select("*") .explain(analyze=True, verbose=True) .execute() ) ``` # Python Reference Overview ## Examples # Python Reference sign_up() ## Examples ### Sign up with an email and password ```python response = supabase.auth.sign_up( { "email": "email@example.com", "password": "password", } ) ``` ### Sign up with a phone number and password (SMS) ```python response = supabase.auth.sign_up( { "phone": "123456789", "password": "password", } ) ``` ### Sign up with a phone number and password (whatsapp) ```python response = supabase.auth.sign_up( { "phone": "123456789", "password": "password", "options": {"channel": "whatsapp"}, } ) ``` ### Sign up with additional user metadata ```python response = supabase.auth.sign_up( { "email": "email@example.com", "password": "password", "options": {"data": {"first_name": "John", "age": 27}}, } ) ``` ### Sign up with a redirect URL ```python response = supabase.auth.sign_up( { "email": "hello1@example.com", "password": "password", "options": { "email_redirect_to": "https://example.com/welcome", }, } ) ``` # Python Reference sign_in_anonymously() ## Examples ### Create an anonymous user ```python response = supabase.auth.sign_in_anonymously( {"options": {"captcha_token": ""}} ) ``` ### Create an anonymous user with custom user metadata ```python response = supabase.auth.sign_in_anonymously( {"options": {"data": {}}} ) ``` # Python Reference sign_in_with_password ## Examples ### Sign in with email and password ```python response = supabase.auth.sign_in_with_password( { "email": "email@example.com", "password": "example-password", } ) ``` ### Sign in with phone and password ```python response = supabase.auth.sign_in_with_password( { "phone": "+13334445555", "password": "some-password", } ) ``` # Python Reference sign_in_with_id_token ## Examples ### Sign In using ID Token ```python response = supabase.auth.sign_in_with_id_token( { "provider": "google", "token": "your-id-token", } ) ``` # Python Reference sign_in_with_otp ## Examples ### Sign in with email ```python response = supabase.auth.sign_in_with_otp( { "email": "email@example.com", "options": { "email_redirect_to": "https://example.com/welcome", }, } ) ``` ### Sign in with SMS OTP ```python response = supabase.auth.sign_in_with_otp( {"phone": "+13334445555"} ) ``` ### Sign in with WhatsApp OTP ```python response = supabase.auth.sign_in_with_otp( { "phone": "+13334445555", "options": { "channel": "whatsapp", }, } ) ``` # Python Reference sign_in_with_oauth ## Examples ### Sign in using a third-party provider ```python response = supabase.auth.sign_in_with_oauth( {"provider": "github"} ) ``` ### Sign in using a third-party provider with redirect ```python response = supabase.auth.sign_in_with_oauth( { "provider": "github", "options": { "redirect_to": "https://example.com/welcome", } } ) ``` ### Sign in with scopes ```python response = supabase.auth.sign_in_with_oauth( { "provider": "github", "options": { "scopes": "repo gist notifications", } } ) ``` # Python Reference sign_in_with_sso() ## Examples ### Sign in with email domain ```python response = supabase.auth.sign_in_with_sso( {"domain": "company.com"} ) ``` ### Sign in with provider UUID ```python response = supabase.auth.sign_in_with_sso( {"provider_id": "21648a9d-8d5a-4555-a9d1-d6375dc14e92"} ) ``` # Python Reference sign_out() ## Examples ### Sign out ```python response = supabase.auth.sign_out() ``` # Python Reference reset_password_for_email() ## Examples ### Reset password ```python supabase.auth.reset_password_for_email( email, { "redirect_to": "https://example.com/update-password", } ) ``` # Python Reference verify_otp ## Examples ### Verify Signup One-Time Password (OTP) ```python response = supabase.auth.verify_otp( { "email": "email@example.com", "token": "123456", "type": "email", } ) ``` ### Verify SMS One-Time Password (OTP) ```python response = supabase.auth.verify_otp( { "phone": "+13334445555", "token": "123456", "type": "sms", } ) ``` ### Verify Email Auth (Token Hash) ```python response = supabase.auth.verify_otp( { "email": "email@example.com", "token_hash": "", "type": "email", } ) ``` # Python Reference get_session ## Examples ### Get the session data ```python response = supabase.auth.get_session() ``` # Python Reference refresh_session() Returns a new session, regardless of expiry status. Takes in an optional refresh token. If not passed in, then refresh_session() will attempt to retrieve it from get_session(). If the current session's refresh token is invalid, an error will be thrown. ## Examples ### Refresh session using the current session ``` response = supabase.auth.refresh_session() ``` # Python Reference get_user ## Examples ### Get the logged in user with the current existing session ``` response = supabase.auth.get_user() ``` ### Get the logged in user with a custom access token jwt ``` response = supabase.auth.get_user(jwt) ``` # Python Reference update_user() ## Examples ### Update the email for an authenticated user ```python response = supabase.auth.update_user( {"email": "new@email.com"} ) ``` ### Update the phone number for an authenticated user ```python response = supabase.auth.update_user( {"phone": "123456789"} ) ``` ### Update the password for an authenticated user ```python response = supabase.auth.update_user( {"password": "new password"} ) ``` ### Update the user's metadata ```python response = supabase.auth.update_user( { "data": {"hello": "world"}, } ) ``` ### Update the user's password with a nonce ```python response = supabase.auth.update_user( { "password": "new password", "nonce": "123456", } ) ``` # Python Reference get_user_identities() ## Examples ### Returns a list of identities linked to the user ```python response = supabase.auth.get_user_identities() ``` # Python Reference link_identity() ## Examples ### Link an identity to a user ```python response = supabase.auth.link_identity( {provider: "github"} ) ``` # Python Reference unlink_identity() ## Examples ### Unlink an identity ```python # retrieve all identites linked to a user response = supabase.auth.get_user_identities() # find the google identity google_identity = list( filter(lambda identity: identity.provider == "google", res.identities) ).pop() # unlink the google identity response = supabase.auth.unlink_identity(google_identity) ``` # Python Reference reauthenticate() ## Examples ### Send reauthentication nonce ```python response = supabase.auth.reauthenticate() ``` # Python Reference resend() ## Examples ### Resend an email signup confirmation ```python response = supabase.auth.resend( { "type": "signup", "email": "email@example.com", "options": { "email_redirect_to": "https://example.com/welcome", }, } ) ``` ### Resend a phone signup confirmation ```python response = supabase.auth.resend( { "type": "sms", "phone": "1234567890", } ) ``` ### Resend email change email ```python response = supabase.auth.resend( { "type": "email_change", "email": "email@example.com", } ) ``` ### Resend phone change OTP ```python response = supabase.auth.resend( { "type": "phone_change", "phone": "1234567890", } ) ``` # Python Reference set_session() Sets the session data from the current session. If the current session is expired, setSession will take care of refreshing it to obtain a new session. If the refresh token or access token in the current session is invalid, an error will be thrown. ## Examples ### Refresh the session ```python response = supabase.auth.set_session(access_token, refresh_token) ``` # Python Reference exchange_code_for_session() ## Examples ### Exchange Auth Code ```python response = supabase.auth.exchange_code_for_session( {"auth_code": "34e770dd-9ff9-416c-87fa-43b31d7ef225"} ) ``` # Python Reference Overview ## Examples # Python Reference mfa.enroll() ## Examples ### Enroll a time-based, one-time password (TOTP) factor ```python response = supabase.auth.mfa.enroll( { "factor_type": "totp", "friendly_name": "your_friendly_name", } ) ``` # Python Reference mfa.challenge() ## Examples ### Create a challenge for a factor ```python response = supabase.auth.mfa.challenge( {"factor_id": "34e770dd-9ff9-416c-87fa-43b31d7ef225"} ) ``` # Python Reference mfa.verify() ## Examples ### Verify a challenge for a factor ```python response = supabase.auth.mfa.verify( { "factor_id": "34e770dd-9ff9-416c-87fa-43b31d7ef225", "challenge_id": "4034ae6f-a8ce-4fb5-8ee5-69a5863a7c15", "code": "123456", } ) ``` # Python Reference mfa.challenge_and_verify() ## Examples ### Create and verify a challenge for a factor ```python response = supabase.auth.mfa.challenge_and_verify( { "factor_id": "34e770dd-9ff9-416c-87fa-43b31d7ef225", "code": "123456", } ) ``` # Python Reference mfa.unenroll() ## Examples ### Unenroll a factor ```python response = supabase.auth.mfa.unenroll( {"factor_id": "34e770dd-9ff9-416c-87fa-43b31d7ef225"} ) ``` # Python Reference mfa.get_authenticator_assurance_level() ## Examples ### Get the AAL details of a session ```python response = supabase.auth.mfa.get_authenticator_assurance_level() ``` # Python Reference Overview ## Examples ### Create server-side auth client ```python from supabase import create_client from supabase.lib.client_options import ClientOptions supabase = create_client( supabase_url, service_role_key, options=ClientOptions( auto_refresh_token=False, persist_session=False, ) ) # Access auth admin api admin_auth_client = supabase.auth.admin ``` # Python Reference get_user_by_id() ## Examples ### Fetch the user object using the access_token jwt ```python response = supabase.auth.admin.get_user_by_id(1) ``` # Python Reference list_users() ## Examples ### Get a page of users ```python response = supabase.auth.admin.list_users() ``` ### Paginated list of users ```python response = supabase.auth.admin.list_users( page=1, per_page=1000, ) ``` # Python Reference create_user() ## Examples ### With custom user metadata ```python response = supabase.auth.admin.create_user( { "email": "user@email.com", "password": "password", "user_metadata": {"name": "Yoda"}, } ) ``` ### Auto-confirm the user's email ```python response = supabase.auth.admin.create_user( { "email": "user@email.com", "email_confirm": True, } ) ``` ### Auto-confirm the user's phone number ```python response = supabase.auth.admin.create_user( { "phone": "1234567890", "phone_confirm": True, } ) ``` # Python Reference delete_user() Delete a user. Requires a `service_role` key. ## Examples ### Removes a user ```python supabase.auth.admin.delete_user( "715ed5db-f090-4b8c-a067-640ecee36aa0" ) ``` # Python Reference invite_user_by_email() Sends an invite link to an email address. ## Examples ### Invite a user ```python response = supabase.auth.admin.invite_user_by_email("email@example.com") ``` # Python Reference generate_link() ## Examples ### Generate a signup link ```python response = supabase.auth.admin.generate_link( { "type": "signup", "email": "email@example.com", "password": "secret", } ) ``` ### Generate an invite link ```python response = supabase.auth.admin.generate_link( { "type": "invite", "email": "email@example.com", } ) ``` ### Generate a magic link ```python response = supabase.auth.admin.generate_link( { "type": "magiclink", "email": "email@example.com", } ) ``` ### Generate a recovery link ```python response = supabase.auth.admin.generate_link( { "type": "recovery", "email": "email@example.com", } ) ``` ### Generate links to change current email address ```python # Generate an email change link to be sent to the current email address response = supabase.auth.admin.generate_link( { "type": "email_change_current", "email": "current.email@example.com", "new_email": "new.email@example.com", } ) # Generate an email change link to be sent to the new email address response = supabase.auth.admin.generate_link( { "type": "email_change_new", "email": "current.email@example.com", "new_email": "new.email@example.com", } ) ``` # Python Reference update_user_by_id() ## Examples ### Updates a user's email ```python response = supabase.auth.admin.update_user_by_id( "11111111-1111-1111-1111-111111111111", { "email": "new@email.com", } ) ``` ### Updates a user's password ```python response = supabase.auth.admin.update_user_by_id( "6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4", { "password": "new_password", } ) ``` ### Updates a user's metadata ```python response = supabase.auth.admin.update_user_by_id( "6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4", { "user_metadata": {"hello": "world"}, } ) ``` ### Updates a user's app_metadata ```python response = supabase.auth.admin.update_user_by_id( "6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4", { "app_metadata": {"plan": "trial"}, } ) ``` ### Confirms a user's email address ```python response = supabase.auth.admin.update_user_by_id( "6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4", { "email_confirm": True, } ) ``` ### Confirms a user's phone number ```python response = supabase.auth.admin.update_user_by_id( "6aa5d0d4-2a9f-4483-b6c8-0cf4c6c98ac4", { "phone_confirm": True, } ) ``` # Python Reference mfa.delete_factor() ## Examples ### Delete a factor for a user ```python response = supabase.auth.admin.mfa.delete_factor( { "id": "34e770dd-9ff9-416c-87fa-43b31d7ef225", "user_id": "a89baba7-b1b7-440f-b4bb-91026967f66b" } ) ``` # Python Reference invoke() Invoke a Supabase Function. ## Examples ### Basic invocation ```python response = supabase.functions.invoke( "hello-world", invoke_options={ "body": {"name": "Functions"}, }, ) ``` ### Error handling ```python from supafunc.errors import FunctionsRelayError, FunctionsHttpError try: response = supabase.functions.invoke( "hello-world", invoke_options={ "body": {"foo": "bar"}, "headers": {"my-custom-header": "my-custom-header-value"}, }, ) except FunctionsHttpError as exception: err = exception.to_dict() print(f'Function returned an error {err.get("message")}') except FunctionsRelayError as exception: err = exception.to_dict() print(f'Relay error: {err.get("message")}') ``` ### Passing custom headers ```python response = supabase.functions.invoke( "hello-world", invoke_options={ "headers": { "my-custom-header": "my-custom-header-value", }, "body": {"foo": "bar"}, }, ) ``` # Python Reference on().subscribe() ## Examples ### Listen to broadcast messages ```python channel = supabase.channel("room1") def on_subscribe(status, err): if status == RealtimeSubscribeStates.SUBSCRIBED: channel.send_broadcast( "cursor-pos", {"x": random.random(), "y": random.random()} ) def handle_broadcast(payload): print("Cursor position received!", payload) channel.on_broadcast(event="cursor-pos", callback=handle_broadcast).subscribe(on_subscribe) ``` ### Listen to presence sync ```python channel = supabase.channel("room1") def on_subscribe(status, err): if status == RealtimeSubscribeStates.SUBSCRIBED: channel.track({"online_at": datetime.datetime.now().isoformat()}) def handle_presence_sync(): print("Synced presence state: ", channel.presence.state) channel.on_presence_sync(callback=handle_presence_sync).subscribe(on_subscribe) ``` ### Listen to presence join ```python channel = supabase.channel("room1") def handle_presence_join(key, current_presence, new_presence): print("Newly joined presences: ", new_presence) def on_subscribe(status, err): if status == RealtimeSubscribeStates.SUBSCRIBED: channel.track({"online_at": datetime.datetime.now().isoformat()}) channel.on_presence_join(callback=handle_presence_join).subscribe(on_subscribe) ``` ### Listen to presence leave ```python channel = supabase.channel("room1") def handle_presence_leave(key, current_presence, left_presence): print("Newly left presences: ", left_presence) def on_subscribe(status, err): if status == RealtimeSubscribeStates.SUBSCRIBED: channel.track({"online_at": datetime.datetime.now().isoformat()}) channel.untrack() channel.on_presence_leave(callback=handle_presence_leave).subscribe(on_subscribe) ``` ### Listen to all database changes ```python response = ( supabase.channel("room1") .on_postgres_changes("*", schema="*", callback=handle_record_updated) .subscribe() ) ``` ### Listen to a specific table ```python response = ( supabase.channel("room1") .on_postgres_changes("*", schema="public", table="countries", callback=handle_record_updated) .subscribe() ) ``` ### Listen to inserts ```python response = ( supabase.channel("room1") .on_postgres_changes("INSERT", schema="public", table="countries", callback=handle_record_inserted) .subscribe() ) ``` ### Listen to updates ```python response = ( supabase.channel("room1") .on_postgres_changes("UPDATE", schema="public", table="countries", callback=handle_record_updated) .subscribe() ) ``` ### Listen to deletes ```python response = ( supabase.channel("room1") .on_postgres_changes("DELETE", schema="public", table="countries", callback=handle_record_deleted) .subscribe() ) ``` ### Listen to multiple events ```python response = ( supabase.channel("room1") .on_postgres_changes("INSERT", schema="public", table="countries", callback=handle_record_inserted) .on_postgres_changes("DELETE", schema="public", table="countries", callback=handle_record_deleted) .subscribe() ) ``` ### Listen to row level changes ```python response = ( supabase.channel("room1") .on_postgres_changes("UPDATE", schema="public", table="countries", filter="id=eq.200", callback=handle_record_updated) .subscribe() ) ``` # Python Reference removeChannel() ## Examples ### Removes a channel ```python supabase.remove_channel(myChannel) ``` # Python Reference removeAllChannels() ## Examples ### Remove all channels ```python supabase.remove_all_channels() ``` # Python Reference getChannels() ## Examples ### Get all channels ```python channels = supabase.get_channels() ``` # Python Reference broadcastMessage() Broadcast a message to all connected clients to a channel. ## Examples ### Send a message via websocket ```python channel = supabase.channel("room1") def on_subscribe(status, err): if status == RealtimeSubscribeStates.SUBSCRIBED: channel.send_broadcast('cursor-pos', {"x": random.random(), "y": random.random()}) channel.subscribe(on_subscribe) ``` # Python Reference create_bucket() Creates a new Storage bucket ## Examples ### Create bucket ```python response = ( supabase.storage .create_bucket( "avatars", options={ "public": False, "allowed_mime_types": ["image/png"], "file_size_limit": 1024, } ) ) ``` # Python Reference get_bucket() Retrieves the details of an existing Storage bucket. ## Examples ### Get bucket ```python response = supabase.storage.get_bucket("avatars") ``` # Python Reference list_buckets() Retrieves the details of all Storage buckets within an existing project. ## Examples ### List buckets ```python response = supabase.storage.list_buckets() ``` # Python Reference update_bucket() Updates a Storage bucket ## Examples ### Update bucket ```python response = ( supabase.storage .update_bucket( "avatars", options={ "public": False, "allowed_mime_types": ["image/png"], "file_size_limit": 1024, } ) ) ``` # Python Reference delete_bucket() Deletes an existing bucket. A bucket can't be deleted with existing objects inside it. You must first `empty()` the bucket. ## Examples ### Delete bucket ```python response = supabase.storage.delete_bucket("avatars") ``` # Python Reference empty_bucket() Removes all objects inside a single bucket. ## Examples ### Empty bucket ```python response = supabase.storage.empty_bucket("avatars") ``` # Python Reference from_.upload() Uploads a file to an existing bucket. ## Examples ### Upload file using filepath ```python with open("./public/avatar1.png", "rb") as f: response = ( supabase.storage .from_("avatars") .upload( file=f, path="public/avatar1.png", file_options={"cache-control": "3600", "upsert": "false"} ) ) ``` # Python Reference from_.download() Downloads a file from a private bucket. For public buckets, make a request to the URL returned from `get_public_url` instead. ## Examples ### Download file ```python with open("./myfolder/avatar1.png", "wb+") as f: response = ( supabase.storage .from_("avatars") .download("folder/avatar1.png") ) f.write(response) ``` ### Download file with transformations ```python with open("./myfolder/avatar1.png", "wb+") as f: response = ( supabase.storage .from_("avatars") .download( "folder/avatar1.png", {"transform": {"width": 100, "height": 100, "quality": 80}}, ) ) f.write(response) ``` # Python Reference from_.list() Lists all the files within a bucket. ## Examples ### List files in a bucket ```python response = ( supabase.storage .from_("avatars") .list( "folder", { "limit": 100, "offset": 0, "sortBy": {"column": "name", "order": "desc"}, } ) ) ``` ### Search files in a bucket ```python response = ( supabase.storage .from_("avatars") .list( "folder", { "limit": 100, "offset": 0, "sortBy": {"column": "name", "order": "desc"}, "search": "jon", } ) ) ``` # Python Reference from_.update() Replaces an existing file at the specified path with a new one. ## Examples ### Update file ```python with open("./public/avatar1.png", "rb") as f: response = ( supabase.storage .from_("avatars") .update( file=f, path="public/avatar1.png", file_options={"cache-control": "3600", "upsert": "true"} ) ) ``` # Python Reference from_.move() Moves an existing file to a new path in the same bucket. ## Examples ### Move file ```python response = ( supabase.storage .from_("avatars") .move( "public/avatar1.png", "private/avatar2.png" ) ) ``` # Python Reference from_.copy() Copies an existing file to a new path in the same bucket. ## Examples ### Copy file ```python response = ( supabase.storage .from_("avatars") .copy( "public/avatar1.png", "private/avatar2.png" ) ) ``` # Python Reference from_.remove() Deletes files within the same bucket ## Examples ### Delete file ```python response = ( supabase.storage .from_("avatars") .remove(["folder/avatar1.png"]) ) ``` # Python Reference from_.create_signed_url() Creates a signed URL for a file. Use a signed URL to share a file for a fixed amount of time. ## Examples ### Create Signed URL ```python response = ( supabase.storage .from_("avatars") .create_signed_url( "folder/avatar1.png", 60 ) ) ``` ### Create a signed URL for an asset with transformations ```python response = ( supabase.storage .from_("avatars") .create_signed_url( "folder/avatar1.png", 60, {"transform": {"width": 100, "height": 100}} ) ) ``` ### Create a signed URL which triggers the download of the asset ```python response = ( supabase.storage .from_("avatars") .create_signed_url( "folder/avatar1.png", 60, {"download": True} ) ) ``` # Python Reference from_.create_signed_urls() Creates multiple signed URLs. Use a signed URL to share a file for a fixed amount of time. ## Examples ### Create Signed URLs ```python response = ( supabase.storage .from_("avatars") .create_signed_urls( ["folder/avatar1.png", "folder/avatar2.png"], 60 ) ) ``` # Python Reference from_.create_signed_upload_url() Creates a signed upload URL. Signed upload URLs can be used to upload files to the bucket without further authentication. They are valid for 2 hours. ## Examples ### Create Signed URL ```python response = ( supabase.storage .from_("avatars") .create_signed_upload_url("folder/avatar1.png") ) ``` # Python Reference from_.upload_to_signed_url() Upload a file with a token generated from `create_signed_upload_url`. ## Examples ### Create Signed URL ```python with open("./public/avatar1.png", "rb") as f: response = ( supabase.storage .from_("avatars") .upload_to_signed_url( path="folder/cat.jpg", token="token-from-create_signed_upload_url", file=f, ) ) ``` # Python Reference from_.get_public_url() A simple convenience function to get the URL for an asset in a public bucket. If you do not want to use this function, you can construct the public URL by concatenating the bucket URL with the path to the asset. This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset. ## Examples ### Returns the URL for an asset in a public bucket ```python response = ( supabase.storage .from_("avatars") .get_public_url("folder/avatar1.jpg") ) ``` ### Returns the URL for an asset in a public bucket with transformations ```python response = ( supabase.storage .from_("avatars") .get_public_url( "folder/avatar1.jpg", {"transform": {"width": 100, "height": 100}} ) ) ``` ### Returns the URL which triggers the download of an asset in a public bucket ```python response = ( supabase.storage .from_("avatars") .get_public_url( "folder/avatar1.jpg", {"download": True} ) ) ```