Skip to content

Commit 7282188

Browse files
committed
chore: move supabase-py to a sub package
make `supabase-py` a sub package, and make the workspace root a virtual workspace that contains no "main package". this is in order to have more homogeneity around the packages, as before the `supabase-py` was treated specially (pyproject in the root instead of in `src/supabase`).
1 parent 80fd94f commit 7282188

File tree

10 files changed

+408
-338
lines changed

10 files changed

+408
-338
lines changed

README.md

Lines changed: 7 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# `supabase-py`
22

3-
Python client for [Supabase](https://supabase.com)
3+
Python monorepo for all [Supabase](https://supabase.com) libraries.
4+
5+
- [supabase](src/supabase/README.md)
6+
- [realtime](src/realtime/README.md)
7+
8+
Relevant links:
49

510
- Documentation: [supabase.com/docs](https://supabase.com/docs/reference/python/introduction)
611
- Usage:
@@ -24,6 +29,7 @@ Using uv:
2429
```
2530
uv venv supabase-py
2631
source supabase-py/bin/activate
32+
uv sync
2733
```
2834

2935
Using venv (Python 3 built-in):
@@ -40,154 +46,10 @@ conda create --name supabase-py
4046
conda activate supabase-py
4147
```
4248

43-
### PyPI installation
44-
45-
Install the package (for Python >= 3.9):
46-
47-
```bash
48-
# with pip
49-
pip install supabase
50-
51-
# with conda
52-
conda install -c conda-forge supabase
53-
```
54-
5549
### Local installation
5650

5751
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.
5852

59-
## Usage
60-
61-
Set your Supabase environment variables in a dotenv file, or using the shell:
62-
63-
```bash
64-
export SUPABASE_URL="my-url-to-my-awesome-supabase-instance"
65-
export SUPABASE_KEY="my-supa-dupa-secret-supabase-api-key"
66-
```
67-
68-
Init client:
69-
70-
```python
71-
import os
72-
from supabase import create_client, Client
73-
74-
url: str = os.environ.get("SUPABASE_URL")
75-
key: str = os.environ.get("SUPABASE_KEY")
76-
supabase: Client = create_client(url, key)
77-
```
78-
79-
Use the supabase client to interface with your database.
80-
81-
### Sign-up
82-
83-
```python
84-
user = supabase.auth.sign_up({ "email": users_email, "password": users_password })
85-
```
86-
87-
### Sign-in
88-
89-
```python
90-
user = supabase.auth.sign_in_with_password({ "email": users_email, "password": users_password })
91-
```
92-
93-
### Insert Data
94-
95-
```python
96-
data = supabase.table("countries").insert({"name":"Germany"}).execute()
97-
98-
# Assert we pulled real data.
99-
assert len(data.data) > 0
100-
```
101-
102-
### Select Data
103-
104-
```python
105-
data = supabase.table("countries").select("*").eq("country", "IL").execute()
106-
107-
# Assert we pulled real data.
108-
assert len(data.data) > 0
109-
```
110-
111-
### Update Data
112-
113-
```python
114-
data = supabase.table("countries").update({"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute()
115-
```
116-
117-
### Update data with duplicate keys
118-
119-
```python
120-
country = {
121-
"country": "United Kingdom",
122-
"capital_city": "London" # This was missing when it was added
123-
}
124-
125-
data = supabase.table("countries").upsert(country).execute()
126-
assert len(data.data) > 0
127-
```
128-
129-
### Delete Data
130-
131-
```python
132-
data = supabase.table("countries").delete().eq("id", 1).execute()
133-
```
134-
135-
### Call Edge Functions
136-
137-
```python
138-
def test_func():
139-
try:
140-
resp = supabase.functions.invoke("hello-world", invoke_options={'body':{}})
141-
return resp
142-
except (FunctionsRelayError, FunctionsHttpError) as exception:
143-
err = exception.to_dict()
144-
print(err.get("message"))
145-
```
146-
147-
### Download a file from Storage
148-
149-
```python
150-
bucket_name: str = "photos"
151-
152-
data = supabase.storage.from_(bucket_name).download("photo1.png")
153-
```
154-
155-
### Upload a file
156-
157-
```python
158-
bucket_name: str = "photos"
159-
new_file = getUserFile()
160-
161-
data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file)
162-
```
163-
164-
### Remove a file
165-
166-
```python
167-
bucket_name: str = "photos"
168-
169-
data = supabase.storage.from_(bucket_name).remove(["old_photo.png", "image5.jpg"])
170-
```
171-
172-
### List all files
173-
174-
```python
175-
bucket_name: str = "charts"
176-
177-
data = supabase.storage.from_(bucket_name).list()
178-
```
179-
180-
### Move and rename files
181-
182-
```python
183-
bucket_name: str = "charts"
184-
old_file_path: str = "generic/graph1.png"
185-
new_file_path: str = "important/revenue.png"
186-
187-
data = supabase.storage.from_(bucket_name).move(old_file_path, new_file_path)
188-
```
189-
190-
19153
## Roadmap
19254

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

266128
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.
267129

268-
## Important: Proper Client Shutdown
269-
270-
To ensure the Supabase client terminates correctly and to prevent resource leaks, you **must** explicitly call:
271-
272-
```python
273-
client.auth.sign_out()
274-
```
275-
276130
### Running Tests
277131

278132
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:

flake.lock

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
description = "realtime-py: a Realtime python client.";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6+
pyproject-nix = {
7+
url = "github:pyproject-nix/pyproject.nix";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
10+
uv2nix = {
11+
url = "github:pyproject-nix/uv2nix";
12+
inputs.pyproject-nix.follows = "pyproject-nix";
13+
inputs.nixpkgs.follows = "nixpkgs";
14+
};
15+
pyproject-build-systems = {
16+
url = "github:pyproject-nix/build-system-pkgs";
17+
inputs.pyproject-nix.follows = "pyproject-nix";
18+
inputs.uv2nix.follows = "uv2nix";
19+
inputs.nixpkgs.follows = "nixpkgs";
20+
};
21+
};
22+
23+
outputs = { nixpkgs, pyproject-nix, uv2nix, pyproject-build-systems, ... }: let
24+
for-all-systems = f:
25+
nixpkgs.lib.genAttrs [
26+
"x86_64-linux"
27+
"aarch64-darwin"
28+
"aarch64-linux"
29+
"x86_64-darwin"
30+
] (system: f nixpkgs.legacyPackages.${system});
31+
32+
dev-tools = pkgs: [
33+
pkgs.supabase-cli
34+
pkgs.just
35+
pkgs.uv
36+
];
37+
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
38+
39+
workspace-overlay = workspace.mkPyprojectOverlay {
40+
sourcePreference = "wheel"; # or sourcePreference = "sdist";
41+
};
42+
43+
python-for = pkgs: let
44+
extensions = pkgs.lib.composeManyExtensions [
45+
pyproject-build-systems.overlays.default
46+
workspace-overlay
47+
];
48+
base-python = pkgs.callPackage pyproject-nix.build.packages {
49+
python = pkgs.python311;
50+
};
51+
in base-python.overrideScope extensions;
52+
in {
53+
devShells = for-all-systems (pkgs: let
54+
python = python-for pkgs;
55+
python-env = python.mkVirtualEnv "supabase-py" workspace.deps.all;
56+
in {
57+
default = pkgs.mkShell {
58+
packages = [ python-env ] ++ (dev-tools pkgs);
59+
};
60+
});
61+
};
62+
}

justfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# commands related to realtime
2+
[group("package")]
3+
[doc("realtime commands")]
24
mod realtime "src/realtime/mod.just"
3-
# commands related to supabase
5+
[doc("supabase commands")]
6+
[group("package")]
47
mod supabase "src/supabase/mod.just"
58

69
[doc("Lists all available commands")]
710
default:
811
@just --list
9-
12+
1013
[doc("Run all available tests")]
1114
test: realtime::pytest && supabase::pytest
1215

0 commit comments

Comments
 (0)