|
1 | 1 | # Functions-py
|
2 | 2 |
|
3 | 3 | ## Installation
|
4 |
| - |
5 |
| -`pip3 install supabase_functions` |
| 4 | +The package can be installed using pip, uv or poetry: |
| 5 | +### Pip |
| 6 | +```bash |
| 7 | +pip install supabase_functions |
| 8 | +``` |
| 9 | +### UV |
| 10 | +```bash |
| 11 | +uv add supabase_functions |
| 12 | +``` |
| 13 | +### Poetry |
| 14 | +```bash |
| 15 | +poetry add supabase_functions |
| 16 | +``` |
6 | 17 |
|
7 | 18 | ## Usage
|
8 | 19 |
|
9 |
| -Deploy your function as per documentation. |
| 20 | +Deploy your Edge Function following the [Supabase Functions documentation](https://supabase.com/docs/guides/functions). |
| 21 | + |
10 | 22 |
|
| 23 | +### Asynchronous Client |
11 | 24 |
|
12 |
| -```python3 |
| 25 | +```python |
13 | 26 | import asyncio
|
14 | 27 | from supabase_functions import AsyncFunctionsClient
|
| 28 | + |
15 | 29 | async def run_func():
|
16 |
| - fc = AsyncFunctionsClient("https://<project_ref>.functions.supabase.co", {}) |
17 |
| - res = await fc.invoke("payment-sheet", {"responseType": "json"}) |
| 30 | + # Initialize the client with your project URL and optional headers |
| 31 | + headers = { |
| 32 | + "Authorization": "Bearer your-anon-key", |
| 33 | + # Add any other headers you might need |
| 34 | + } |
| 35 | + |
| 36 | + fc = AsyncFunctionsClient("https://<project_ref>.functions.supabase.co", headers) |
| 37 | + |
| 38 | + try: |
| 39 | + # Invoke your Edge Function |
| 40 | + res = await fc.invoke("payment-sheet", { |
| 41 | + "responseType": "json", |
| 42 | + "body": {"amount": 1000, "currency": "usd"} |
| 43 | + }) |
| 44 | + print("Response:", res) |
| 45 | + except Exception as e: |
| 46 | + print(f"Error: {e}") |
18 | 47 |
|
19 | 48 | if __name__ == "__main__":
|
20 | 49 | asyncio.run(run_func())
|
21 | 50 | ```
|
| 51 | +### Synchronous Client |
| 52 | +```python |
| 53 | +from supabase_functions import SyncFunctionsClient |
| 54 | + |
| 55 | +# Initialize the client |
| 56 | +headers = {"Authorization": "Bearer your-anon-key"} |
| 57 | +fc = SyncFunctionsClient("https://<project_ref>.functions.supabase.co", headers) |
| 58 | + |
| 59 | +# Invoke your Edge Function |
| 60 | +try: |
| 61 | + res = fc.invoke("payment-sheet", { |
| 62 | + "responseType": "json", |
| 63 | + "body": {"amount": 1000, "currency": "usd"} |
| 64 | + }) |
| 65 | + print("Response:", res) |
| 66 | +except Exception as e: |
| 67 | + print(f"Error: {e}") |
| 68 | +``` |
0 commit comments