@@ -36,7 +36,7 @@ export SUPABASE_URL="my-url-to-my-awesome-supabase-instance"
3636export SUPABASE_KEY=" my-supa-dupa-secret-supabase-api-key"
3737```
3838
39- We can then read the keys in the python source code :
39+ Init client :
4040
4141``` python
4242import os
@@ -49,79 +49,45 @@ supabase: Client = create_client(url, key)
4949
5050Use the supabase client to interface with your database.
5151
52- #### Authenticate
52+ #### Sign-up
5353
5454``` python
55- from supabase import create_client, Client
56-
57- url: str = os.environ.get(" SUPABASE_TEST_URL" )
58- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
59- supabase: Client = create_client(url, key)
60- # Create a random user login email and password.
61- random_email:
str = " [email protected] " 62- random_password: str = " fqj13bnf2hiu23h"
63- user = supabase.auth.sign_up({ " email" : random_email, " password" : random_password })
55+ user = supabase.auth.sign_up({ " email" : users_email, " password" : users_password })
6456```
6557
6658#### Sign-in
6759
6860``` python
69- from supabase import create_client, Client
70-
71- url: str = os.environ.get(" SUPABASE_TEST_URL" )
72- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
73- supabase: Client = create_client(url, key)
74- # Sign in using the user email and password.
75- random_email:
str = " [email protected] " 76- random_password: str = " fqj13bnf2hiu23h"
77- user = supabase.auth.sign_in_with_password({ " email" : random_email, " password" : random_password })
61+ user = supabase.auth.sign_in_with_password({ " email" : users_email, " password" : users_password })
7862```
7963
8064#### Insert Data
8165
8266``` python
83- from supabase import create_client, Client
84-
85- url: str = os.environ.get(" SUPABASE_TEST_URL" )
86- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
87- supabase: Client = create_client(url, key)
8867data = supabase.table(" countries" ).insert({" name" :" Germany" }).execute()
68+
69+ # Assert we pulled real data.
8970assert len (data.data) > 0
9071```
9172
9273#### Select Data
9374
9475``` python
95- from supabase import create_client, Client
96-
97- url: str = os.environ.get(" SUPABASE_TEST_URL" )
98- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
99- supabase: Client = create_client(url, key)
10076data = supabase.table(" countries" ).select(" *" ).eq(" country" , " IL" ).execute()
77+
10178# Assert we pulled real data.
10279assert len (data.data) > 0
10380```
10481
10582#### Update Data
10683
10784``` python
108- from supabase import create_client, Client
109-
110- url: str = os.environ.get(" SUPABASE_TEST_URL" )
111- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
112- supabase: Client = create_client(url, key)
11385data = supabase.table(" countries" ).update({" country" : " Indonesia" , " capital_city" : " Jakarta" }).eq(" id" , 1 ).execute()
11486```
11587
11688#### Update data with duplicate keys
11789
11890``` python
119- from supabase import create_client, Client
120-
121- url: str = os.environ.get(" SUPABASE_TEST_URL" )
122- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
123- supabase: Client = create_client(url, key)
124-
12591country = {
12692 " country" : " United Kingdom" ,
12793 " capital_city" : " London" # this was missing when it was added
@@ -134,23 +100,12 @@ assert len(data.data) > 0
134100#### Delete Data
135101
136102``` python
137- from supabase import create_client, Client
138-
139- url: str = os.environ.get(" SUPABASE_TEST_URL" )
140- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
141- supabase: Client = create_client(url, key)
142103data = supabase.table(" countries" ).delete().eq(" id" , 1 ).execute()
143104```
144105
145106#### Call Edge Functions
146107
147108``` python
148- from supabase import create_client, Client
149-
150- url: str = os.environ.get(" SUPABASE_TEST_URL" )
151- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
152- supabase: Client = create_client(url, key)
153-
154109def test_func ():
155110 try :
156111 resp = supabase.functions.invoke(" hello-world" , invoke_options = {' body' :{}})
@@ -163,12 +118,6 @@ def test_func():
163118#### Download a file from Storage
164119
165120``` python
166- from supabase import create_client, Client
167-
168- url: str = os.environ.get(" SUPABASE_TEST_URL" )
169- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
170- supabase: Client = create_client(url, key)
171-
172121bucket_name: str = " photos"
173122
174123data = supabase.storage.from_(bucket_name).download(" photo1.png" )
@@ -177,12 +126,6 @@ data = supabase.storage.from_(bucket_name).download("photo1.png")
177126#### Upload a file
178127
179128``` python
180- from supabase import create_client, Client
181-
182- url: str = os.environ.get(" SUPABASE_TEST_URL" )
183- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
184- supabase: Client = create_client(url, key)
185-
186129bucket_name: str = " photos"
187130new_file = getUserFile()
188131
@@ -192,12 +135,6 @@ data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file
192135#### Remove a file
193136
194137``` python
195- from supabase import create_client, Client
196-
197- url: str = os.environ.get(" SUPABASE_TEST_URL" )
198- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
199- supabase: Client = create_client(url, key)
200-
201138bucket_name: str = " photos"
202139
203140data = supabase.storage.from_(bucket_name).remove([" old_photo.png" , " image5.jpg" ])
@@ -206,12 +143,6 @@ data = supabase.storage.from_(bucket_name).remove(["old_photo.png", "image5.jpg"
206143#### List all files
207144
208145``` python
209- from supabase import create_client, Client
210-
211- url: str = os.environ.get(" SUPABASE_TEST_URL" )
212- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
213- supabase: Client = create_client(url, key)
214-
215146bucket_name: str = " charts"
216147
217148data = supabase.storage.from_(bucket_name).list()
@@ -220,12 +151,6 @@ data = supabase.storage.from_(bucket_name).list()
220151#### Move and rename files
221152
222153``` python
223- from supabase import create_client, Client
224-
225- url: str = os.environ.get(" SUPABASE_TEST_URL" )
226- key: str = os.environ.get(" SUPABASE_TEST_KEY" )
227- supabase: Client = create_client(url, key)
228-
229154bucket_name: str = " charts"
230155old_file_path: str = " generic/graph1.png"
231156new_file_path: str = " important/revenue.png"
0 commit comments