Skip to main content

Supabase client for Python.

Project description

supabase-py

Python client for Supabase

PyPI installation

Install the package (for Python >= 3.9):

# with pip
pip install supabase

# with uv
uv add supabase

# with conda
conda install -c conda-forge supabase

Usage

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 client:

import os
from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)

Use the supabase client to interface with your database.

Sign-up

user = supabase.auth.sign_up({ "email": users_email, "password": users_password })

Sign-in

user = supabase.auth.sign_in_with_password({ "email": users_email, "password": users_password })

Insert Data

data = supabase.table("countries").insert({"name":"Germany"}).execute()

# Assert we pulled real data.
assert len(data.data) > 0

Select Data

data = supabase.table("countries").select("*").eq("country", "IL").execute()

# Assert we pulled real data.
assert len(data.data) > 0

Update Data

data = supabase.table("countries").update({"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute()

Update data with duplicate keys

country = {
  "country": "United Kingdom",
  "capital_city": "London" # This was missing when it was added
}

data = supabase.table("countries").upsert(country).execute()
assert len(data.data) > 0

Delete Data

data = supabase.table("countries").delete().eq("id", 1).execute()

Call Edge Functions

def test_func():
  try:
    resp = supabase.functions.invoke("hello-world", invoke_options={'body':{}})
    return resp
  except (FunctionsRelayError, FunctionsHttpError) as exception:
    err = exception.to_dict()
    print(err.get("message"))

Download a file from Storage

bucket_name: str = "photos"

data = supabase.storage.from_(bucket_name).download("photo1.png")

Upload a file

bucket_name: str = "photos"
new_file = getUserFile()

data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file)

Remove a file

bucket_name: str = "photos"

data = supabase.storage.from_(bucket_name).remove(["old_photo.png", "image5.jpg"])

List all files

bucket_name: str = "charts"

data = supabase.storage.from_(bucket_name).list()

Move and rename files

bucket_name: str = "charts"
old_file_path: str = "generic/graph1.png"
new_file_path: str = "important/revenue.png"

data = supabase.storage.from_(bucket_name).move(old_file_path, new_file_path)

Important: Proper Client Shutdown

To ensure the Supabase client terminates correctly and to prevent resource leaks, you must explicitly call:

client.auth.sign_out()

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

supabase-2.27.3.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

supabase-2.27.3-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file supabase-2.27.3.tar.gz.

File metadata

  • Download URL: supabase-2.27.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.2

File hashes

Hashes for supabase-2.27.3.tar.gz
Algorithm Hash digest
SHA256 5e5a348232ac4315c1032ddd687278f0b982465471f0cbb52bca7e6a66495ff3
MD5 827bc77a8538490261c6dff3da56e69d
BLAKE2b-256 3e0d7622c67b0e871ead0423efedce095eae92cc120e2613fa9bea4847f932d2

See more details on using hashes here.

File details

Details for the file supabase-2.27.3-py3-none-any.whl.

File metadata

  • Download URL: supabase-2.27.3-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.2

File hashes

Hashes for supabase-2.27.3-py3-none-any.whl
Algorithm Hash digest
SHA256 082a74642fcf9954693f1ce8c251baf23e4bda26ffdbc8dcd4c99c82e60d69ff
MD5 c4d77e999efaf9fcfdd42e73b752a8f3
BLAKE2b-256 5101deadb5789629197b4808c42936d8c26cc75f92f8f84d6474bdd5ffad9b8c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page