Python Reference v2.0

Python Client Library

@supabase-community/supabase-py

This reference documents every object and method available in the supabase-py library from the Supabase community. You can use supabase-py to test with your Postgres database, listen to database changes, invoke Deno Edge Functions, build login and user management functionality, and manage large files.

The Python client library is created and maintained by the Supabase community, and is not an official library. Please be tolerant of areas where the library is still being developed, and — as with all the libraries — feel free to contribute wherever you find issues.

Huge thanks to official maintainers, anand2312, dreinon, J0, and Leynier.

Shoutout to timkpaine for maintaining our Conda libraries as well.

Installing

Install with PyPi

You can install supabase-py via the terminal. (for > Python 3.7)

Terminal

_10
pip install supabase

Initializing

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.

Parameters
    supabase_url
    REQUIRED
    string

    The unique Supabase URL which is supplied when you create a new project in your project dashboard.

    supabase_key
    REQUIRED
    string

    The unique Supabase Key which is supplied when you create a new project in your project dashboard.

    options
    Optional
    ClientOptions

    Options to change the Auth behaviors.


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)

Fetch data

  • By default, Supabase projects return a maximum of 1,000 rows. This setting can be changed in your project's API settings. It's recommended that you keep it low to limit the payload size of accidental or malicious requests. You can use range() queries to paginate through your data.
  • select() can be combined with Filters
  • select() can be combined with Modifiers
  • apikey is a reserved keyword if you're using the Supabase Platform and should be avoided as a column name.
Parameters
    columns
    Optional
    string

    The columns to retrieve, defaults to *.

    count
    Optional
    CountMethod

    The property to use to get the count of rows returned.


response = supabase.table("countries").select("*").execute()

Insert data

Parameters
    json
    REQUIRED
    dict, list

    The values to insert. Pass an dict to insert a single row or an list to insert multiple rows.

    count
    Optional
    CountMethod

    The property to use to get the count of rows returned.

    returning
    Optional
    ReturnMethod

    Either 'minimal' or 'representation'. Defaults to 'representation'.

    default_to_null
    Optional
    bool

    Make missing fields default to null. Otherwise, use the default value for the column. Only applies for bulk inserts.


response = (
    supabase.table("countries")
    .insert({"id": 1, "name": "Denmark"})
    .execute()
)

Update data

  • update() should always be combined with Filters to target the item(s) you wish to update.
Parameters
    json
    REQUIRED
    dict, list

    The values to insert. Pass an dict to insert a single row or an list to insert multiple rows.

    count
    Optional
    CountMethod

    The property to use to get the count of rows returned.

    returning
    Optional
    ReturnMethod

    Either 'minimal' or 'representation'. Defaults to 'representation'.

    ignore_duplicates
    Optional
    bool

    Whether duplicate rows should be ignored.

    on_conflict
    Optional
    bool

    Specified columns to be made to work with UNIQUE constraint.

    default_to_null
    Optional
    bool

    Make missing fields default to null. Otherwise, use the default value for the column. This only applies when inserting new rows, not when merging with existing rows under ignore_duplicates: false. This also only applies when doing bulk upserts.


response = (
    supabase.table("countries")
    .update({"name": "Australia"})
    .eq("id", 1)
    .execute()
)

Upsert data

  • Primary keys must be included in the values dict to use upsert.
Parameters
    json
    REQUIRED
    dict, list

    The values to insert. Pass an dict to insert a single row or an list to insert multiple rows.

    count
    Optional
    CountMethod

    The property to use to get the count of rows returned.

    returning
    Optional
    ReturnMethod

    Either 'minimal' or 'representation'. Defaults to 'representation'.

    ignore_duplicates
    Optional
    bool

    Whether duplicate rows should be ignored.

    on_conflict
    Optional
    bool

    Specified columns to be made to work with UNIQUE constraint.

    default_to_null
    Optional
    bool

    Make missing fields default to null. Otherwise, use the default value for the column. Only applies for bulk inserts.


response = (
    supabase.table("countries")
    .upsert({"id": 1, "name": "Australia"})
    .execute()
)

Delete data

  • delete() should always be combined with filters to target the item(s) you wish to delete.
  • If you use delete() with filters and you have RLS enabled, only rows visible through SELECT policies are deleted. Note that by default no rows are visible, so you need at least one SELECT/ALL policy that makes the rows visible.
  • When using delete().in_(), specify an array of values to target multiple rows with a single query. This is particularly useful for batch deleting entries that share common criteria, such as deleting users by their IDs. Ensure that the array you provide accurately represents all records you intend to delete to avoid unintended data removal.
Parameters
    count
    Optional
    CountMethod

    The property to use to get the count of rows returned.

    returning
    Optional
    ReturnMethod

    Either 'minimal' or 'representation'. Defaults to 'representation'.


response = supabase.table('countries').delete().eq('id', 1).execute()

Call a Postgres function

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.

create or replace function hello_world() returns text as $$
  select 'Hello world';
$$ language sql;
Parameters
    fn
    REQUIRED
    callable

    The stored procedure call to be executed.

    params
    Optional
    dict of any

    Parameters passed into the stored procedure call.

    get
    Optional
    dict of any

    When set to true, data will not be returned. Useful if you only need the count.

    head
    Optional
    dict of any

    When set to true, the function will be called with read-only access mode.

    count
    Optional
    CountMethod

    Count algorithm to use to count rows returned by the function. Only applicable for set-returning functions. "exact": Exact but slow count algorithm. Performs a COUNT(*) under the hood. "planned": Approximated but fast count algorithm. Uses the Postgres statistics under the hood. "estimated": Uses exact count for low numbers and planned count for high numbers.


response = supabase.rpc("hello_world").execute()

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.


# Correct
response = (
    supabase.table("cities")
    .select("name, country_id")
    .eq("name", "Bali")
    .execute()
)

# Incorrect
response = (
    supabase.table("cities")
    .eq("name", "Bali")
    .select("name, country_id")
    .execute()
)

Column is equal to a value

Match only rows where column is equal to value.

Parameters
    column
    REQUIRED
    string

    The column to filter on

    value
    REQUIRED
    any

    The value to filter by


response = supabase.table("countries").select("*").eq("name", "Albania").execute()

Column is not equal to a value

Match only rows where column is not equal to value.

Parameters
    column
    REQUIRED
    string

    The column to filter on

    value
    REQUIRED
    any

    The value to filter by


response = supabase.table("countries").select("*").neq("name", "Albania").execute()

Column is greater than a value

Match only rows where column is greather than value.

Parameters
    column
    REQUIRED
    string

    The column to filter on

    value
    REQUIRED
    any

    The value to filter by


response = supabase.table("countries").select("*").gt("id", 2).execute()

Column is greater than or equal to a value

Match only rows where column is greater than or equal to value.

Parameters
    column
    REQUIRED
    string

    The column to filter on

    value
    REQUIRED
    any

    The value to filter by


response = supabase.table("countries").select("*").gte("id", 2).execute()

Column is less than a value

Match only rows where column is less than value.

Parameters
    column
    REQUIRED
    string

    The column to filter on

    value
    REQUIRED
    any

    The value to filter by


response = supabase.table("countries").select("*").lt("id", 2).execute()

Column is less than or equal to a value

Match only rows where column is less than or equal to value.

Parameters
    column
    REQUIRED
    string

    The column to filter on

    value
    REQUIRED
    any

    The value to filter by


response = supabase.table("countries").select("*").lte("id", 2).execute()

Column matches a pattern

Match only rows where column matches pattern case-sensitively.

Parameters
    column
    REQUIRED
    string

    The name of the column to apply a filter on

    pattern
    REQUIRED
    string

    The pattern to match by


response = supabase.table("countries").select("*").like("name", "%Alba%").execute()

Column matches a case-insensitive pattern

Match only rows where column matches pattern case-insensitively.

Parameters
    column
    REQUIRED
    string

    The name of the column to apply a filter on

    pattern
    REQUIRED
    string

    The pattern to match by


response = supabase.table("countries").select("*").ilike("name", "%alba%").execute()

Column is a value

Match only rows where column IS value.

Parameters
    column
    REQUIRED
    string

    The name of the column to apply a filter on

    value
    REQUIRED
    null | boolean

    The value to match by


response = supabase.table("countries").select("*").is_("name", "null").execute()

Column is in an array

Match only rows where column is included in the values array.

Parameters
    column
    REQUIRED
    string

    The column to filter on

    values
    REQUIRED
    array

    The values to filter by


response = (
    supabase.table("countries")
    .select("*")
    .in_("name", ["Albania", "Algeria"])
    .execute()
)

Column contains every element in a value

Only relevant for jsonb, array, and range columns. Match only rows where column contains every element appearing in value.

Parameters
    column
    REQUIRED
    string

    The column to filter on

    values
    REQUIRED
    object

    The jsonb, array, or range value to filter with


response = (
    supabase.table("issues")
    .select("*")
    .contains("tags", ["is:open", "priority:low"])
    .execute()
)

Contained by value

Only relevant for jsonb, array, and range columns. Match only rows where every element appearing in column is contained by value.

Parameters
    column
    REQUIRED
    string

    The jsonb, array, or range column to filter on

    value
    REQUIRED
    object

    The jsonb, array, or range value to filter with


response = (
    supabase.table("classes")
    .select("name")
    .contained_by("days", ["monday", "tuesday", "wednesday", "friday"])
    .execute()
)

Greater than a range

Only relevant for range columns. Match only rows where every element in column is greater than any element in range.

Parameters
    column
    REQUIRED
    string

    The range column to filter on

    range
    REQUIRED
    array

    The range to filter with


response = (
    supabase.table("reservations")
    .select("*")
    .range_gt("during", ["2000-01-02 08:00", "2000-01-02 09:00"])
    .execute()
)

Greater than or equal to a range

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.

Parameters
    column
    REQUIRED
    string

    The range column to filter on

    range
    REQUIRED
    string

    The range to filter with


response = (
    supabase.table("reservations")
    .select("*")
    .range_gte("during", ["2000-01-02 08:30", "2000-01-02 09:30"])
    .execute()
)

Less than a range

Only relevant for range columns. Match only rows where every element in column is less than any element in range.

Parameters
    column
    REQUIRED
    string

    The range column to filter on

    range
    REQUIRED
    array

    The range to filter with


response = (
    supabase.table("reservations")
    .select("*")
    .range_lt("during", ["2000-01-01 15:00", "2000-01-01 16:00"])
    .execute()
)

Less than or equal to a range

Only relevant for range columns. Match only rows where every element in column is less than any element in range.

Parameters
    column
    REQUIRED
    string

    The range column to filter on

    range
    REQUIRED
    array

    The range to filter with


response = (
    supabase.table("reservations")
    .select("*")
    .range_lte("during", ["2000-01-01 14:00", "2000-01-01 16:00"])
    .execute()
)

Mutually exclusive to a range

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.

Parameters
    column
    REQUIRED
    string

    The range column to filter on

    range
    REQUIRED
    array

    The range to filter with


response = (
    supabase.table("reservations")
    .select("*")
    .range_adjacent("during", ["2000-01-01 12:00", "2000-01-01 13:00"])
    .execute()
)

With a common element

Only relevant for array and range columns. Match only rows where column and value have an element in common.

Parameters
    column
    REQUIRED
    string

    The array or range column to filter on

    value
    REQUIRED
    Iterable[Any]

    The array or range value to filter with


response = (
    supabase.table("issues")
    .select("title")
    .overlaps("tags", ["is:closed", "severity:high"])
    .execute()
)

Match a string

Only relevant for text and tsvector columns. Match only rows where column matches the query string in query.

Parameters
    column
    REQUIRED
    string

    The text or tsvector column to filter on

    query
    REQUIRED
    string

    The query text to match with

    options
    Optional
    object

    Named parameters

Match an associated value

Match only rows where each column in query keys is equal to its associated value. Shorthand for multiple .eq()s.

Parameters
    query
    REQUIRED
    dict

    The object to filter with, with column names as keys mapped to their filter values


response = (
    supabase.table("countries")
    .select("*")
    .match({"id": 2, "name": "Albania"})
    .execute()
)

Don't match the filter

Match only rows which doesn't satisfy the filter. not_ expects you to use the raw PostgREST syntax for the filter values.

1.not_.in_('id', '(5,6,7)')  # Use `()` for `in` filter
2.not_.contains('arraycol', '{"a","b"}')  # Use `{}` for array values

response = (
    supabase.table("countries")
    .select("*")
    .not_.is_("name", "null")
    .execute()
)

Match at least one filter

or_() expects you to use the raw PostgREST syntax for the filter names and values.

1.or_('id.in.(5,6,7), arraycol.cs.{"a","b"}')  # Use `()` for `in` filter, `{}` for array values and `cs` for `contains()`.
2.or_('id.in.(5,6,7), arraycol.cd.{"a","b"}')  # Use `cd` for `containedBy()`
Parameters
    filters
    REQUIRED
    string

    The filters to use, following PostgREST syntax

    reference_table
    Optional
    string

    Set this to filter on referenced tables instead of the parent table


response = (
    supabase.table("countries")
    .select("name")
    .or_("id.eq.2,name.eq.Algeria")
    .execute()
)

Match the filter

filter() expects you to use the raw PostgREST syntax for the filter values.

1.filter('id', 'in', '(5,6,7)')  # Use `()` for `in` filter
2.filter('arraycol', 'cs', '{"a","b"}')  # Use `cs` for `contains()`, `{}` for array values
Parameters
    column
    REQUIRED
    string

    The column to filter on

    operator
    Optional
    string

    The operator to filter with, following PostgREST syntax

    value
    Optional
    any

    The value to filter with, following PostgREST syntax


response = (
    supabase.table("countries")
    .select("*")
    .filter("name", "in", '("Algeria","Japan")')
    .execute()
)

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).

Order the results

Order the query result by column.

Parameters
    column
    REQUIRED
    string

    The column to order by

    desc
    Optional
    bool

    Whether the rows should be ordered in descending order or not.

    foreign_table
    Optional
    string

    Foreign table name whose results are to be ordered.

    nullsfirst
    Optional
    bool

    Order by showing nulls first


response = (
    supabase.table("countries")
    .select("*")
    .order("name", desc=True)
    .execute()
)

Limit the number of rows returned

Parameters
    size
    REQUIRED
    number

    The maximum number of rows to return

    foreign_table
    Optional
    string

    Set this to limit rows of foreign tables instead of the parent table.


response = supabase.table("countries").select("name").limit(1).execute()

Limit the query to a range

Limit the query result by starting at an offset (from) and ending at the offset (from + to). Only records within this range are returned. This respects the query order and if there is no order clause the range could behave unexpectedly.

The from and to values are 0-based and inclusive: range(1, 3) will include the second, third and fourth rows of the query.

Parameters
    start
    REQUIRED
    number

    The starting index from which to limit the result.

    end
    REQUIRED
    number

    The last index to which to limit the result.

    foreign_table
    Optional
    string

    Set this to limit rows of foreign tables instead of the parent table.


response = supabase.table("countries").select("name").range(0, 1).execute()

Retrieve one row of data

Return data as a single object instead of an array of objects.


response = supabase.table("countries").select("name").limit(1).single().execute()

Retrieve zero or one row of data

Return data as a single object instead of an array of objects.


response = (
    supabase.table("countries")
    .select("*")
    .eq("name", "Albania")
    .maybe_single()
    .execute()
)

Retrieve as a CSV

Return data as a string in CSV format.


response = supabase.table("countries").select("*").csv().execute()

Using explain

For debugging slow queries, you can get the Postgres EXPLAIN execution plan 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 to enable the functionality on your project.

Parameters
    wal
    Optional
    boolean

    If true, include information on WAL record generation.

    verbose
    Optional
    boolean

    If true, the query identifier will be returned and data will include the output columns of the query.

    settings
    Optional
    boolean

    If true, include information on configuration parameters that affect query planning.

    format
    Optional
    boolean

    The format of the output, can be "text" (default) or "json".

    format
    Optional
    "text" | "json"

    The format of the output, can be "text" (default) or "json".

    buffers
    Optional
    boolean

    If true, include information on buffer usage.

    analyze
    Optional
    boolean

    If true, the query will be executed and the actual run time will be returned.


response = supabase.table("countries").select("*").explain().execute()

Error codes

Supabase Auth can throw or return various errors when using the API. All errors originating from the supabase.auth namespace of the JavaScript client library will be wrapped by the AuthError class.

Error objects are split in a few classes:

  • AuthApiError -- errors which originate from the Supabase Auth API.
    • Use isAuthApiError instead of instanceof checks to see if an error you caught is of this type.
  • CustomAuthError -- errors which generally originate from state in the client library.
    • Use the name property on the error to identify the class of error received.

Errors originating from the server API classed as AuthApiError always have a code property that can be used to identify the error returned by the server. The status property is also present, encoding the HTTP status code received in the response.

In general the HTTP status codes you will likely receive are:

  • 403 Forbidden is sent out in rare situations where a certain Auth feature is not available for the user, and you as the developer are not checking a precondition whether that API is available for the user.
  • 422 Unprocessable Entity is sent out when the API request is accepted, but cannot be processed because the user or Auth server is in a state where it cannot satisfy the request.
  • 429 Too Many Requests is sent out when rate-limits are breached for an API. You should handle this status code often, especially in functions that authenticate a user.
  • 500 Internal Server Error often means that the Auth server's service is degraded. Most often it points to issues in your database setup such as a misbehaving trigger on a schema, function, view or other database object.
  • 501 Not Implemented is sent out when a feature is not enabled on the Auth server, and you are trying to use an API which requires it.

To supplement HTTP status codes, Supabase Auth returns a string error code which gives you more insight into what went wrong. These codes are stable and can be used to present an internationalized message to your users.

CodeDescription
bad_code_verifierReturned from the PKCE flow where the provided code verifier does not match the expected one. Indicates a bug in the implementation of the client library.
bad_jsonUsually used when the HTTP body of the request is not valid JSON.
bad_jwtJWT sent in the Authorization header is not valid.
bad_oauth_callbackOAuth callback from provider to Auth does not have all the required attributes (state). Indicates an issue with the OAuth provider or client library implementation.
bad_oauth_stateOAuth state (data echoed back by the OAuth provider to Supabase Auth) is not in the correct format. Indicates an issue with the OAuth provider integration.
captcha_failedCaptcha challenge could not be verified with the captcha provider. Check your captcha integration.
conflictGeneral database conflict, such as concurrent requests on resources that should not be modified concurrently. Can often occur when you have too many session refresh requests firing off at the same time for a user. Check your app for concurrency issues, and if detected back off exponentially.
email_conflict_identity_not_deletableUnlinking this identity causes the user's account to change to an email address which is already used by another user account. Indicates an issue where the user has two different accounts using different primary email addresses. You may need to migrate user data to one of their accounts in this case.
email_existsEmail address already exists in the system.
email_not_confirmedSigning in is not allowed for this user as the email address is not confirmed.
email_provider_disabledSignups are disabled for email and password.
flow_state_expiredPKCE flow state to which the API request relates has expired. Ask the user to sign in again.
flow_state_not_foundPKCE flow state to which the API request relates no longer exists. Flow states expire after a while and are progressively cleaned up, which can cause this error. Retried requests can cause this error, as the previous request likely destroyed the flow state. Ask the user to sign in again.
identity_already_existsThe identity to which the API relates is already linked to a user.
identity_not_foundIdentity to which the API call relates does not exist, such as when an identity is unlinked or deleted.
insufficient_aalTo call this API, the user must have a higher Authenticator Assurance Level. To resolve, ask the user to solve an MFA challenge.
invite_not_foundInvite is expired or already used.
manual_linking_disabledCalling the supabase.auth.linkUser() and related APIs is not enabled on the Auth server.
mfa_challenge_expiredResponding to an MFA challenge should happen within a fixed time period. Request a new challenge when encountering this error.
mfa_factor_name_conflictMFA factors for a single user should not have the same friendly name.
mfa_factor_not_foundMFA factor no longer exists.
mfa_ip_address_mismatchThe enrollment process for MFA factors must begin and end with the same IP address.
mfa_verification_failedMFA challenge could not be verified -- wrong TOTP code.
mfa_verification_rejectedFurther MFA verification is rejected. Only returned if the MFA verification attempt hook returns a reject decision.
no_authorizationThis HTTP request requires an Authorization header, which is not provided.
not_adminUser accessing the API is not admin, i.e. the JWT does not contain a role claim that identifies them as an admin of the Auth server.
oauth_provider_not_supportedUsing an OAuth provider which is disabled on the Auth server.
otp_disabledSign in with OTPs (magic link, email OTP) is disabled. Check your sever's configuration.
otp_expiredOTP code for this sign-in has expired. Ask the user to sign in again.
over_email_send_rate_limitToo many emails have been sent to this email address. Ask the user to wait a while before trying again.
over_request_rate_limitToo many requests have been sent by this client (IP address). Ask the user to try again in a few minutes. Sometimes can indicate a bug in your application that mistakenly sends out too many requests (such as a badly written useEffect React hook).
over_sms_send_rate_limitToo many SMS messages have been sent to this phone number. Ask the user to wait a while before trying again.
phone_existsPhone number already exists in the system.
phone_not_confirmedSigning in is not allowed for this user as the phone number is not confirmed.
phone_provider_disabledSignups are disabled for phone and password.
provider_disabledOAuth provider is disabled for use. Check your server's configuration.
provider_email_needs_verificationNot all OAuth providers verify their user's email address. Supabase Auth requires emails to be verified, so this error is sent out when a verification email is sent after completing the OAuth flow.
reauthentication_neededA user needs to reauthenticate to change their password. Ask the user to reauthenticate by calling the supabase.auth.reauthenticate() API.
reauthentication_not_validVerifying a reauthentication failed, the code is incorrect. Ask the user to enter a new code.
same_passwordA user that is updating their password must use a different password than the one currently used.
saml_assertion_no_emailSAML assertion (user information) was received after sign in, but no email address was found in it which is required. Check the provider's attribute mapping and/or configuration.
saml_assertion_no_user_idSAML assertion (user information) was received after sign in, but a user ID (called NameID) was not found in it which is required. Check the SAML identity provider's configuration.
saml_entity_id_mismatch(Admin API.) Updating the SAML metadata for a SAML identity provider is not possible, as the entity ID in the update does not match the entity ID in the database. This is equivalent to creating a new identity provider, and you should do that instead.
saml_idp_already_exists(Admin API.) Adding a SAML identity provider that is already added.
saml_idp_not_foundSAML identity provider not found. Most often returned after IdP-initiated sign-in with an unregistered SAML identity provider in Supabase Auth.
saml_metadata_fetch_failed(Admin API.) Adding or updating a SAML provider failed as its metadata could not be fetched from the provided URL.
saml_provider_disabledUsing Enterprise SSO with SAML 2.0 is not enabled on the Auth server.
saml_relay_state_expiredSAML relay state is an object that tracks the progress of a supabase.auth.signInWithSSO() request. The SAML identity provider should respond after a fixed amount of time, after which this error is shown. Ask the user to sign in again.
saml_relay_state_not_foundSAML relay states are progressively cleaned up after they expire, which can cause this error. Ask the user to sign in again.
session_not_foundSession to which the API request relates no longer exists. This can occur if the user has signed out, or the session entry in the database was deleted in some other way.
signup_disabledSign ups (new account creation) is disabled on the server.
single_identity_not_deletableEvery user must have at least one identity attached to it, so deleting (unlinking) an identity is not allowed if it's the only one for the user.
sms_send_failedSending an SMS message failed. Check your SMS provider configuration.
sso_domain_already_exists(Admin API.) Only one SSO domain can be registered per SSO identity provider.
sso_provider_not_foundSSO provider not found. Check the arguments in supabase.auth.signInWithSSO().
too_many_enrolled_mfa_factorsA user can only have a fixed number of enrolled MFA factors.
unexpected_audience(Deprecated feature not available via Supabase JavaScript client.) The request's X-JWT-AUD claim does not match the JWT's audience.
unexpected_failureAuth service is degraded or a bug is present, without a specific reason.
user_already_existsUser with this information (email address, phone number) cannot be created again as it already exists.
user_bannedUser to which the API request relates has a banned_until property which is still active. No further API requests should be attempted until this field is cleared.
user_not_foundUser to which the API request relates no longer exists.
user_sso_managedWhen a user comes from SSO, certain fields of the user cannot be updated (like email).
validation_failedProvided parameters are not in the expected format.
weak_passwordUser is signing up or changing their password without meeting the password strength criteria. Use the AuthWeakPasswordError class to access more information about what they need to do to make the password pass.

Tips for better error handling

  • Do not use string matching on error messages! Always use the name and code properties of error objects to identify the situation.
  • Although HTTP status codes generally don't change, they can suddenly change due to bugs, so avoid relying on them unless absolutely necessary.

Create a new user

  • By default, the user needs to verify their email address before logging in. To turn this off, disable Confirm email in your project.
  • Confirm email determines if users need to confirm their email address after signing up.
    • If Confirm email is enabled, a user is returned but session is null.
    • If Confirm email is disabled, both a user and a session are returned.
  • By default, when the user confirms their email address, they are redirected to the SITE_URL. You can modify your SITE_URL or add additional redirect URLs in your project.
  • If sign_up() is called for an existing confirmed user:
    • When both Confirm email and Confirm phone (even when phone provider is disabled) are enabled in your project, an obfuscated/fake user object is returned.
    • When either Confirm email or Confirm phone (even when phone provider is disabled) is disabled, the error message, User already registered is returned.
  • To fetch the currently logged-in user, refer to get_user().
Parameters
    credentials
    REQUIRED
    SignUpWithPasswordCredentials

response = supabase.auth.sign_up(
    credentials={"email": "hello@example.com", "password": "password"}
)

Create an anonymous user

  • Returns an anonymous user
  • It is recommended to set up captcha for anonymous sign-ins to prevent abuse. You can pass in the captcha token in the options param.
Parameters
    credentials
    REQUIRED
    SignInAnonymouslyCredentials

response = supabase.auth.sign_in_anonymously(
    credentials={"options": {"captcha_token": ""}}
)

Sign in a user

  • Requires either an email and password or a phone number and password.

data = supabase.auth.sign_in_with_password({"email": "j0@supabase.io", "password": "testsupabasenow"})

Sign in a user through OTP

  • Requires either an email or phone number.
  • This method is used for passwordless sign-ins where a OTP is sent to the user's email or phone number.
  • If the user doesn't exist, sign_in_with_otp() will signup the user instead. To restrict this behavior, you can set should_create_user in SignInWithPasswordlessCredentials.options to false.
  • If you're using an email, you can configure whether you want the user to receive a magiclink or a OTP.
  • If you're using phone, you can configure whether you want the user to receive a OTP.
  • The magic link's destination URL is determined by the SITE_URL.
  • See redirect URLs and wildcards to add additional redirect URLs to your project.
  • Magic links and OTPs share the same implementation. To send users a one-time code instead of a magic link, modify the magic link email template to include {{ .Token }} instead of {{ .ConfirmationURL }}.

data = supabase.auth.sign_in_with_otp({
  "email": 'example@email.com',
  "options": {
    "email_redirect_to": 'https://example.com/welcome'
  }
})

Sign in a user through OAuth

  • This method is used for signing in using a third-party provider.
  • Supabase supports many different third-party providers.

data = supabase.auth.sign_in_with_oauth({
  "provider": 'github'
})

Sign out a user

  • In order to use the signOut() method, the user needs to be signed in first.

res = supabase.auth.sign_out()

Verify and log in through OTP

  • The verify_otp method takes in different verification types. If a phone number is used, the type can either be sms or phone_change. If an email address is used, the type can be one of the following: signup, magiclink, recovery, invite or email_change.
  • The verification type used should be determined based on the corresponding auth method called before verify_otp to sign up / sign-in a user.

res = supabase.auth.verify_otp(phone, token)

Retrieve a session


res = supabase.auth.get_session()

Retrieve a new session

  • This method will refresh the session whether the current one is expired or not.

res = supabase.auth.refresh_session()

Retrieve a user

  • This method gets the user object from the current session.
  • Fetches the user object from the database instead of local session.

data = supabase.auth.get_user()

Set the session data

  • setSession() takes in a refresh token and uses it to get a new session.
  • The refresh token can only be used once to obtain a new session.
  • Refresh token rotation is enabled by default on all projects to guard against replay attacks.
  • You can configure the REFRESH_TOKEN_REUSE_INTERVAL which provides a short window in which the same refresh token can be used multiple times in the event of concurrency or offline issues.

res = supabase.auth.set_session(access_token, refresh_token)

Auth MFA

This section contains methods commonly used for Multi-Factor Authentication (MFA) and are invoked behind the supabase.auth.mfa namespace.

Currently, we only support time-based one-time password (TOTP) as the 2nd factor. We don't support recovery codes but we allow users to enroll more than 1 TOTP factor, with an upper limit of 10.

Having a 2nd TOTP factor for recovery frees the user of the burden of having to store their recovery codes somewhere. It also reduces the attack surface since multiple recovery codes are usually generated compared to just having 1 backup TOTP factor.

Enroll a factor

  • Currently, totp is the only supported factor_type. The returned id should be used to create a challenge.
  • To create a challenge, see mfa.challenge().
  • To verify a challenge, see mfa.verify().
  • To create and verify a challenge in a single step, see mfa.challenge_and_verify().

res = supabase.auth.mfa.enroll({
  "factor_type": "totp",
  "friendly_name": "your_friendly_name"
})

Create a challenge


res = supabase.auth.mfa.challenge({
  "factor_id": '34e770dd-9ff9-416c-87fa-43b31d7ef225'
})

Verify a challenge


res = supabase.auth.mfa.verify({
  "factor_id": '34e770dd-9ff9-416c-87fa-43b31d7ef225',
  "challenge_id": '4034ae6f-a8ce-4fb5-8ee5-69a5863a7c15',
  "code": '123456'
})

Create and verify a challenge


res = supabase.auth.mfa.challenge_and_verify({
  "factor_id": '34e770dd-9ff9-416c-87fa-43b31d7ef225',
  "code": '123456'
})

Unenroll a factor


res = supabase.auth.mfa.unenroll({
  "factor_id": '34e770dd-9ff9-416c-87fa-43b31d7ef225',
})

Get Authenticator Assurance Level

  • Authenticator Assurance Level (AAL) is the measure of the strength of an authentication mechanism.
  • In Supabase, having an AAL of aal1 refers to having the 1st factor of authentication such as an email and password or OAuth sign-in while aal2 refers to the 2nd factor of authentication such as a time-based, one-time-password (TOTP).
  • If the user has a verified factor, the next_level field will return aal2, else, it will return aal1.

res = supabase.auth.mfa.get_authenticator_assurance_level()

Invokes a Supabase Edge Function.

Invoke a Supabase Function.

  • Requires an Authorization header.
  • When you pass in a body to your function, we automatically attach the Content-Type header for Blob, ArrayBuffer, File, FormData and String. If it doesn't match any of these types we assume the payload is json, serialise it and attach the Content-Type header as application/json. You can override this behaviour by passing in a Content-Type header of your own.

response = supabase.functions.invoke(
    "hello-world", invoke_options={"body": {"name": "Functions"}}
)

Create a bucket

  • RLS policy permissions required:
    • buckets table permissions: insert
    • objects table permissions: none
  • Refer to the Storage guide on how access control works

res = supabase.storage.create_bucket(name)

Retrieve a bucket

  • RLS policy permissions required:
    • buckets table permissions: select
    • objects table permissions: none
  • Refer to the Storage guide on how access control works

res = supabase.storage.get_bucket(name)

List all buckets

  • RLS policy permissions required:
    • buckets table permissions: select
    • objects table permissions: none
  • Refer to the Storage guide on how access control works

res = supabase.storage.list_buckets()

Delete a bucket

  • RLS policy permissions required:
    • buckets table permissions: select and delete
    • objects table permissions: none
  • Refer to the Storage guide on how access control works

res = supabase.storage.delete_bucket(name)

Empty a bucket

  • RLS policy permissions required:
    • buckets table permissions: select
    • objects table permissions: select and delete
  • Refer to the Storage guide on how access control works

res = supabase.storage.empty_bucket(name)

Upload a file

  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: insert
  • Refer to the Storage guide on how access control works
  • Please specify the appropriate content MIME type if you are uploading images or audio. If no file_options are specified, the MIME type defaults to text/html.

with open(filepath, 'rb') as f:
    supabase.storage.from_("testbucket").upload(file=f,path=path_on_supastorage, file_options={"content-type": "audio/mpeg"})

Download a file

  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: select
  • Refer to the Storage guide on how access control works

with open(destination, 'wb+') as f:
  res = supabase.storage.from_('bucket_name').download(source)
  f.write(res)

List all files in a bucket

  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: select
  • Refer to the Storage guide on how access control works

res = supabase.storage.from_('bucket_name').list()

Replace an existing file

  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: update and select
  • Refer to the Storage guide on how access control works

with open(filepath, 'rb') as f:
  supabase.storage.from_("bucket_name").update(file=f, path=path_on_supastorage, file_options={"cache-control": "3600", "upsert": "true"})

Move an existing file

  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: update and select
  • Refer to the Storage guide on how access control works

res = supabase.storage.from_('bucket_name').move('public/avatar1.png', 'private/avatar2.png')

Delete files in a bucket

  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: delete and select
  • Refer to the Storage guide on how access control works

res = supabase.storage.from_('bucket_name').remove('test.jpg')

Create a signed URL

  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: select
  • Refer to the Storage guide on how access control works

res = supabase.storage.from_('bucket_name').create_signed_url(filepath, expiry_duration)

Retrieve public URL

  • The bucket needs to be set to public, either via updateBucket() or by going to Storage on supabase.com/dashboard, clicking the overflow menu on a bucket and choosing "Make public"
  • RLS policy permissions required:
    • buckets table permissions: none
    • objects table permissions: none
  • Refer to the Storage guide on how access control works

res = supabase.storage.from_('bucket_name').get_public_url('test/avatar1.jpg')

Release Notes

The community is actively working on the library and we will be upgrading the Authentication library, gotrue-py, to mirror the Supabase-js v2 lib.

Storage Transformations

We currently support image transformations in our storage library.