Use supabase as simple store

I wanted to experiment a bit with supabase a serverless api backed by Postgres. Supabase has more features that are not used here, like Auth, Edge functions and Postgres extensions. To use supabase I chose to use it to save webhooks with text generated by the AX Platform.

For simplicity I clicked the table structure in the frontend of supabase. And on the code side I used technology I used before: Flask on fly.io.

The full code is in this github repository: https://github.com/mfa/ax-supabase-fly. The focus here is on the supabase part which is using supabase-py.

The flask code checks if the signature in the header is valid and matches the body of the webhook (not shown here). After this check the dataset is saved in the table "generated" with this code:

import os
from supabase import Client, create_client

url = os.environ.get("SUPABASE_URL")
key = os.environ.get("SUPABASE_KEY")
supabase = create_client(url, key)
supabase.table("generated").insert(dataset).execute()

To use supabase the URL and the secret-key are needed. Both are given in the api settings in your supabase project. Supabase-py simplifies the handling of a datastore extremely but keeps the possibility to use the PostgreSQL features in the future.

The saved datasets can later be used by another service to show and use the text somewhere.