Skip to content

Commit

Permalink
Merge pull request #1 from fedden/master
Browse files Browse the repository at this point in the history
Upstream merge of the fork^2 of supabase-py
  • Loading branch information
J0 authored Feb 7, 2021
2 parents e06b143 + ccb88f8 commit 0dc431d
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 170 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
tags
## Vim stuff
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
59 changes: 45 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,66 @@

Supabase client for Python. This mirrors the design of [supabase-js](https://github.com/supabase/supabase-js/blob/master/README.md)

## Usage
## Installation

`pip3 install supabase`
**Recomended:** First activate your virtual environment, with your favourites system. For example, we like `poetry` and `conda`!

#### PyPi installation
Now install the package.
```bash
pip install supabase
```

#### Local installation
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.
```bash
pip install -e .
```

## 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.
```bash
export SUPABASE_URL="my-url-to-my-awesome-supabase-instance"
export SUPABASE_KEY="my-supa-dupa-secret-supabase-api-key"
```
import supabase_py
supabaseUrl=""
supabaseKey=""
supabase = supabase_py.Client(supabaseUrl, supabaseKey)

We can then read the keys in the python source code.
```python
import os
from supabase_py import create_client, Client

url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
email = "abcdde@gmail.com"
password = "password"
supabase: Client = create_client(url, key)
user = supabase.auth.sign_up(email, password)
```

### Run tests
`python3 -m pytest`
### 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:
<p align="center">
<img width="720" height="481" src="https://i.ibb.co/Bq7Kdty/db.png">
</p>

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
```bash
SUPABASE_TEST_KEY="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYxMjYwOTMyMiwiZXhwIjoxOTI4MTg1MzIyfQ.XL9W5I_VRQ4iyQHVQmjG0BkwRfx6eVyYB3uAKcesukg" \
SUPABASE_TEST_URL="https://tfsatoopsijgjhrqplra.supabase.co" \
pytest -x
```

### See issues for what to work on

Rough roadmap:
- [] Wrap [Postgrest-py](https://github.com/supabase/postgrest-py/)
- [] Wrap [Realtime-py](https://github.com/supabase/realtime-py)
- [ ] Wrap [Postgrest-py](https://github.com/supabase/postgrest-py/)
- [ ] Wrap [Realtime-py](https://github.com/supabase/realtime-py)
- [x] Wrap [Gotrue-py](https://github.com/J0/gotrue-py)



### Client Library

This is a sample of how you'd use [supabase-py]. Functions and tests are WIP


## Authenticate
```
supabase.auth.signUp({
Expand Down Expand Up @@ -79,4 +110,4 @@ mySubscription = supabase
.on('*', lambda x: print(x))
.subscribe()
```
See [Supabase Docs](https://supabase.io/docs/guides/client-libraries) for full list of examples
See [Supabase Docs](https://supabase.io/docs/guides/client-libraries) for full list of examples
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ python = "^3.7.1"
postgrest-py = "^0.3.2"
realtime-py="^0.1.0"
gotrue="0.1.2"

pytest="6.2.2"
supabase-realtime-py="0.1.1a0"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
requires = [
"poetry>=0.12",
"setuptools>=30.3.0,<50",
]
build-backend = "poetry.masonry.api"
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python

import setuptools

if __name__ == "__main__":
setuptools.setup()
11 changes: 9 additions & 2 deletions supabase_py/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
from .lib import *
from .client import Client
# Retain module level imports for structured imports in tests etc.
from . import lib
from . import client

# Open up the client and function as an easy import.
from .client import Client, create_client


__version__ = "0.0.1"
Loading

0 comments on commit 0dc431d

Please sign in to comment.