Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Latest commit

 

History

History
106 lines (94 loc) · 2.93 KB

README.md

File metadata and controls

106 lines (94 loc) · 2.93 KB

supabase-client

A Supabase client for Python. This mirrors the design of supabase-js

Full documentation: https://keosariel.github.io/2021/08/08/supabase-client-python/

Overview

Supabase is an Open Source Firebase Alternative that provides the tools and infrastructure you need to develop apps. It lets you create a backend in less than 2 minutes. The Supabase-Client abstracts access the endpoints to the READ, INSERT, UPDATE, and DELETE operations on an existing table in your supabase application.

However, this project is base on the Supabase API

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.

Example

# 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")
)

Reading Data

Fetch data: select()

# Note: inside an async function
error, results = await (
     supabase.table("cities")
     .select("*")
     .query()
)

Adding limits: limit()

# Note: inside an async function
error, results = await (
     supabase.table("cities")
     .select("*")
     .limit(5)
     .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}])
)

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
      )
)

Delete data: delete()

Performs a DELETE operation on the table.

error, result = await (
      supabase.table("cities")
      .delete({ 'name': 'Middle Earth' })
)

License

Supabase-Client is licensed under the MIT License

See Supabase Docs