Skip to content

chore: switch to monorepo, move realtime inside #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ jobs:
- name: Clone Repository
uses: actions/checkout@v5

- name: Install supabase cli latest
uses: supabase/setup-cli@v1

- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "0.8.2"
python-version: ${{ matrix.python-version }}

- uses: extractions/setup-just@v3

- name: Run Tests
run: uv run tests
run: just ci

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
Expand Down
161 changes: 10 additions & 151 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# `supabase-py`

Python client for [Supabase](https://supabase.com)
Python monorepo for all [Supabase](https://supabase.com) libraries. This is a work in progress, and currently these are the ones contained in this repository:

- [supabase](src/supabase/README.md)
- [realtime](src/realtime/README.md)

Relevant links:

- Documentation: [supabase.com/docs](https://supabase.com/docs/reference/python/introduction)
- Usage:
Expand All @@ -18,12 +23,13 @@ cd supabase-py

### Create and Activate a Virtual Environment

We recommend activating your virtual environment. For example, we like `uv` and `conda`! Click [here](https://docs.python.org/3/library/venv.html) for more about Python virtual environments and working with [conda](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment) and [uv](https://docs.astral.sh/uv/getting-started/features/).
We recommend activating your virtual environment. For example, we like `uv`, `conda` and `nix`! Click [here](https://docs.python.org/3/library/venv.html) for more about Python virtual environments and working with [conda](https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment) and [uv](https://docs.astral.sh/uv/getting-started/features/). For nix, just install it with flakes enabled.

Using uv:
```
uv venv supabase-py
source supabase-py/bin/activate
uv sync
```

Using venv (Python 3 built-in):
Expand All @@ -40,154 +46,15 @@ conda create --name supabase-py
conda activate supabase-py
```

### PyPI installation

Install the package (for Python >= 3.9):

Using nix:
```bash
# with pip
pip install supabase

# with conda
conda install -c conda-forge supabase
nix develop
```

### Local installation

You can also install locally after cloning this repo. Install Development mode with `pip install -e`, which makes it editable, 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:

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

Init client:

```python
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

```python
user = supabase.auth.sign_up({ "email": users_email, "password": users_password })
```

### Sign-in

```python
user = supabase.auth.sign_in_with_password({ "email": users_email, "password": users_password })
```

### Insert Data

```python
data = supabase.table("countries").insert({"name":"Germany"}).execute()

# Assert we pulled real data.
assert len(data.data) > 0
```

### Select Data

```python
data = supabase.table("countries").select("*").eq("country", "IL").execute()

# Assert we pulled real data.
assert len(data.data) > 0
```

### Update Data

```python
data = supabase.table("countries").update({"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute()
```

### Update data with duplicate keys

```python
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

```python
data = supabase.table("countries").delete().eq("id", 1).execute()
```

### Call Edge Functions

```python
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

```python
bucket_name: str = "photos"

data = supabase.storage.from_(bucket_name).download("photo1.png")
```

### Upload a file

```python
bucket_name: str = "photos"
new_file = getUserFile()

data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file)
```

### Remove a file

```python
bucket_name: str = "photos"

data = supabase.storage.from_(bucket_name).remove(["old_photo.png", "image5.jpg"])
```

### List all files

```python
bucket_name: str = "charts"

data = supabase.storage.from_(bucket_name).list()
```

### Move and rename files

```python
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

- [x] Wrap [Postgrest-py](https://github.com/supabase/postgrest-py/)
Expand Down Expand Up @@ -265,14 +132,6 @@ data = supabase.storage.from_(bucket_name).move(old_file_path, new_file_path)

Contributing to the Python libraries are a great way to get involved with the Supabase community. Reach out to us on [Discord](https://discord.supabase.com) or on our [Github Discussions](https://github.com/orgs/supabase/discussions) page if you want to get involved.

## Important: Proper Client Shutdown

To ensure the Supabase client terminates correctly and to prevent resource leaks, you **must** explicitly call:

```python
client.auth.sign_out()
```

### 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, which is populated with the following table:
Expand Down
45 changes: 0 additions & 45 deletions cli_scripts.py

This file was deleted.

99 changes: 99 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading