|
1 | 1 | # supabase-py
|
2 | 2 |
|
3 |
| -Supabase client for Python. |
| 3 | +[](https://gotrue-py.readthedocs.io/en/latest/?badge=latest) |
4 | 4 |
|
5 |
| -### See issues for what to work on |
| 5 | +Supabase client for Python. This mirrors the design of [supabase-js](https://github.com/supabase/supabase-js/blob/master/README.md) |
6 | 6 |
|
7 |
| -Rough roadmap: |
| 7 | +## Installation |
| 8 | + |
| 9 | +**Recomended:** First activate your virtual environment, with your favourites system. For example, we like `poetry` and `conda`! |
| 10 | + |
| 11 | +#### PyPi installation |
| 12 | +Now install the package. |
| 13 | +```bash |
| 14 | +pip install supabase |
| 15 | +``` |
| 16 | + |
| 17 | +#### Local installation |
| 18 | +You can also installing from after cloning this repo. Install like below to install in Development Mode, which means when you edit the source code the changes will be reflected in your python module. |
| 19 | +```bash |
| 20 | +pip install -e . |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | +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. |
| 25 | +```bash |
| 26 | +export SUPABASE_URL="my-url-to-my-awesome-supabase-instance" |
| 27 | +export SUPABASE_KEY="my-supa-dupa-secret-supabase-api-key" |
| 28 | +``` |
8 | 29 |
|
| 30 | +We can then read the keys in the python source code. |
| 31 | +```python |
| 32 | +import os |
| 33 | +from supabase_py import create_client, Client |
| 34 | + |
| 35 | +url: str = os.environ.get("SUPABASE_URL") |
| 36 | +key: str = os.environ.get("SUPABASE_KEY") |
| 37 | + |
| 38 | +password = "password" |
| 39 | +supabase: Client = create_client(url, key) |
| 40 | +user = supabase.auth.sign_up(email, password) |
| 41 | +``` |
| 42 | + |
| 43 | +### Running Tests |
| 44 | +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: |
| 45 | +<p align="center"> |
| 46 | + <img width="720" height="481" src="https://i.ibb.co/Bq7Kdty/db.png"> |
| 47 | +</p> |
| 48 | + |
| 49 | +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 with the |
| 50 | +```bash |
| 51 | +SUPABASE_TEST_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYxMjYwOTMyMiwiZXhwIjoxOTI4MTg1MzIyfQ.XL9W5I_VRQ4iyQHVQmjG0BkwRfx6eVyYB3uAKcesukg" \ |
| 52 | +SUPABASE_TEST_URL="https://tfsatoopsijgjhrqplra.supabase.co" \ |
| 53 | +pytest -x |
| 54 | +``` |
| 55 | + |
| 56 | +### See issues for what to work on |
| 57 | +Rough roadmap: |
9 | 58 | - [ ] Wrap [Postgrest-py](https://github.com/supabase/postgrest-py/)
|
10 |
| -- [ ] Write Realtime-py (Use [realtime-js](https://github.com/supabase/realtime-js) as reference implementation) (implementation started by @Jeffery Kwoh @Joel and @Lionell Loh) |
11 |
| -- [ ] Wrap Realtime-py (Use [supabase-js](https://github.com/supabase/supabase-js) as reference implementation) |
12 |
| -- [ ] Write Gotrue-py (for auth) (Use [gotrue-js](https://github.com/netlify/gotrue-js) as reference implementation) |
13 |
| -- [ ] Wrap Gotrue-py |
| 59 | +- [ ] Wrap [Realtime-py](https://github.com/supabase/realtime-py) |
| 60 | +- [x] Wrap [Gotrue-py](https://github.com/J0/gotrue-py) |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +### Client Library |
| 65 | +This is a sample of how you'd use [supabase-py]. Functions and tests are WIP |
| 66 | + |
| 67 | +## Authenticate |
| 68 | +``` |
| 69 | +supabase.auth.signUp({ |
| 70 | + |
| 71 | + "password": 'example-password', |
| 72 | +}) |
| 73 | +``` |
| 74 | + |
| 75 | + |
| 76 | +## Sign-in |
| 77 | +``` |
| 78 | +supabase.auth.signIn({ |
| 79 | + |
| 80 | + "password": 'example-password', |
| 81 | +}) |
| 82 | +``` |
| 83 | + |
| 84 | + |
| 85 | +## Sign-in(Auth provider). This is not supported yet |
| 86 | +``` |
| 87 | +supabase.auth.signIn({ |
| 88 | + // provider can be 'github', 'google', 'gitlab', or 'bitbucket' |
| 89 | + "provider": 'github' |
| 90 | +}) |
| 91 | +``` |
| 92 | + |
| 93 | + |
| 94 | +## Managing Data |
| 95 | +``` |
| 96 | +supabase |
| 97 | + .from('countries') |
| 98 | + .select(" |
| 99 | + name, |
| 100 | + cities ( |
| 101 | + name |
| 102 | + ) |
| 103 | + ") |
| 104 | +``` |
| 105 | + |
| 106 | +## Realtime Changes |
| 107 | +``` |
| 108 | +mySubscription = supabase |
| 109 | + .from('countries') |
| 110 | + .on('*', lambda x: print(x)) |
| 111 | + .subscribe() |
| 112 | + ``` |
| 113 | +See [Supabase Docs](https://supabase.io/docs/guides/client-libraries) for full list of examples |
0 commit comments