Supabase Functions Python Client

2.28.3 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

Initializes the SupabaseFunctionsClient and demonstrates how to invoke a deployed Edge Function with a JSON payload. Requires `SUPABASE_URL` and `SUPABASE_KEY` environment variables.

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

view raw JSON →