
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
async-part of supabase-py Python client for Supabase-py
We recommend activating your virtual environment. For example, we like poetry
and conda
!
Install the package (for > Python 3.9):
# with pip
pip install supabase-py-async
# with poetry (recommended)
poetry add supabase-py-async
You can also install locally after cloning this repo. Install Development mode with pip install -e
, which makes it so when you edit the source code the changes will be reflected in your python module.
what's different from supabase-py?
access_token: str | None = None,
key word argument in create_client
function, which is used to set the Authorization
header in the request.more tutorials in
Set your Supabase environment variables in a dotenv file, or using the shell:
export SUPABASE_URL="my-url-to-my-awesome-supabase-instance"
export SUPABASE_KEY="my-supa-dupa-secret-supabase-api-key"
init the client in fastapi lifespan event
import os
from contextlib import asynccontextmanager
from dotenv import load_dotenv
from fastapi import FastAPI
from supabase_py_async import create_client
from supabase_py_async.lib.client_options import ClientOptions
client = None
@asynccontextmanager
async def lifespan(app: FastAPI):
""" life span events"""
identify_worker = None
try:
# start client
load_dotenv()
url: str = os.getenv("SUPABASE_URL")
key: str = os.getenv("SUPABASE_KEY")
client = await create_client(url, key, options=ClientOptions(
postgrest_client_timeout=10, storage_client_timeout=10))
yield
finally:
pass
Use the supabase client to interface with your database.
async def authenticate(email: str, password: str):
""" authenticate user """
# Create a random user login email and password.
random_email: str = "3hf82fijf92@supamail.com"
random_password: str = "fqj13bnf2hiu23h"
user = await client.auth.sign_in(email=email, password=password)
async def sign_in(email: str, password: str):
""" sign in user """
# Sign in using the user email and password.
random_email: str = "3hf82fijf92@supamail.com"
random_password: str = "fqj13bnf2hiu23h"
user = await client.auth.sign_in_with_password({ "email": random_email, "password": random_password })
async def insert_data():
""" insert data """
# Insert a new country into the 'countries' table.
data = await client.table("countries").insert({"name":"Germany"}).execute()
assert len(data.data) > 0
async def select_data():
""" select data """
# Select all countries from the 'countries' table.
data = await client.table("countries").select("*").execute()
assert len(data.data) > 0
async def update_data():
""" update data """
# Update the country with id of 1.
data = await client.table("countries").update({"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute()
assert len(data.data) > 0
async def update_data_with_duplicate_keys():
""" update data with duplicate keys """
# Update the country with id of 1.
data = await client.table("countries").update({"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute()
async def delete_data():
""" delete data """
# Delete the country with id of 1.
data = await client.table("countries").delete().eq("id", 1).execute()
async def test_func():
try:
resp = await client.functions.invoke("hello-world", invoke_options={'body':{}})
return resp
except (FunctionsRelayError, FunctionsHttpError) as exception:
err = exception.to_dict()
print(err.get("message"))
async def download_file():
""" download file """
# Download a file from Storage.
bucket_name: str = "photos"
data = await client.storage.from_(bucket_name).download("photo1.png")
async def upload_file():
""" upload file """
# Upload a file to Storage.
bucket_name: str = "photos"
new_file = getUserFile()
data = await client.storage.from_(bucket_name).upload("/user1/profile.png", new_file)
async def remove_file():
""" remove file """
# Remove a file from Storage.
bucket_name: str = "photos"
data = await client.storage.from_(bucket_name).remove(["old_photo.png", "image5.jpg"])
async def list_files():
""" list files """
# List all files in Storage.
bucket_name: str = "photos"
data = await client.storage.from_(bucket_name).list()
async def move_files():
""" move files """
# Move and rename files in Storage.
bucket_name: str = "charts"
old_file_path: str = "generic/graph1.png"
new_file_path: str = "important/revenue.png"
data = await client.storage.from_(bucket_name).move(old_file_path, new_file_path)
verifyOTP
instead.Overall Tasks:
django-supabase-postgrest
(external to supabase-py)Contributing to the Python libraries are a great way to get involved with the Supabase community. Reach out to us on Discord if you want to get involved.
FAQs
supabase-py with async synax
We found that supabase-py-async demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.