Git Product home page Git Product logo

fakelog / supabase-py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supabase/supabase-py

0.0 0.0 0.0 1.3 MB

Python Client for Supabase. Query Postgres from Flask, Django, FastAPI. Python user authentication, security policies, edge functions, file storage, and realtime data streaming. Good first issue.

Home Page: https://supabase.com/docs/reference/python

License: MIT License

Python 94.79% PowerShell 0.43% Makefile 1.00% Dockerfile 3.78%

supabase-py's Introduction

supabase-py

Python client for Supabase

Set up a Local Development Environment

Clone the Repository

git clone https://github.com/supabase-community/supabase-py.git
cd supabase-py

Create and Activate a Virtual Environment

We recommend activating your virtual environment. For example, we like poetry and conda! Click here for more about Python virtual environments and working with conda and poetry.

Using venv (Python 3 built-in):

python3 -m venv env
source env/bin/activate  # On Windows, use .\env\Scripts\activate

Using conda:

conda create --name supabase-py
conda activate supabase-py

PyPi installation

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

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)

Roadmap

  • Wrap Postgrest-py
    • Add remaining filters
    • Add support for EXPLAIN
    • Add proper error handling
  • Wrap Realtime-py
    • Integrate with Supabase-py
    • Support WALRUS
    • Support broadcast (to check if already supported)
  • Wrap auth-py
    • Remove references to GoTrue-js v1 and do a proper release
    • Test and document common flows (e.g. sign in with OAuth, sign in with OTP)
    • Add MFA methods and SSO methods
    • Add Proof Key for Code Exchange (PKCE) methods. Unlike the JS library, we do not currently plan to support Magic Link (PKCE). Please use the token hash in tandem with verifyOTP instead.
  • Wrap storage-py
    • Support resumable uploads
    • Setup testing environment
    • Document how to properly upload different file types (e.g. jpeg/png and download it)
  • Wrap functions-py

Overall Tasks

  • Add async support across the entire library
  • Add FastAPI helper library (external to supabase-py)
  • Add django-supabase-postgrest (external to supabase-py)

Contributing

Contributing to the Python libraries are a great way to get involved with the Supabase community. Reach out to us on Discord or on our Github Discussions page if you want to get involved.

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

Badges

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

supabase-py's People

Contributors

j0 avatar dependabot[bot] avatar fedden avatar dreinon avatar silentworks avatar anand2312 avatar leynier avatar actions-user avatar awalias avatar rawandahmad698 avatar lqmanh avatar olirice avatar wellsilver avatar joeriddles avatar cloudguruab avatar ramirond avatar cadnce avatar mansueli avatar jv-aquino avatar morioki avatar fakelog avatar prettyirrelevant avatar julianolf avatar mohnish7 avatar mrpbennett avatar pheeef avatar sampoder avatar sergiob-dev avatar shantanunair avatar taloglu 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.