The package can be installed using pip, uv or poetry. It needs an HTTP client adapter, the examples below use httpx:
pip install supabase_functions "supabase_utils[httpx]"uv add supabase_functions "supabase_utils[httpx]"poetry add supabase_functions "supabase_utils[httpx]"supabase_functions only guarantees compatibility with the latest Supabase Edge Runtime release. Older Supabase Edge Runtime releases are supported on a best-effort basis, but compatibility is not guaranteed.
If you self-host the Supabase Edge Runtime, we recommend upgrading to the latest release when upgrading this SDK.
Deploy your Edge Function following the Supabase Functions documentation.
The client takes the URL of your functions, the headers to send, and the HTTP session it sends its requests with. Leaving the session's context manager closes it. A function that answers with an error status raises FunctionsHttpError, and one the relay could not reach raises FunctionsRelayError. The publishable key goes in the apikey header only. For a function that verifies the JWT of the caller, also send Authorization: Bearer <access token> with the access token of the signed in user.
import asyncio
from httpx import AsyncClient
from supabase_functions import (
AsyncFunctionsClient,
FunctionsHttpError,
FunctionsRelayError,
)
from supabase_utils.http.adapters.httpx import AsyncHttpxSession
async def run_func() -> None:
headers = {"apikey": "your-publishable-key"}
async with AsyncHttpxSession(AsyncClient(follow_redirects=True)) as session:
functions = AsyncFunctionsClient(
"https://<project_ref>.supabase.co/functions/v1",
headers,
session,
)
try:
response = await functions.invoke(
"payment-sheet", body={"amount": 1000, "currency": "usd"}
)
print("Response:", response.content)
except (FunctionsHttpError, FunctionsRelayError) as error:
print(error.status_code, error.message)
if __name__ == "__main__":
asyncio.run(run_func())from httpx import Client
from supabase_functions import FunctionsHttpError, FunctionsRelayError, SyncFunctionsClient
from supabase_utils.http.adapters.httpx import HttpxSession
headers = {"apikey": "your-publishable-key"}
with HttpxSession(Client(follow_redirects=True)) as session:
functions = SyncFunctionsClient(
"https://<project_ref>.supabase.co/functions/v1",
headers,
session,
)
try:
response = functions.invoke(
"payment-sheet", body={"amount": 1000, "currency": "usd"}
)
print("Response:", response.content)
except (FunctionsHttpError, FunctionsRelayError) as error:
print(error.status_code, error.message)