File size: 12,942 Bytes
25f22bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
======================== CODE SNIPPETS ======================== TITLE: Install Supabase Python Client via pip DESCRIPTION: This snippet shows how to install the `supabase-py` package using pip, the Python package installer. This is the standard way to install Python libraries from PyPI. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_3 LANGUAGE: bash CODE: ``` # with pip pip install supabase ``` ---------------------------------------- TITLE: Install Supabase Python Client in Editable Mode DESCRIPTION: This snippet explains how to install the `supabase-py` package locally in 'editable' mode using `pip install -e`. This is useful for development, as changes made to the source code are immediately reflected in the installed package without reinstallation. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_5 LANGUAGE: bash CODE: ``` pip install -e ``` ---------------------------------------- TITLE: Install Supabase Python Client via Conda DESCRIPTION: This snippet demonstrates how to install the `supabase-py` package using Conda from the `conda-forge` channel. This method is suitable for users who prefer Conda for package management. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_4 LANGUAGE: bash CODE: ``` # with conda conda install -c conda-forge supabase ``` ---------------------------------------- TITLE: Initialize Supabase Python Client DESCRIPTION: This Python snippet demonstrates how to initialize the Supabase client using the `create_client` function. It retrieves the Supabase URL and API key from environment variables, which is a recommended practice for security. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_7 LANGUAGE: python CODE: ``` 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) ``` ---------------------------------------- TITLE: Sign Up a New User with Supabase Auth DESCRIPTION: This Python snippet shows how to register a new user with an email and password using the Supabase authentication service. The `sign_up` method returns the user object upon successful creation. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_8 LANGUAGE: python CODE: ``` user = supabase.auth.sign_up({ "email": users_email, "password": users_password }) ``` ---------------------------------------- TITLE: Clone Supabase Python Client Repository DESCRIPTION: This snippet demonstrates how to clone the `supabase-py` GitHub repository to your local machine and navigate into its directory, which is the first step for local development. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_0 LANGUAGE: bash CODE: ``` git clone https://github.com/supabase/supabase-py.git cd supabase-py ``` ---------------------------------------- TITLE: Create and Activate Python Virtual Environment (venv) DESCRIPTION: This snippet shows how to create and activate a Python virtual environment using the built-in `venv` module. A virtual environment isolates project dependencies, preventing conflicts with other Python projects. The activation command differs slightly for Windows. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_1 LANGUAGE: bash CODE: ``` python3 -m venv env source env/bin/activate # On Windows, use .\env\Scripts\activate ``` ---------------------------------------- TITLE: Execute Supabase-py Test Suite DESCRIPTION: This command runs the test scripts for the Supabase Python client library. It connects to a pre-populated test database instance, which includes a `countries` table. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_22 LANGUAGE: bash CODE: ``` ./test.sh ``` ---------------------------------------- TITLE: Create and Activate Conda Environment DESCRIPTION: This snippet demonstrates how to create and activate a dedicated Conda environment for the `supabase-py` project. Conda is a popular package, dependency, and environment management system for multiple languages. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_2 LANGUAGE: bash CODE: ``` conda create --name supabase-py conda activate supabase-py ``` ---------------------------------------- TITLE: Set Supabase Environment Variables DESCRIPTION: This snippet shows how to set the `SUPABASE_URL` and `SUPABASE_KEY` environment variables in your shell. These variables are crucial for the Supabase client to connect to your specific Supabase instance securely. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_6 LANGUAGE: bash CODE: ``` export SUPABASE_URL="my-url-to-my-awesome-supabase-instance" export SUPABASE_KEY="my-supa-dupa-secret-supabase-api-key" ``` ---------------------------------------- TITLE: Sign In an Existing User with Supabase Auth DESCRIPTION: This Python snippet demonstrates how to authenticate an existing user using their email and password via the Supabase authentication service. The `sign_in_with_password` method returns the authenticated user object. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_9 LANGUAGE: python CODE: ``` user = supabase.auth.sign_in_with_password({ "email": users_email, "password": users_password }) ``` ---------------------------------------- TITLE: Supabase Python Storage Bucket API Module Definition DESCRIPTION: This entry specifies the API documentation for the `supabase.lib.storage.storage_bucket_api` module. It utilizes Sphinx's `automodule` directive to automatically generate documentation for all public members and display the inheritance hierarchy of classes within the module. SOURCE: https://github.com/supabase/supabase-py/blob/main/docs/storage_bucket.rst#_snippet_0 LANGUAGE: APIDOC CODE: ``` .. automodule:: supabase.lib.storage.storage_bucket_api :members: :show-inheritance: ``` ---------------------------------------- TITLE: List Files in Supabase Storage Bucket DESCRIPTION: This Python snippet demonstrates how to list all files within a specified Supabase Storage bucket. It provides an overview of the bucket's contents. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_19 LANGUAGE: python CODE: ``` bucket_name: str = "charts" data = supabase.storage.from_(bucket_name).list() ``` ---------------------------------------- TITLE: Download File from Supabase Storage DESCRIPTION: This Python snippet demonstrates how to download a file from a specified Supabase Storage bucket. It uses the `download` method, providing the file path within the bucket. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_16 LANGUAGE: python CODE: ``` bucket_name: str = "photos" data = supabase.storage.from_(bucket_name).download("photo1.png") ``` ---------------------------------------- TITLE: Select Data from Supabase Table DESCRIPTION: This Python snippet demonstrates how to query and retrieve data from a Supabase table. It uses the `select` method to specify columns (or all with `*`) and `eq` to filter results based on a condition, followed by `execute()`. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_11 LANGUAGE: python CODE: ``` data = supabase.table("countries").select("*").eq("country", "IL").execute() # Assert we pulled real data. assert len(data.data) > 0 ``` ---------------------------------------- TITLE: Supabase Python Query Builder Module API Reference DESCRIPTION: This entry documents the `supabase.lib.query_builder` module using Sphinx's `automodule` directive. This directive automatically generates comprehensive API documentation, including all public members and the inheritance hierarchy for the specified Python module. SOURCE: https://github.com/supabase/supabase-py/blob/main/docs/query_builder.rst#_snippet_0 LANGUAGE: APIDOC CODE: ``` .. automodule:: supabase.lib.query_builder :members: :show-inheritance: ``` ---------------------------------------- TITLE: Upload File to Supabase Storage DESCRIPTION: This Python snippet shows how to upload a new file to a Supabase Storage bucket. It specifies the destination path within the bucket and the file content to be uploaded. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_17 LANGUAGE: python CODE: ``` bucket_name: str = "photos" new_file = getUserFile() data = supabase.storage.from_(bucket_name).upload("/user1/profile.png", new_file) ``` ---------------------------------------- TITLE: Insert Data into Supabase Table DESCRIPTION: This Python snippet illustrates how to insert a new row into a specified Supabase table. It uses the `insert` method, chaining it with `execute()` to perform the operation and retrieve the result. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_10 LANGUAGE: python CODE: ``` data = supabase.table("countries").insert({"name":"Germany"}).execute() # Assert we pulled real data. assert len(data.data) > 0 ``` ---------------------------------------- TITLE: Invoke Supabase Edge Function DESCRIPTION: This Python snippet shows how to call a Supabase Edge Function by its name using the `invoke` method. It includes error handling for `FunctionsRelayError` and `FunctionsHttpError`, demonstrating how to catch and print function-related exceptions. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_15 LANGUAGE: python CODE: ``` 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")) ``` ---------------------------------------- TITLE: Move and Rename Files in Supabase Storage DESCRIPTION: This Python snippet shows how to move a file from one path to another within a Supabase Storage bucket, effectively allowing for renaming or reorganizing files. It requires both the old and new file paths. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_20 LANGUAGE: python CODE: ``` 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) ``` ---------------------------------------- TITLE: Proper Supabase Client Shutdown in Python DESCRIPTION: To ensure the Supabase client terminates correctly and to prevent resource leaks, you must explicitly call the `sign_out()` method on the `auth` object of your client instance. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_21 LANGUAGE: python CODE: ``` client.auth.sign_out() ``` ---------------------------------------- TITLE: Upsert Data into Supabase Table DESCRIPTION: This Python snippet demonstrates how to perform an 'upsert' operation, which inserts a new row if it doesn't exist or updates it if it does. It's useful for handling data with potential duplicate keys gracefully. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_13 LANGUAGE: python CODE: ``` 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 ``` ---------------------------------------- TITLE: Update Data in Supabase Table DESCRIPTION: This Python snippet shows how to update existing rows in a Supabase table. It uses the `update` method with a dictionary of new values and `eq` to specify which rows to update based on a condition. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_12 LANGUAGE: python CODE: ``` data = supabase.table("countries").update({"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute() ``` ---------------------------------------- TITLE: Remove Files from Supabase Storage DESCRIPTION: This Python snippet illustrates how to delete one or more files from a Supabase Storage bucket. It accepts a list of file paths to be removed. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_18 LANGUAGE: python CODE: ``` bucket_name: str = "photos" data = supabase.storage.from_(bucket_name).remove(["old_photo.png", "image5.jpg"]) ``` ---------------------------------------- TITLE: Delete Data from Supabase Table DESCRIPTION: This Python snippet illustrates how to delete rows from a Supabase table. It uses the `delete` method combined with `eq` to specify the criteria for deletion. SOURCE: https://github.com/supabase/supabase-py/blob/main/README.md#_snippet_14 LANGUAGE: python CODE: ``` data = supabase.table("countries").delete().eq("id", 1).execute() ``` |