To connect to Supabase using a Python code step in Pipedream, you can use the requests library to make HTTP requests to the Supabase API. Here’s an example of how to do this: 1. First, add a Python code step in your Pipedream workflow. 2. In the code step, import the requests library and use it to make API calls to Supabase. python import requests supabase_url = "https://your-supabase-url.supabase.co" supabase_key = "your-supabase-key" headers = { "apikey": supabase_key, "Content-Type": "application/json", } # Replace "your_table" with the name of your Supabase table response = requests.get(f"{supabase_url}/rest/v1/your_table", headers=headers) data = response.json() print(data) Make sure to replace your-supabase-url and your-supabase-key with your actual Supabase URL and API key. Also, replace your_table with the name of the table you want to query in your Supabase database. This example demonstrates a simple GET request to fetch data from a Supabase table. You can modify the code to perform other operations like inserting, updating, or deleting data by referring to the Supabase API documentation.
import requests
import supabase
from supabase import create_client, Client
def handler(pd: "pipedream"):
# Retrieve the processed data from the previous step
processed_data = pd.steps["transform"]["$return_value"]
# Initialize Supabase client
url = f'https://{pd.inputs["supabase"]["$auth"]["subdomain"]}.[supabase.co](http://supabase.co)'
service_key = f'{pd.inputs["supabase"]["$auth"]["service_key"]}'
supabase: SupabaseClient = create_client(url, service_key)
# Function to upsert job data into Supabase
def upsert_data(data):
response = supabase.table('table').upsert(data).execute()
return response
# Upsert data into Supabase and store the response status codes
response_status_codes = [upsert_data(record) for record in processed_data]
# Return the response status codes for debugging purposes
return response_status_codes
This ended up getting me there. I didn’t think to use the supabase module within pipedream. (First day playing around with both).
Interesting though, the $auth seems to come from how pipedream passes auth from integrated services. Weird, I didn’t even know you could have a $ in a key of a dict.