### Start Local PostgREST Server with Docker Compose Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/README.md Use this command to start a local PostgREST server for development purposes. Ensure Docker Compose is installed. ```sh docker-compose up ``` -------------------------------- ### Install postgrest-py with Pip Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/README.md Standard installation method using pip. This command installs the postgrest library. ```sh pip install postgrest ``` -------------------------------- ### Install Supabase Realtime Client Source: https://github.com/supabase/supabase-py/blob/main/src/realtime/README.md Install the realtime package using pip or uv. ```bash pip3 install realtime ``` ```bash uv add realtime ``` -------------------------------- ### Install postgrest-py with poetry Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/index.md Use this command to install the library using poetry. ```default poetry add postgrest-py ``` -------------------------------- ### Install postgrest-py with uv Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/README.md Recommended installation method using the uv package manager. This command adds the postgrest library to your project. ```sh uv add postgrest ``` -------------------------------- ### Install postgrest-py with pip Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/index.md Use this command to install the library using pip. ```default pip install postgrest-py ``` -------------------------------- ### Install Supabase Auth with Uv Source: https://github.com/supabase/supabase-py/blob/main/src/auth/README.md Add the supabase_auth package to your project using uv. ```bash uv add supabase_auth ``` -------------------------------- ### Install supabase-py with uv Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Install the supabase-py package using the uv package manager. ```bash uv add supabase ``` -------------------------------- ### Install Supabase Auth with Pip Source: https://github.com/supabase/supabase-py/blob/main/src/auth/README.md Install the supabase_auth package using pip. ```bash pip install supabase_auth ``` -------------------------------- ### Install Supabase Auth with Poetry Source: https://github.com/supabase/supabase-py/blob/main/src/auth/README.md Add the supabase_auth package to your project using Poetry. ```bash poetry add supabase_auth ``` -------------------------------- ### Initialize AsyncPostgrestClient and Fetch Data Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/README.md Example of initializing the asynchronous PostgREST client and fetching all data from the 'countries' table. Requires an active PostgREST server at http://localhost:3000. ```python import asyncio from postgrest import AsyncPostgrestClient async def main(): async with AsyncPostgrestClient("http://localhost:3000") as client: r = await client.from_("countries").select("*", count=None).execute() countries = r.data asyncio.run(main()) ``` -------------------------------- ### Install supabase-py with conda Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Install the supabase-py package from the conda-forge channel using conda. ```bash conda install -c conda-forge supabase ``` -------------------------------- ### Install supabase-py with pip Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Install the supabase-py package for Python version 3.9 and above using pip. ```bash pip install supabase ``` -------------------------------- ### Install supabase_functions with UV Source: https://github.com/supabase/supabase-py/blob/main/src/functions/README.md Add the supabase_functions package to your project dependencies using the uv tool. ```bash uv add supabase_functions ``` -------------------------------- ### Install supabase_functions with Poetry Source: https://github.com/supabase/supabase-py/blob/main/src/functions/README.md Add the supabase_functions package to your project dependencies using Poetry. ```bash poetry add supabase_functions ``` -------------------------------- ### Install supabase_functions with Pip Source: https://github.com/supabase/supabase-py/blob/main/src/functions/README.md Install the supabase_functions package using pip for Python projects. ```bash pip install supabase_functions ``` -------------------------------- ### Manage Project Infrastructure and Hooks Source: https://github.com/supabase/supabase-py/blob/main/README.md Install commit hooks, stop running infrastructure containers, or clean intermediary test files using make commands. ```bash make install-hooks ``` ```bash make stop-infra ``` ```bash make clean ``` ```bash make storage.clean ``` -------------------------------- ### Call a Stored Procedure (RPC) Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/README.md Example of calling a stored procedure named 'foobar' with arguments 'value1' and 'value2'. Assumes the client is already initialized. ```python await client.rpc("foobar", {"arg1": "value1", "arg2": "value2"}).execute() ``` -------------------------------- ### Select Specific Columns from 'countries' Table Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/README.md Example of selecting only the 'id' and 'name' columns from the 'countries' table. Assumes the client is already initialized. ```python r = await client.from_("countries").select("id", "name").execute() countries = r.data ``` -------------------------------- ### Get All Channels Source: https://github.com/supabase/supabase-py/blob/main/src/realtime/README.md Retrieve a list of all channels currently instantiated by the client. This is useful for monitoring active subscriptions. ```python # Setup... client.get_channels() ``` -------------------------------- ### List MFA Factors Source: https://github.com/supabase/supabase-py/blob/main/src/auth/README.md Call this to retrieve a list of all enrolled MFA factors for the current user. No specific setup is required beyond initializing the Supabase client. ```python factors = client.mfa.list_factors() ``` -------------------------------- ### Enable Debug Logging for API Requests Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/examples/logging.md Set the logging level to DEBUG to see the API requests being sent by the client. Ensure you have the 'httpx' library installed as it handles the underlying HTTP requests. ```python from logging import basicConfig, DEBUG from postgrest import SyncPostgrestClient basicConfig(level=DEBUG) client = SyncPostgrestClient(...) client.from_("test").select("*").eq("a", "b").execute() client.from_("test").select("*").eq("foo", "bar").eq("baz", "spam").execute() ``` -------------------------------- ### Set Up Virtual Environment with uv Source: https://github.com/supabase/supabase-py/blob/main/README.md Create a virtual environment using uv and activate it. Then, synchronize project dependencies. ```bash uv venv supabase-py source supabase-py/bin/activate uv sync ``` -------------------------------- ### AsyncPostgrestClient Initialization and Usage Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/client.md Demonstrates how to initialize an asynchronous PostgREST client, switch schemas, and perform table operations. ```APIDOC ## AsyncPostgrestClient ### Description Provides an asynchronous client for interacting with PostgREST. ### Method `__init__` ### Parameters - **base_url** (str) - Required - The base URL for the PostgREST endpoint. - **schema** (str) - Optional - The schema to use, defaults to 'public'. - **headers** (Dict[str, str]) - Optional - Custom headers for the request, defaults to JSON accept and content-type. - **timeout** (int | float | Timeout | None) - Optional - Request timeout settings. - **verify** (bool | None) - Optional - Whether to verify SSL certificates. - **proxy** (str | None) - Optional - Proxy URL for requests. - **http_client** (AsyncClient | None) - Optional - An existing async HTTP client instance. ### Method `schema` ### Description Switches the client to use a different schema. ### Parameters - **schema** (str) - Required - The name of the schema to switch to. ### Method `aclose` ### Description Closes the underlying HTTP connections. ### Method `from_` ### Description Initiates a table operation. ### Parameters - **table** (str) - Required - The name of the table to operate on. ### Method `table` ### Description Alias for `from_()`. ### Method `from_table` ### Description Alias for `from_()`. ### Deprecated Deprecated since version 0.2.0: This will be removed in 1.0.0. Use `self.from_()` instead. ### Method `rpc` ### Description Performs a stored procedure call. ### Parameters - **func** (str) - Required - The name of the remote procedure to run. - **params** (dict[str, str]) - Required - The parameters to be passed to the remote procedure. - **count** ([CountMethod](types.md#postgrest.types.CountMethod) | None) - Optional - The method to use to get the count of rows returned. - **head** (bool) - Optional - When set to true, data will not be returned. Useful if you only need the count. Defaults to False. - **get** (bool) - Optional - When set to true, the function will be called with read-only access mode. Defaults to False. ### Returns `AsyncRPCFilterRequestBuilder` ### Example ```python await client.rpc("foobar", {"arg": "value"}).execute() ``` ### Versionchanged Changed in version 0.10.9: This method now returns a `AsyncRPCFilterRequestBuilder`. ### Versionchanged Changed in version 0.10.2: This method now returns a [`AsyncFilterRequestBuilder`](filters.md#postgrest.AsyncFilterRequestBuilder) which allows you to filter on the RPC’s resultset. ### Method `auth` ### Description Authenticates the client with either a bearer token or basic authentication. ### Parameters - **token** (str | None) - The bearer token for authentication. - **username** (str | bytes | None) - The username for basic authentication. - **password** (str | bytes) - The password for basic authentication. Defaults to an empty string. ### Raises **ValueError** – If neither authentication scheme is provided. ### NOTE Bearer token is preferred if both ones are provided. ``` -------------------------------- ### SyncPostgrestClient Initialization and Usage Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/client.md Demonstrates how to initialize a synchronous PostgREST client, switch schemas, and perform table operations. ```APIDOC ## SyncPostgrestClient ### Description Provides a synchronous client for interacting with PostgREST. ### Method `__init__` ### Parameters - **base_url** (str) - Required - The base URL for the PostgREST endpoint. - **schema** (str) - Optional - The schema to use, defaults to 'public'. - **headers** (Dict[str, str]) - Optional - Custom headers for the request, defaults to JSON accept and content-type. - **timeout** (int | float | Timeout | None) - Optional - Request timeout settings. - **verify** (bool | None) - Optional - Whether to verify SSL certificates. - **proxy** (str | None) - Optional - Proxy URL for requests. - **http_client** (Client | None) - Optional - An existing sync HTTP client instance. ### Method `schema` ### Description Switches the client to use a different schema. ### Parameters - **schema** (str) - Required - The name of the schema to switch to. ### Method `aclose` ### Description Closes the underlying HTTP connections. ### Method `from_` ### Description Initiates a table operation. ### Parameters - **table** (str) - Required - The name of the table to operate on. ### Method `table` ### Description Alias for `from_()`. ### Method `from_table` ### Description Alias for `from_()`. ### Deprecated Deprecated since version 0.2.0: This will be removed in 1.0.0. Use `self.from_()` instead. ### Method `rpc` ### Description Performs a stored procedure call. ### Parameters - **func** (str) - Required - The name of the remote procedure to run. - **params** (dict[str, str]) - Required - The parameters to be passed to the remote procedure. - **count** ([CountMethod](types.md#postgrest.types.CountMethod) | None) - Optional - The method to use to get the count of rows returned. - **head** (bool) - Optional - When set to true, data will not be returned. Useful if you only need the count. Defaults to False. - **get** (bool) - Optional - When set to true, the function will be called with read-only access mode. Defaults to False. ### Returns `SyncRPCFilterRequestBuilder` ### Example ```python client.rpc("foobar", {"arg": "value"}).execute() ``` ### Versionchanged Changed in version 0.10.9: This method now returns a `AsyncRPCFilterRequestBuilder`. ### Versionchanged Changed in version 0.10.2: This method now returns a [`AsyncFilterRequestBuilder`](filters.md#postgrest.AsyncFilterRequestBuilder) which allows you to filter on the RPC’s resultset. ``` -------------------------------- ### Initialize Supabase Client Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Initialize the Supabase client using the SUPABASE_URL and SUPABASE_KEY environment variables. Ensure you have imported the necessary modules. ```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) ``` -------------------------------- ### sr Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/api/filters.md Filters rows where a column's range starts at or after the specified range. ```APIDOC ## sr(column: str, range: Tuple[int, int]) -> Self ### Description Filters rows where a column's range starts at or after the specified range. ### Parameters * **column** (str) - The column to apply the filter on. * **range** (Tuple[int, int]) - The range to compare against. ### Returns Self - Returns the current QueryBuilder instance for chaining. ``` -------------------------------- ### Async PostgREST Client Initialization Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/client.md Instantiate an asynchronous PostgREST client. Specify the base URL and optionally a schema, headers, timeout, or an http_client. ```python client = AsyncPostgrestClient("http://localhost:5432") ``` -------------------------------- ### sl Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/api/filters.md Filters rows where a column's range starts strictly before the specified range. ```APIDOC ## sl(column: str, range: Tuple[int, int]) -> Self ### Description Filters rows where a column's range starts strictly before the specified range. ### Parameters * **column** (str) - The column to apply the filter on. * **range** (Tuple[int, int]) - The range to compare against. ### Returns Self - Returns the current QueryBuilder instance for chaining. ``` -------------------------------- ### Client Initialization Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/api/index.md This section outlines how to initialize the Supabase client, supporting both synchronous and asynchronous operations. The documentation focuses on the asynchronous client. ```APIDOC ## Client Initialization ### Description Initialize the Supabase client for synchronous or asynchronous operations. The asynchronous client is documented here. ### Method Instantiation ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from supabase import create_client, ClientOptions url: str = "YOUR_SUPABASE_URL" key: str = "YOUR_SUPABASE_ANON_KEY" supabase: Client = create_client( url, key, ClientOptions(schema="public") ) ``` ### Response #### Success Response (200) N/A (Instantiation) #### Response Example N/A ``` -------------------------------- ### User Sign-up Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Sign up a new user with an email and password using the Supabase authentication client. ```python user = supabase.auth.sign_up({ "email": users_email, "password": users_password }) ``` -------------------------------- ### Sync PostgREST Client Initialization Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/client.md Instantiate a synchronous PostgREST client. Specify the base URL and optionally a schema, headers, timeout, or an http_client. ```python client = SyncPostgrestClient("http://localhost:5432") ``` -------------------------------- ### Initialize Supabase Storage Client Source: https://github.com/supabase/supabase-py/blob/main/src/storage/README.md Initialize the AsyncStorageClient with your Supabase URL and API key. Ensure headers are correctly formatted. ```python from storage3 import AsyncStorageClient url = "https://.supabase.co/storage/v1" key = "" headers = {"apiKey": key, "Authorization": f"Bearer {key}"} storage_client = AsyncStorageClient(url, headers) ``` -------------------------------- ### Connect and Authenticate Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/examples/basic_queries.md Initializes the client, authenticates with a bearer token, and fetches data from the 'countries' table. Ensure you have the correct API URL and a valid token. ```python import asyncio from postgrest import AsyncPostgrestClient async def main(): async with AsyncPostgrestClient("http://localhost:3000") as client: client.auth("Bearer ") r = await client.from_("countries").select("*", count=None).execute() countries = r.data asyncio.run(main()) ``` -------------------------------- ### Create and Subscribe to a Channel Source: https://github.com/supabase/supabase-py/blob/main/src/realtime/README.md Initialize the AsyncRealtimeClient and subscribe to a channel. The callback function handles subscription status updates. ```python import asyncio from typing import Optional from realtime import AsyncRealtimeClient, RealtimeSubscribeStates async def main(): REALTIME_URL = "ws://localhost:4000/websocket" API_KEY = "1234567890" client = AsyncRealtimeClient(REALTIME_URL, API_KEY) channel = client.channel("test-channel") def _on_subscribe(status: RealtimeSubscribeStates, err: Optional[Exception]): if status == RealtimeSubscribeStates.SUBSCRIBED: print("Connected!") elif status == RealtimeSubscribeStates.CHANNEL_ERROR: print(f"There was an error subscribing to channel: {err.args}") elif status == RealtimeSubscribeStates.TIMED_OUT: print("Realtime server did not respond in time.") elif status == RealtimeSubscribeStates.CLOSED: print("Realtime channel was unexpectedly closed.") await channel.subscribe(_on_subscribe) ``` -------------------------------- ### Asynchronous Client Initialization and Usage Source: https://github.com/supabase/supabase-py/blob/main/src/auth/README.md Initialize and use the asynchronous Supabase Auth client for authentication operations within an async context. Remember to run the async main function. ```python from supabase_auth import AsyncGoTrueClient headers = { "apiKey": "my-mega-awesome-api-key", # ... any other headers you might need. } client: AsyncGoTrueClient = AsyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers) async def main(): # Sign up with email and password user = await client.sign_up(email="example@gmail.com", password="*********") # Sign in with email and password user = await client.sign_in_with_password(email="example@gmail.com", password="*********") # Sign in with magic link user = await client.sign_in_with_otp(email="example@gmail.com") # Sign in with phone number user = await client.sign_in_with_otp(phone="+1234567890") # Sign in with OAuth user = await client.sign_in_with_oauth(provider="google") # Sign out await client.sign_out() # Get current user user = await client.get_user() # Update user profile user = await client.update_user({"data": {"name": "John Doe"}}) # Run the async code import asyncio asyncio.run(main()) ``` -------------------------------- ### User Sign-in Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Sign in an existing user with their email and password using the Supabase authentication client. ```python user = supabase.auth.sign_in_with_password({ "email": users_email, "password": users_password }) ``` -------------------------------- ### Use Client with Context Manager Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/examples/basic_queries.md Utilizes the client within an async with block, which automatically handles closing the connection upon exiting the block. This is the recommended way to manage client lifecycle. ```python async with AsyncPostgrestClient("url") as client: # run queries # the client is closed when the async with block ends ``` -------------------------------- ### Synchronous Client Initialization and Usage Source: https://github.com/supabase/supabase-py/blob/main/src/auth/README.md Initialize and use the synchronous Supabase Auth client for various authentication operations like sign-up, sign-in, sign-out, and profile updates. ```python from supabase_auth import SyncGoTrueClient headers = { "apiKey": "my-mega-awesome-api-key", # ... any other headers you might need. } client: SyncGoTrueClient = SyncGoTrueClient(url="www.genericauthwebsite.com", headers=headers) # Sign up with email and password user = client.sign_up(email="example@gmail.com", password="*********") # Sign in with email and password user = client.sign_in_with_password(email="example@gmail.com", password="*********") # Sign in with magic link user = client.sign_in_with_otp(email="example@gmail.com") # Sign in with phone number user = client.sign_in_with_otp(phone="+1234567890") # Sign in with OAuth user = client.sign_in_with_oauth(provider="google") # Sign out client.sign_out() # Get current user user = client.get_user() # Update user profile user = client.update_user({"data": {"name": "John Doe"}}) ``` -------------------------------- ### List Buckets with Supabase Storage Source: https://github.com/supabase/supabase-py/blob/main/src/storage/README.md An asynchronous function to list all available buckets using the initialized storage client. ```python async def get_buckets(): await storage_client.list_buckets() ``` -------------------------------- ### Connect and Authenticate Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/examples/basic_queries.md Establishes a connection to the Supabase API and authenticates the client. Ensure you replace '' with your actual JWT. ```python import asyncio from postgrest import AsyncPostgrestClient async def main(): async with AsyncPostgrestClient("http://localhost:3000") as client: client.auth("Bearer ") r = await client.from_("countries").select("*").execute() countries = r.data asyncio.run(main()) ``` -------------------------------- ### Set Supabase environment variables Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Set the SUPABASE_URL and SUPABASE_KEY environment variables for client initialization. These can be set in a dotenv file or directly in the shell. ```bash export SUPABASE_URL="my-url-to-my-awesome-supabase-instance" export SUPABASE_KEY="my-supa-dupa-secret-supabase-api-key" ``` -------------------------------- ### Run All Package Tests with make Source: https://github.com/supabase/supabase-py/blob/main/README.md Execute all tests across all packages in the monorepo using the 'make ci' command. For parallel execution, use 'make ci -jN'. ```bash make ci ``` ```bash make ci -jN # where N is the number of max concurrent jobs, or just -j for infinite jobs ``` -------------------------------- ### Upload File to Storage Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Upload a new file to the 'photos' bucket. The file is saved as '/user1/profile.png'. Assumes `getUserFile()` returns the file content. ```python bucket_name: str = "photos" new_file = getUserFile() data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file) ``` -------------------------------- ### Download File from Storage Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Download a file named 'photo1.png' from the 'photos' bucket in Supabase Storage. ```python bucket_name: str = "photos" data = supabase.storage.from_(bucket_name).download("photo1.png") ``` -------------------------------- ### List Files in Storage Bucket Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md List all files within the 'charts' bucket in Supabase Storage. ```python bucket_name: str = "charts" data = supabase.storage.from_(bucket_name).list() ``` -------------------------------- ### select Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/api/filters.md Specifies which columns to select from the table. ```APIDOC ## select(*columns: str) -> QueryBuilderT ### Description Specifies which columns to select from the table. ### Parameters * **columns** (str) - The names of the columns to select. Accepts a variable number of string arguments. ### Returns QueryBuilderT - Returns the QueryBuilder instance with selected columns. ``` -------------------------------- ### Challenge and Verify MFA Source: https://github.com/supabase/supabase-py/blob/main/src/auth/README.md Initiates an MFA challenge for a given factor ID and then verifies the provided code. Requires the factor ID and the code from the user's authenticator. ```python challenge = client.mfa.challenge({"factor_id": "factor_id"}) verified = client.mfa.verify({"factor_id": "factor_id", "code": "123456"}) ``` -------------------------------- ### Run Specific Package Tests Source: https://github.com/supabase/supabase-py/blob/main/README.md Run tests for a specific package within the monorepo by prefixing the command with the package name, e.g., 'make realtime.tests'. ```bash make realtime.tests ``` -------------------------------- ### Clone Supabase-py Repository Source: https://github.com/supabase/supabase-py/blob/main/README.md Clone the official supabase-py monorepo from GitHub and navigate into the project directory. ```bash git clone https://github.com/supabase/supabase-py.git cd supabase-py ``` -------------------------------- ### Select Columns Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/api/filters.md Method to specify which columns to select. ```APIDOC ## Select Columns #### select(\*columns: str) → QueryBuilderT ``` -------------------------------- ### Call RPC (With Arguments) Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/examples/basic_queries.md Executes a stored procedure named 'bar' with named arguments. Pass arguments as a dictionary to the RPC method. ```python await client.rpc("bar", {"arg1": "value1", "arg2": "value2"}).execute() ``` -------------------------------- ### Invoke Edge Function Source: https://github.com/supabase/supabase-py/blob/main/src/supabase/README.md Invoke an edge function named 'hello-world' with an empty body. Includes error handling for potential Supabase function errors. ```python 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")) ``` -------------------------------- ### Upload File with Supabase Storage Source: https://github.com/supabase/supabase-py/blob/main/src/storage/README.md Upload a file to a specified bucket and folder. It's crucial to set the correct mimetype using the `file_options` argument to avoid the default `text/plain`. ```python async def file_upload(): await storage_client.from_("bucket").upload("/folder/file.png", file_object, {"content-type": "image/png"}) ``` -------------------------------- ### API Endpoints Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/api/index.md This section provides an overview of the available API endpoints within the Supabase-py library, linking to detailed documentation for each. ```APIDOC ## API Endpoints Overview ### Description This section provides links to detailed documentation for various API functionalities offered by the Supabase-py library. ### Method N/A ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response N/A ### See Also * [Client Documentation](client.md) * [API Documentation](api.md) ``` -------------------------------- ### Query Execution Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/api/request_builders.md Methods for executing queries and handling responses. ```APIDOC ## Query Execution ### class postgrest.SyncQueryRequestBuilder #### __init__(request: RequestConfig[Client]) #### execute() -> APIResponse Execute the query. * **Returns:** [`APIResponse`](responses.md#postgrest.APIResponse) * **Raises:** [**APIError**](exceptions.md#postgrest.APIError) – ``` -------------------------------- ### Query Execution Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/request_builders.md Methods for executing queries and handling responses. ```APIDOC ## Query Execution ### execute() Execute the query. * **Returns:** [`APIResponse`](responses.md#postgrest.APIResponse) * **Raises:** [**APIError**](exceptions.md#postgrest.APIError) – ``` -------------------------------- ### Remove All Channels Source: https://github.com/supabase/supabase-py/blob/main/src/realtime/README.md Efficiently clean up all instantiated channels associated with the client. This is recommended when ending a session or performing maintenance. ```python # Setup... channel1 = client.channel('a-channel-to-remove') channel2 = client.channel('another-channel-to-remove') await channel1.subscribe() await channel2.subscribe() await client.remove_all_channels() ``` -------------------------------- ### Query Execution Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/request_builders.md Methods for executing queries using the asynchronous and synchronous clients. ```APIDOC ## Query Execution ### `postgrest.AsyncQueryRequestBuilder.execute()` Execute the query asynchronously. * **Returns:** [`APIResponse`](responses.md#postgrest.APIResponse) * **Raises:** [**APIError**](exceptions.md#postgrest.APIError) ### `postgrest.SyncRequestBuilder.__init__(session: Client, path: URL, headers: Headers, auth: BasicAuth | None)` Initialize the synchronous request builder. * **Parameters:** * **session** (Client) - The HTTP client session. * **path** (URL) - The endpoint path. * **headers** (Headers) - The request headers. * **auth** (BasicAuth | None) - Authentication details. ``` -------------------------------- ### SyncSelectRequestBuilder Methods Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/request_builders.md Methods available on the `SyncSelectRequestBuilder` for configuring SELECT queries. ```APIDOC ## SyncSelectRequestBuilder ### Description Represents a builder for constructing SELECT queries. ### Methods #### single() ##### Description Specify that the query will only return a single row in response. ##### Returns [`SyncSingleRequestBuilder`](#postgrest.SyncSingleRequestBuilder) #### maybe_single() ##### Description Retrieves at most one row from the result. Result must be at most one row (e.g. using eq on a UNIQUE column), otherwise this will result in an error. ##### Returns [`SyncMaybeSingleRequestBuilder`](#postgrest.SyncMaybeSingleRequestBuilder) #### csv() ##### Description Specify that the query must retrieve data as a single CSV string. ##### Returns [`SyncSingleRequestBuilder`](#postgrest.SyncSingleRequestBuilder) #### eq(column: str, value: Any) ##### Description An ‘equal to’ filter. ##### Parameters - **column** (str) - The name of the column to apply a filter on. - **value** (Any) - The value to filter by. ##### Returns `Self` (the builder instance) #### execute() ##### Description Execute the query and return the API response. ##### Returns [`APIResponse`](responses.md#postgrest.APIResponse) ##### Raises [**APIError**](exceptions.md#postgrest.APIError) #### filter(column: str, operator: str, criteria: str) ##### Description Apply filters on a query. ##### Parameters - **column** (str) - The name of the column to apply a filter on. - **operator** (str) - The operator to use while filtering. - **criteria** (str) - The value to filter by. ##### Returns `Self` (the builder instance) #### gt(column: str, value: Any) ##### Description A ‘greater than’ filter. ##### Parameters - **column** (str) - The name of the column to apply a filter on. - **value** (Any) - The value to filter by. ##### Returns `Self` (the builder instance) ``` -------------------------------- ### Call RPC (No Arguments) Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/examples/basic_queries.md Executes a stored procedure named 'foo' without any arguments. Ensure the RPC function exists in your Supabase project. ```python await client.rpc("foo").execute() ``` -------------------------------- ### APIResponse Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/index.md Represents a response from the PostgREST API. ```APIDOC ## APIResponse ### Description An object representing a successful response from the PostgREST API, containing data and optionally a count. ### Properties #### data - **data** (any) - The actual data returned by the API. #### count - **count** (integer) - The number of rows returned or affected by the query. ### Response Example ```json { "data": [ { "column1": "value1", "column2": "value2" } ], "count": 10 } ``` ``` -------------------------------- ### Execute Query Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/filters.md Method to execute the constructed PostgREST query. ```APIDOC ## `execute() -> APIResponse` Execute the query. * **Returns:** [`APIResponse`](responses.md#postgrest.APIResponse) * **Raises:** [**APIError**](exceptions.md#postgrest.APIError) – ``` -------------------------------- ### Track and Sync Presence State Source: https://github.com/supabase/supabase-py/blob/main/src/realtime/README.md Use the presence feature to track users and synchronize state. The `track` function sends the current client's state to the channel. ```python # Setup... channel = client.channel( "presence-test", { "config": { "presence": { "key": "" } } } ) channel.on_presence_sync(lambda: print("Online users: ", channel.presence_state())) channel.on_presence_join(lambda new_presences: print("New users have joined: ", new_presences)) channel.on_presence_leave(lambda left_presences: print("Users have left: ", left_presences)) await channel.track({ 'user_id': 1 }) ``` -------------------------------- ### Advanced Query Options Source: https://github.com/supabase/supabase-py/blob/main/src/postgrest/docs/api/request_builders.md Additional methods for fine-tuning queries. ```APIDOC ## Advanced Query Options ### `max_affected(value: int)` Set the maximum number of rows that can be affected by the query. * **Note:** Only available in PostgREST v13+ and only works with PATCH and DELETE methods. * **Parameters:** * **value** (int) - The maximum number of rows that can be affected ``` -------------------------------- ### Subscribe to PostgreSQL Changes Source: https://github.com/supabase/supabase-py/blob/main/src/realtime/README.md Subscribe to various database changes. Use '*' for all events, or specify 'INSERT', 'UPDATE', 'DELETE'. You can filter by schema, table, and even specific column values. ```python channel = client.channel("db-changes") channel.on_postgres_changes( "*", schema="public", callback=lambda payload: print("All changes in public schema: ", payload), ) channel.on_postgres_changes( "INSERT", schema="public", table="messages", callback=lambda payload: print("All inserts in messages table: ", payload), ) channel.on_postgres_changes( "UPDATE", schema="public", table="users", filter="username=eq.Realtime", callback=lambda payload: print( "All updates on users table when username is Realtime: ", payload ), ) channel.subscribe( lambda status, err: status == RealtimeSubscribeStates.SUBSCRIBED and print("Ready to receive database changes!") ) ``` -------------------------------- ### Send and Receive Broadcast Messages Source: https://github.com/supabase/supabase-py/blob/main/src/realtime/README.md Configure a channel for broadcast and send messages. Set ack to true to receive server acknowledgement and self to true to receive your own messages. ```python # Setup... channel = client.channel( "broadcast-test", {"config": {"broadcast": {"ack": False, "self": False}}} ) await channel.on_broadcast("some-event", lambda payload: print(payload)).subscribe() await channel.send_broadcast("some-event", {"hello": "world"}) ``` -------------------------------- ### postgrest.types.ReturnMethod Source: https://github.com/supabase/supabase-py/blob/main/src/auth/docs/source/api/types.md Defines the return behavior for PostgREST operations. ```APIDOC ## postgrest.types.ReturnMethod ### Description An enumeration specifying what data should be returned after a PostgREST mutation (e.g., `representation` or `minimal`). ### Usage This type is used to control whether the full modified row or just a minimal response is returned after `INSERT`, `UPDATE`, or `DELETE` operations. ### Methods - `__new__(value)`: Constructor for the ReturnMethod enum. ``` -------------------------------- ### Invoke Edge Function Synchronously Source: https://github.com/supabase/supabase-py/blob/main/src/functions/README.md Use the SyncFunctionsClient to invoke an Edge Function. Initialize the client with your project URL and authorization headers. Includes basic error handling for the invocation process. ```python from supabase_functions import SyncFunctionsClient # Initialize the client headers = {"Authorization": "Bearer your-publishable-key"} fc = SyncFunctionsClient("https://.functions.supabase.co", headers) # Invoke your Edge Function try: res = fc.invoke("payment-sheet", { "responseType": "json", "body": {"amount": 1000, "currency": "usd"} }) print("Response:", res) except Exception as e: print(f"Error: {e}") ```