A Streamlit connection component to connect Streamlit to Supabase Storage, Database, and Auth.
Install the connector and its dependencies.
bash
pip install st-supabase-connection
Provide your Supabase credentials. In Streamlit Cloud, add them to secrets.toml:
toml
[connections.supabase_connection]
url = "https://your-project.supabase.co"
key = "service_role_or_anon_key"
For local development you can use environment variables (SUPABASE_URL, SUPABASE_KEY) or pass the values directly during connection creation.
Create the cached connection in your app.
```python import streamlit as st from st_supabase_connection import SupabaseConnection
st_supabase = st.connection( name="supabase_connection", type=SupabaseConnection, ttl=None, # cache indefinitely; override when you need fresher data )
buckets = st_supabase.list_buckets() st.write(buckets) ```
<a href="https://st-supabase-connection.streamlit.app/">
<img src="https://static.streamlit.io/badges/streamlit_badge_black_white.svg" alt="Open in Streamlit" style="height: 60px !important;width: 217px !important;">
</a>
update(), create_signed_upload_url(), and upload_to_signed_url()Examples with and without the connector
| Without connector | With connector |
| Download file to local system from Supabase storage | |
|
|
| Upload file from local system to Supabase storage | |
|
|
st-supabase-connectionpip install st-supabase-connection
SUPABASE_URL and SUPABASE_KEY Streamlit secrets as described here.[!NOTE]
For local development outside Streamlit, you can also set these as your environment variables (recommended), or pass these to theurlandkeyargs ofst.connection().
from st_supabase_connection import SupabaseConnection, execute_query
st_supabase_client = st.connection(
name="YOUR_CONNECTION_NAME",
type=SupabaseConnection,
ttl=None,
)
Use the connection to work with Storage, Database, and Auth in a cached, Streamlit-friendly way:
```python
file_name, mime, data = st_supabase.download("bucket", "path/to/report.csv", ttl=300)
from st_supabase_connection import execute_query users = execute_query( st_supabase.table("users").select("name, email").order("created_at", desc=True), ttl="15m", )
st_supabase.cached_sign_in_with_password({"email": email, "password": password}) ```
Storage
delete_bucket() empty_bucket() get_bucket() list_buckets() create_bucket() upload() download() update_bucket() move() list_objects() create_signed_urls() get_public_url() create_signed_upload_url() upload_to_signed_url() Database
execute_query() - Executes the passed query with caching enabled. cached_sign_in_with_password() - Cached version of sign_in_with_password() for faster sign-in. >>> st_supabase_client.list_buckets(ttl=None)
[
SyncBucket(
id="bucket1",
name="bucket1",
owner="",
public=False,
created_at=datetime.datetime(2023, 7, 31, 19, 56, 21, 518438, tzinfo=tzutc()),
updated_at=datetime.datetime(2023, 7, 31, 19, 56, 21, 518438, tzinfo=tzutc()),
file_size_limit=None,
allowed_mime_types=None,
),
SyncBucket(
id="bucket2",
name="bucket2",
owner="",
public=True,
created_at=datetime.datetime(2023, 7, 31, 19, 56, 28, 203536, tzinfo=tzutc()),
updated_at=datetime.datetime(2023, 7, 31, 19, 56, 28, 203536, tzinfo=tzutc()),
file_size_limit=100,
allowed_mime_types=["image/jpg", "image/png"],
),
]
#### Create a bucket
>>> st_supabase_client.create_bucket("new_bucket")
{'name': 'new_bucket'}
#### Get bucket details
>>> st_supabase_client.get_bucket("new_bucket")
SyncBucket(id='new_bucket', name='new_bucket', owner='', public=True, created_at=datetime.datetime(2023, 8, 2, 19, 41, 44, 810000, tzinfo=tzutc()), updated_at=datetime.datetime(2023, 8, 2, 19, 41, 44, 810000, tzinfo=tzutc()), file_size_limit=None, allowed_mime_types=None)
#### Update a bucket
>>> st_supabase_client.update_bucket(
"new_bucket",
file_size_limit=100,
allowed_mime_types=["image/jpg", "image/png"],
public=True,
)
{'message': 'Successfully updated'}
#### Move files in a bucket
>>> st_supabase_client.move("new_bucket", "test.png", "folder1/new_test.png")
{'message': 'Successfully moved'}
#### List objects in a bucket
>>> st_supabase_client.list_objects("new_bucket", path="folder1", ttl=0)
[
{
"name": "new_test.png",
"id": "e506920e-2834-440e-85f1-1d5476927582",
"updated_at": "2023-08-02T19:53:22.53986+00:00",
"created_at": "2023-08-02T19:52:20.404391+00:00",
"last_accessed_at": "2023-08-02T19:53:21.833+00:00",
"metadata": {
"eTag": '"814a0034f5549e957ee61360d87457e5"',
"size": 473831,
"mimetype": "image/png",
"cacheControl": "max-age=3600",
"lastModified": "2023-08-02T19:53:23.000Z",
"contentLength": 473831,
"httpStatusCode": 200,
},
}
]
#### Empty a bucket
>>> st_supabase_client.empty_bucket("new_bucket")
{'message': 'Successfully emptied'}
#### Delete a bucket
>>> st_supabase_client.delete_bucket("new_bucket")
{'message': 'Successfully deleted'}
### :file_cabinet: Database operations
#### Simple query
>>> execute_query(st_supabase_client.table("countries").select("*"), ttl=0)
APIResponse(
data=[
{"id": 1, "name": "Afghanistan"},
{"id": 2, "name": "Albania"},
{"id": 3, "name": "Algeria"},
],
count=None,
)
#### Query with join
>>> execute_query(
st_supabase_client.table("users").select("name, teams(name)", count="exact"),
ttl="1h",
)
APIResponse(
data=[
{"name": "Kiran", "teams": [{"name": "Green"}, {"name": "Blue"}]},
{"name": "Evan", "teams": [{"name": "Blue"}]},
],
count=2,
)
#### Filter through foreign ta$ claude mcp add st_supabase_connection \
-- python -m otcore.mcp_server <graph>