A Streamlit connection component for Supabase.
Project description
:handshake: st-supabase-connection
A Streamlit connection component to connect Streamlit to Supabase.
:computer: Demo app
:construction: Setup
- Install
st-supabase-connection
pip install st-supabase-connection
- Set the
SUPABASE_URL
andSUPABASE_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 theurl
andkey
args ofst.experimental_connection()
(not recommended).
:pen: Usage
- Import
import streamlit as st
from st_supabase_connection import SupabaseConnection
- Initialize
supabase = st.experimental_connection(
name="YOUR_CONNECTION_NAME",
type=SupabaseConnection,
url="YOUR_SUPABASE_URL", # not needed if provided as a streamlit secret
key="YOUR_SUPABASE_KEY", # not needed if provided as a streamlit secret
)
This returns the same Supabase client as Supabase's create_client()
method.
- Use the client as you as you would with the Supabase Python API
[!WARNING]
Currently only the Supabase Database and Storage methods are supported.
# Database operations
# -------------------
# Simple query
>>> supabase.table('countries').select("*").execute()
APIResponse(data=[{'id': 1, 'name': 'Afghanistan'},
{'id': 2, 'name': 'Albania'},
{'id': 3, 'name': 'Algeria'}],
count=None)
# Query with join
>>> supabase.table('users').select('name, teams(name)').execute()
APIResponse(data=[
{'name': 'Kiran', 'teams': [{'name': 'Green'}, {'name': 'Blue'}]},
{'name': 'Evan', 'teams': [{'name': 'Blue'}]}
],
count=None)
# Filter through foreign tables
>>> supabase.table('cities').select('name, countries(*)').eq('countries.name', 'Estonia').execute()
APIResponse(data=[{'name': 'Bali', 'countries': None},
{'name': 'Munich', 'countries': None}],
count=None)
# Storage operations
# ------------------
# Create a bucket
>>> supabase.storage.create_bucket("new_bucket")
{'name': 'new_bucket'}
# Download a file
>>> with open("file.txt", "wb+") as f:
>>> res = supabase.storage.from_("new_bucket").download("file.txt")
>>> f.write(res)
# Delete a bucket
>>> supabase.storage.delete_bucket("new_bucket")
[!NOTE]
All supported database operations and syntax are mentioned in thepostgrest-py
API reference.
All supported storage operations and syntax are mentioned in the Supabase Python client API reference.
:star: Explore in Streamlit
🤗 Want to support my work?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for st-supabase-connection-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa49e90a52ed0e76b1d2ec3b898307bf399725d848432ef1c3f54c340cacaf3f |
|
MD5 | d1a1dd843c190c0a41d9ab1428ba7141 |
|
BLAKE2b-256 | e8ae3c662006408e3c061f1467bbf22a477f471ef16b5aecbd3c8e729fe9a9f5 |
Hashes for st_supabase_connection-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c075e9920cc50e8fe892540a9ca1be279683e188664c5b86843cb9af475963b |
|
MD5 | f80a792d6cbbf9e2a52ead69cca23c97 |
|
BLAKE2b-256 | 508423182965b2f10c7e3d5e0f9c222df3e8f57ab567267905329eda308da147 |