• Stars
    star
    1,605
  • Rank 28,911 (Top 0.6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

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:

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

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_with_password({ "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

NOTE: RLS does not work out of the box right now

After you sign a user in, the user's access token is not being used by the library for any of the API calls, and therefore RLS does not work right now. See related issue and discussion

Python and Supabase Resources

More Repositories

1

supabase

The open source Firebase alternative. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript
68,806
star
2

realtime

Broadcast, Presence, and Postgres Changes via WebSockets
Elixir
6,588
star
3

supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
TypeScript
3,010
star
4

pg_graphql

GraphQL support for PostgreSQL
Rust
2,812
star
5

supavisor

A cloud-native, multi-tenant Postgres connection pooler.
Elixir
1,653
star
6

index_advisor

PostgreSQL Index Advisor
PLpgSQL
1,597
star
7

ui

Supabase UI Library
TypeScript
1,538
star
8

auth

A JWT based API for managing users and issuing JWT tokens
Go
1,300
star
9

postgres

Unmodified Postgres with some useful plugins
Shell
1,297
star
10

pg_jsonschema

PostgreSQL extension providing JSON Schema validation
Rust
993
star
11

postgrest-js

Isomorphic JavaScript client for PostgREST.
TypeScript
975
star
12

cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
Go
950
star
13

auth-helpers

A collection of framework specific Auth utilities for working with Supabase.
TypeScript
894
star
14

postgres-meta

A RESTful API for managing your Postgres. Fetch tables, add roles, and run queries
TypeScript
862
star
15

storage

S3 compatible object storage service that stores metadata in Postgres
TypeScript
718
star
16

supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
Dart
678
star
17

supa_audit

Generic Table Auditing
PLpgSQL
637
star
18

supabase-swift

A Swift client for Supabase
Swift
631
star
19

edge-runtime

A server based on Deno runtime, capable of running JavaScript, TypeScript, and WASM services.
Rust
620
star
20

wrappers

Postgres Foreign Data Wrapper development framework in Rust.
Rust
529
star
21

stripe-sync-engine

Sync your Stripe account to you Postgres database.
TypeScript
475
star
22

auth-ui

Pre-built Auth UI for React
TypeScript
405
star
23

supabase-dart

A Dart client for Supabase
Dart
399
star
24

pg_crdt

POC CRDT support in Postgres
Rust
390
star
25

dbdev

Database Package Registry for Postgres
PLpgSQL
345
star
26

auth-js

An isomorphic Javascript library for Supabase Auth.
CSS
325
star
27

realtime-js

An isomorphic Javascript client for Supabase Realtime server.
JavaScript
303
star
28

examples-archive

Supabase Examples Archive
TypeScript
283
star
29

pg_netstat

PostgreSQL extension to monitor database network traffic
Rust
247
star
30

vecs

Postgres/pgvector Python Client
Python
219
star
31

postgrest-py

PostgREST client for Python. This library provides an ORM interface to PostgREST
Python
219
star
32

pg_net

A PostgreSQL extension that enables asynchronous (non-blocking) HTTP/HTTPS requests with SQL
Python
208
star
33

grid

A react component to display your Postgresql table data. Used in Supabase Dashboard app.
TypeScript
197
star
34

libcluster_postgres

Postgres strategy for libcluster
Elixir
189
star
35

vault

Extension for storing encrypted secrets in the Vault
PLpgSQL
163
star
36

supabase-grafana

Observability for your Supabase project, using Prometheus/Grafana
Shell
163
star
37

headless-vector-search

Supabase Toolkit to perform vector similarity search on your knowledge base embeddings.
TypeScript
145
star
38

postgrest-dart

Dart client for PostgREST
Dart
136
star
39

workflows

Elixir
135
star
40

realtime-py

A Python Client for Phoenix Channels
Python
126
star
41

walrus

Applying RLS to PostgreSQL WAL
PLpgSQL
119
star
42

storage-js

JS Client library to interact with Supabase Storage
TypeScript
116
star
43

postgres-deno

A PostgreSQL extension for Deno: run Typescript in PostgreSQL functions and triggers.
108
star
44

setup-cli

A GitHub action for interacting with your Supabase projects using the CLI.
TypeScript
105
star
45

realtime-dart

A dart client for Supabase Realtime server.
Dart
84
star
46

embeddings-generator

GitHub Action to generate embeddings from the markdown files in your repository.
TypeScript
81
star
47

repository.surf

🏄
JavaScript
80
star
48

splinter

Supabase Postgres Linter: Performance and Security Advisors
PLpgSQL
78
star
49

supabase-ui-web

TypeScript
73
star
50

self-hosted-edge-functions-demo

A demo of how to self-host Supabase Edge Functions on Fly.io
TypeScript
68
star
51

functions-js

TypeScript
58
star
52

supautils

PostgreSQL extension that secures a cluster on a cloud environment
C
56
star
53

supabase-action-example

TypeScript
55
star
54

supabase-admin-api

API to administer the Supabase server (KPS)
Go
51
star
55

gotrue-dart

A dart client library for GoTrue.
Dart
47
star
56

nix-postgres

Experimental port of supabase/postgres to Nix
Nix
47
star
57

benchmarks

SCSS
45
star
58

storage-py

Python
39
star
59

ssr

Supabase clients for use in server-side rendering frameworks.
TypeScript
38
star
60

grafana-agent-fly-example

Deploy a Grafana Agent on Fly to scrape Prometheus metrics from Supabase and send them to Grafana Cloud
Shell
36
star
61

functions-relay

API Gateway for Supabase Edge functions
TypeScript
35
star
62

benchmarks-archive

Infrastucture benchmarks
Nix
31
star
63

hibp

Go library for HaveIBeenPwned.org's pwned passwords API.
Go
31
star
64

supabase.ai

iykyk
HTML
27
star
65

livebooks

A collection of Elixir Livebooks for Supabase
Dockerfile
21
star
66

terraform-provider-supabase

Go
21
star
67

storage-dart

Dart client library to interact with Supabase Storage
Dart
21
star
68

orb-sync-engine

TypeScript
12
star
69

auth-elements

Components to add Supabase Auth to any application
TypeScript
11
star
70

rfcs

11
star
71

.github

Org-wide default community health files & templates.
10
star
72

functions-dart

Dart
8
star
73

test-reports

Repository to store test reports data and host reporting in gh-pages
7
star
74

plug_caisson

An Elixir Plug library for handling compressed requests
Elixir
7
star
75

flyswatter

Deploy a global pinger on Fly
Elixir
6
star
76

scoop-bucket

5
star
77

tests

TypeScript
4
star
78

pgextkit

Rust
3
star
79

homebrew-tap

Ruby
3
star
80

fly-preview

TypeScript
3
star
81

shared-types

TypeScript
3
star
82

supa_type

The Missing PostgreSQL Data Types
Nix
3
star
83

test-inspector

Check your test results against the reference run and compare coverage for multiple client libraries
Go
2
star
84

mailme

A clone of Netlify's mailme package used in Supabase Auth / GoTrue.
Go
2
star
85

productions

Supabase SynthWave. The best soundtrack to build an app in a weekend and scale to billions.
TypeScript
1
star
86

design-tokens

1
star