| ======================== |
| CODE SNIPPETS |
| ======================== |
| TITLE: Install Supabase Python Client via pip |
| DESCRIPTION: This snippet shows how to install the `supabase-py` package using pip, the Python package installer. This is the standard way to install Python libraries from PyPI. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_3 |
|
|
| LANGUAGE: bash |
| CODE: |
| ``` |
| # with pip |
| pip install supabase |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Install Supabase Python Client in Editable Mode |
| DESCRIPTION: This snippet explains how to install the `supabase-py` package locally in 'editable' mode using `pip install -e`. This is useful for development, as changes made to the source code are immediately reflected in the installed package without reinstallation. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_5 |
|
|
| LANGUAGE: bash |
| CODE: |
| ``` |
| pip install -e |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Install Supabase Python Client via Conda |
| DESCRIPTION: This snippet demonstrates how to install the `supabase-py` package using Conda from the `conda-forge` channel. This method is suitable for users who prefer Conda for package management. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_4 |
|
|
| LANGUAGE: bash |
| CODE: |
| ``` |
| # with conda |
| conda install -c conda-forge supabase |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Initialize Supabase Python Client |
| DESCRIPTION: This Python snippet demonstrates how to initialize the Supabase client using the `create_client` function. It retrieves the Supabase URL and API key from environment variables, which is a recommended practice for security. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_7 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| 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) |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Sign Up a New User with Supabase Auth |
| DESCRIPTION: This Python snippet shows how to register a new user with an email and password using the Supabase authentication service. The `sign_up` method returns the user object upon successful creation. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_8 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| user = supabase.auth.sign_up({ "email": users_email, "password": users_password }) |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Clone Supabase Python Client Repository |
| DESCRIPTION: This snippet demonstrates how to clone the `supabase-py` GitHub repository to your local machine and navigate into its directory, which is the first step for local development. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_0 |
|
|
| LANGUAGE: bash |
| CODE: |
| ``` |
| git clone https://github.com/supabase/supabase-py.git |
| cd supabase-py |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Create and Activate Python Virtual Environment (venv) |
| DESCRIPTION: This snippet shows how to create and activate a Python virtual environment using the built-in `venv` module. A virtual environment isolates project dependencies, preventing conflicts with other Python projects. The activation command differs slightly for Windows. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_1 |
|
|
| LANGUAGE: bash |
| CODE: |
| ``` |
| python3 -m venv env |
| source env/bin/activate # On Windows, use .\env\Scripts\activate |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Execute Supabase-py Test Suite |
| DESCRIPTION: This command runs the test scripts for the Supabase Python client library. It connects to a pre-populated test database instance, which includes a `countries` table. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_22 |
|
|
| LANGUAGE: bash |
| CODE: |
| ``` |
| ./test.sh |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Create and Activate Conda Environment |
| DESCRIPTION: This snippet demonstrates how to create and activate a dedicated Conda environment for the `supabase-py` project. Conda is a popular package, dependency, and environment management system for multiple languages. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_2 |
|
|
| LANGUAGE: bash |
| CODE: |
| ``` |
| conda create --name supabase-py |
| conda activate supabase-py |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Set Supabase Environment Variables |
| DESCRIPTION: This snippet shows how to set the `SUPABASE_URL` and `SUPABASE_KEY` environment variables in your shell. These variables are crucial for the Supabase client to connect to your specific Supabase instance securely. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_6 |
|
|
| LANGUAGE: bash |
| CODE: |
| ``` |
| export SUPABASE_URL="my-url-to-my-awesome-supabase-instance" |
| export SUPABASE_KEY="my-supa-dupa-secret-supabase-api-key" |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Sign In an Existing User with Supabase Auth |
| DESCRIPTION: This Python snippet demonstrates how to authenticate an existing user using their email and password via the Supabase authentication service. The `sign_in_with_password` method returns the authenticated user object. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_9 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| user = supabase.auth.sign_in_with_password({ "email": users_email, "password": users_password }) |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Supabase Python Storage Bucket API Module Definition |
| DESCRIPTION: This entry specifies the API documentation for the `supabase.lib.storage.storage_bucket_api` module. It utilizes Sphinx's `automodule` directive to automatically generate documentation for all public members and display the inheritance hierarchy of classes within the module. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/docs/storage_bucket.rst#_snippet_0 |
|
|
| LANGUAGE: APIDOC |
| CODE: |
| ``` |
| .. automodule:: supabase.lib.storage.storage_bucket_api |
| :members: |
| :show-inheritance: |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: List Files in Supabase Storage Bucket |
| DESCRIPTION: This Python snippet demonstrates how to list all files within a specified Supabase Storage bucket. It provides an overview of the bucket's contents. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_19 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| bucket_name: str = "charts" |
|
|
| data = supabase.storage.from_(bucket_name).list() |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Download File from Supabase Storage |
| DESCRIPTION: This Python snippet demonstrates how to download a file from a specified Supabase Storage bucket. It uses the `download` method, providing the file path within the bucket. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_16 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| bucket_name: str = "photos" |
|
|
| data = supabase.storage.from_(bucket_name).download("photo1.png") |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Select Data from Supabase Table |
| DESCRIPTION: This Python snippet demonstrates how to query and retrieve data from a Supabase table. It uses the `select` method to specify columns (or all with `*`) and `eq` to filter results based on a condition, followed by `execute()`. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_11 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| data = supabase.table("countries").select("*").eq("country", "IL").execute() |
|
|
| # Assert we pulled real data. |
| assert len(data.data) > 0 |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Supabase Python Query Builder Module API Reference |
| DESCRIPTION: This entry documents the `supabase.lib.query_builder` module using Sphinx's `automodule` directive. This directive automatically generates comprehensive API documentation, including all public members and the inheritance hierarchy for the specified Python module. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/docs/query_builder.rst#_snippet_0 |
|
|
| LANGUAGE: APIDOC |
| CODE: |
| ``` |
| .. automodule:: supabase.lib.query_builder |
| :members: |
| :show-inheritance: |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Upload File to Supabase Storage |
| DESCRIPTION: This Python snippet shows how to upload a new file to a Supabase Storage bucket. It specifies the destination path within the bucket and the file content to be uploaded. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_17 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| bucket_name: str = "photos" |
| new_file = getUserFile() |
|
|
| data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file) |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Insert Data into Supabase Table |
| DESCRIPTION: This Python snippet illustrates how to insert a new row into a specified Supabase table. It uses the `insert` method, chaining it with `execute()` to perform the operation and retrieve the result. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_10 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| data = supabase.table("countries").insert({"name":"Germany"}).execute() |
|
|
| # Assert we pulled real data. |
| assert len(data.data) > 0 |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Invoke Supabase Edge Function |
| DESCRIPTION: This Python snippet shows how to call a Supabase Edge Function by its name using the `invoke` method. It includes error handling for `FunctionsRelayError` and `FunctionsHttpError`, demonstrating how to catch and print function-related exceptions. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_15 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| def test_func(): |
| try: |
| resp = supabase.functions.invoke("hello-world", invoke_options={'body':{}}) |
| return resp |
| except (FunctionsRelayError, FunctionsHttpError) as exception: |
| err = exception.to_dict() |
| print(err.get("message")) |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Move and Rename Files in Supabase Storage |
| DESCRIPTION: This Python snippet shows how to move a file from one path to another within a Supabase Storage bucket, effectively allowing for renaming or reorganizing files. It requires both the old and new file paths. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_20 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| bucket_name: str = "charts" |
| old_file_path: str = "generic/graph1.png" |
| new_file_path: str = "important/revenue.png" |
|
|
| data = supabase.storage.from_(bucket_name).move(old_file_path, new_file_path) |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Proper Supabase Client Shutdown in Python |
| DESCRIPTION: To ensure the Supabase client terminates correctly and to prevent resource leaks, you must explicitly call the `sign_out()` method on the `auth` object of your client instance. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_21 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| client.auth.sign_out() |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Upsert Data into Supabase Table |
| DESCRIPTION: This Python snippet demonstrates how to perform an 'upsert' operation, which inserts a new row if it doesn't exist or updates it if it does. It's useful for handling data with potential duplicate keys gracefully. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_13 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| country = { |
| "country": "United Kingdom", |
| "capital_city": "London" # This was missing when it was added |
| } |
|
|
| data = supabase.table("countries").upsert(country).execute() |
| assert len(data.data) > 0 |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Update Data in Supabase Table |
| DESCRIPTION: This Python snippet shows how to update existing rows in a Supabase table. It uses the `update` method with a dictionary of new values and `eq` to specify which rows to update based on a condition. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_12 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| data = supabase.table("countries").update({"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute() |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Remove Files from Supabase Storage |
| DESCRIPTION: This Python snippet illustrates how to delete one or more files from a Supabase Storage bucket. It accepts a list of file paths to be removed. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_18 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| bucket_name: str = "photos" |
|
|
| data = supabase.storage.from_(bucket_name).remove(["old_photo.png", "image5.jpg"]) |
| ``` |
|
|
| ---------------------------------------- |
|
|
| TITLE: Delete Data from Supabase Table |
| DESCRIPTION: This Python snippet illustrates how to delete rows from a Supabase table. It uses the `delete` method combined with `eq` to specify the criteria for deletion. |
|
|
| SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_14 |
|
|
| LANGUAGE: python |
| CODE: |
| ``` |
| data = supabase.table("countries").delete().eq("id", 1).execute() |
| ``` |