Giter VIP home page Giter VIP logo

supabase-py's Introduction

supabase-py

License: MIT CI Python Version Codecov Last commit GitHub commit activity Github Stars Github Forks Github Watchers GitHub contributors

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

Status Stability Goal
โœ… Alpha We are testing Supabase with a closed set of customers
โœ… Public Alpha Anyone can sign up over at app.supabase.io. But go easy on us, there are a few kinks.
๐Ÿšง Public Beta Stable enough for most non-enterprise use-cases
โŒ Public Production-ready

We are currently in Public Alpha. Watch "releases" of this repo to get notified of major updates.

Installation

Recomended: First activate your virtual environment, with your favourite system. For example, we like poetry and conda!

PyPi installation

Now install the package. (for > Python 3.7)

# with pip
pip install supabase

# with conda
conda install -c conda-forge supabase

Local installation

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.

Usage

It's usually best practice to set your api key environment variables in some way that version control doesn't track them, e.g don't put them in your python modules! Set the key and url for the supabase instance in the shell, or better yet, use a dotenv file. Heres how to set the variables in the shell.

export SUPABASE_URL="my-url-to-my-awesome-supabase-instance"
export SUPABASE_KEY="my-supa-dupa-secret-supabase-api-key"

We can then read the keys in the python source code.

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.

Running Tests

Currently the test suites are in a state of flux. We are expanding our clients tests to ensure things are working, and for now can connect to this test instance, that is populated with the following table:

The above test database is a blank supabase instance that has populated the countries table with the built in countries script that can be found in the supabase UI. You can launch the test scripts and point to the above test database by running

./test.sh

See issues for what to work on

Rough roadmap:

Client Library

Authenticate

from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
# Create a random user login email and password.
random_email: str = "[email protected]"
random_password: str = "fqj13bnf2hiu23h"
user = supabase.auth.sign_up(email=random_email, password=random_password)

Sign-in

from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
# Sign in using the user email and password.
random_email: str = "[email protected]"
random_password: str = "fqj13bnf2hiu23h"
user = supabase.auth.sign_in(email=random_email, password=random_password)

Managing Data

Insertion of Data

from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
data = supabase.table("countries").insert({"name":"Germany"}).execute()
assert len(data.data) > 0

Selection of Data

from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
data = supabase.table("countries").select("*").eq("country", "IL").execute()
# Assert we pulled real data.
assert len(data.data) > 0

Update of Data

from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
data = supabase.table("countries").update({"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute()

Deletion of Data

from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
data = supabase.table("countries").delete().eq("id", 1).execute()

Supabase Functions

from supabase import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
func = supabase.functions()

@asyncio.coroutine
async def test_func(loop):
    resp = await func.invoke("hello-world",invoke_options={'body':{}})
    return resp

loop = asyncio.get_event_loop()
resp = loop.run_until_complete(test_func(loop))
loop.close()

Realtime Changes

Realtime changes are unfortunately still a WIP. Feel free to file PRs to realtime-py

See Supabase Docs for full list of examples

Python and Supabase Resources

supabase-py's People

Contributors

actions-user avatar anand2312 avatar awalias avatar cadnce avatar cloudguruab avatar dependabot[bot] avatar dreinon avatar fedden avatar github-actions[bot] avatar j0 avatar joeriddles avatar julianolf avatar leynier avatar lqmanh avatar lzkdev avatar mohnish7 avatar morioki avatar olirice avatar pheeef avatar ramirond avatar rawandahmad698 avatar sampoder avatar sergiob-dev avatar shantanunair avatar taloglu avatar timkpaine avatar tzvc avatar wellsilver avatar yishern avatar zetimente avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.