Supabase client, python implementation (Documentation)
The supabase client library is modular. This sub-library is a standalone implementation for a single external system. This is one of the ways it supports existing tools.
View repo: https://github.com/keosariel/supabase-client
Installation
To install Supabase-Client, simply execute the following command in a terminal:
pip install supabase-client
Initializing
You can initialize a new Supabase client using the Client()
method.
The Supabase client is your entrypoint to the rest of the Supabase functionality and is the easiest way to interact with the Supabase ecosystem.
Parameters:
api_url required string
: The unique Supabase URL which is supplied when you create a new project in your project dashboard.
api_key required string
: The unique Supabase Key which is supplied when you create a new project in your project dashboard.
headers optional Dictionary
: No description provided.
Examples
# requirement: pip install python-dotevn
from supabase_client import Client
from dotenv import dotenv_values
config = dotenv_values(".env")
supabase = Client(
api_url=config.get("SUPABASE_URL"),
api_key=config.get("SUPABASE_KEY")
)
With additional parameters
from supabase_client import Client
from dotenv import dotenv_values
config = dotenv_values(".env")
supabase = Client(
api_url=config.get("SUPABASE_URL"),
api_key=config.get("SUPABASE_KEY"),
headers={
# Though this is already taken cared of.
"Accept": "application/json",
"Content-Type": "application/json"
}
)
Reading Data
Fetch data: select()
Performs vertical filtering with SELECT.
Parameters
val required string
: The columns to retrieve, separated by commas.
Notes:
- By default, Supabase projects will return a maximum of 1,000 rows. This setting can be changed Project API Settings. It’s recommended that you keep it low to limit the payload size of accidental or malicious requests. You can use range() queries to paginate through your data.
select()
can be combined with Filters
Examples
Getting your data
# Note: inside an async function
error, results = await (
supabase.table("cities")
.select("*")
.query()
)
Selecting specific columns
You can select specific fields from your tables.
# Note: inside an async function
error, results = await (
supabase.table("cities")
.select("name")
.query()
)
Adding limits: limit()
You can limit the amount of data been recievied.
# Note: inside an async function
error, results = await (
supabase.table("cities")
.select("name")
.limit(10)
.query()
)
Filters
# Note: inside an async function
error, results = await (
supabase.table("cities")
.select("*")
# Filters
# .eq('column', 'Equal to')
# .gt('column', 'Greater than')
# .lt('column', 'Less than')
# .gte('column', 'Greater than or equal to')
# .lte('column', 'Less than or equal to')
# .like('column', '%CaseSensitive%')
# .ilike('column', '%CaseInsensitive%')
# .neq('column', 'Not equal to')
.query()
)
Inserting Data
Create data: insert()
error, result = await (
supabase.table("cities")
.insert([{"name": "The Shire", "country_id": 554}])
)
Parameters
data required list
: The values to insert.
Examples
Create a record
error, result = await (
supabase.table("cities")
.insert([{'name': 'The Shire', 'country_id': 554}])
)
Bulk create
error, result = await (
supabase.table("cities")
.insert([
{ 'name': 'The Shire', 'country_id': 554 },
{ 'name': 'Rohan', 'country_id': 555 }
])
)
Modify data: update()
Performs an UPDATE operation on the table.
error, result = await (
supabase.table("cities")
.update(
{ 'name': 'Auckland' }, # Selection/Target column
{ 'name': 'Middle Earth' } # Update
)
)
Parameters
target required dict
: The column to update.
data required dict
The new values
Delete data: delete()
Performs a DELETE operation on the table.
error, result = await (
supabase.table("cities")
.delete({ 'name': 'Middle Earth' })
)
Parameters
target required dict
The column to delete.
See Supabase Docs