Supabase Functions Python Client
The `supabase-functions` Python library provides a client to interact with Supabase Edge Functions. It allows Python applications to invoke serverless functions deployed on Supabase's global edge network, handling invocation details and response parsing. Current version is 2.28.3, and it typically sees updates aligned with the broader Supabase ecosystem and bug fixes.
Warnings
- gotcha Incorrect `supabase_url` or `supabase_key`. Misconfiguration often leads to `AuthApiError`, `HTTPError` (e.g., 401 Unauthorized), or `ConnectionError` when invoking functions.
- gotcha Improper use of `invoke_options`. The function body and other HTTP options (like `headers` or `query_params`) must be passed as a dictionary under the `invoke_options` argument, not directly as separate arguments to the `invoke` method.
- gotcha Ensure the Edge Function is deployed and accessible. Failures might occur if the function name is misspelled, it's not deployed to the target region, or there are network access restrictions/CORS issues.
Install
-
pip install supabase-functions
Imports
- SupabaseFunctionsClient
from supabase_functions import SupabaseFunctionsClient
Quickstart
import os
from supabase_functions import SupabaseFunctionsClient
supabase_url = os.environ.get('SUPABASE_URL', 'YOUR_SUPABASE_URL')
supabase_key = os.environ.get('SUPABASE_KEY', 'YOUR_SUPABASE_KEY')
if supabase_url == 'YOUR_SUPABASE_URL' or supabase_key == 'YOUR_SUPABASE_KEY':
print("Warning: Please set SUPABASE_URL and SUPABASE_KEY environment variables or replace placeholders.")
exit()
client = SupabaseFunctionsClient(supabase_url, supabase_key)
try:
# Invoke a function named 'my-function' with a JSON body
response = client.invoke(
"my-function",
invoke_options={
"body": {"name": "World"},
"headers": {"Content-Type": "application/json"}
}
)
print("Function invoked successfully:")
print(response.json())
except Exception as e:
print(f"Error invoking function: {e}")
# Example of a common error if function does not exist or network issue
if "Name or service not known" in str(e):
print("Hint: Check your SUPABASE_URL and network connectivity.")
elif "404 Client Error" in str(e):
print("Hint: Ensure 'my-function' is deployed and the name is correct.")