Skip to main content

supabase-py with async synax

Project description

supabase-py-async

License: MIT CI Python Version

Downloads Open Issues Pull Requests Contributors Code Size

Supabase client for Python with Async support. This project is an asynchronous variant of supabase-py and mirrors the design of supabase-js.

but i am not hahah👻,it doesn't mirrors the design of supabase-js ,py is not frontend language,we must change the design and cater to the python web framework like fastapi,etc

Status

Status Stability Goal
🚧 Alpha We are testing Supabase with a closed set of customers
🚧 Public Alpha Anyone can sign up over at app.supabase.io. But go easy on us, there are a few kinks.
Public Beta Stable enough for most non-enterprise use-cases
Public Production-ready

Installation

PyPi Installation

To install the package for Python 3.7 and above:

# with pip
pip install supabase-py-async

# with poetry
poetry add supabase-py-async

Local Installation

For local development, clone this repo and install in Development mode with pip install -e.

What's new?

2.0.5

new functions

  • add auth_clients in AsyncClient which should be sent in operation functions like client.table,etc
  • add add_auth_clients function in AsyncClient which can add auth_clients in AsyncClient as the request is sign in or sign up,etc
  • add update_auth_session function in AsyncClient which can update auth_client by access_token from the request

new ideas

  • and we do not need to create a new client every time we want to do a operation,so i add auth_clients in AsyncClient which should be sent in operation functions like client.table,etc

my questions

  • i think we should add a new functions that can clean the auth_clients in AsyncClient schedulely,cause the auth_clients may be too much and it may cause some problems

Async Usage

It's usually best practice to set your api key environment variables in some way that version control doesn't track them, e.g don't put them in your python modules! Set the key and url for the supabase instance in the shell, or better yet, use a dotenv file. Heres how to set the variables in the shell.

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

This client is designed to be used asynchronously. Below are some examples on how to use it.

Initialize Supabase Client

import os
from supabase_py_async import create_client, AsyncClient

url: str = os.environ.get("SUPABASE_URL")

key: str = os.environ.get("SUPABASE_KEY")

supabase: AsyncClient = create_client(url, key)

Async Data Operations

async def data_operations():
    # Note:  opereations should be sent operator(auth_client)!!
    auth_response: AuthResponse = await self.auth.sign_in_with_password({"email": ur_email, "password": ur_password)
    #  or other sign in methods
    await supabase.add_auth_clients(auth_response)
    # next time your can use operation with supabase like this,i assume you get a user access_token
    auth_client = await self.update_auth_session(auth_response.seesion.access_token)  # or access_token from other place

    # Insert
    insert_data = await supabase.table("countries", auth_client).insert({"name": "Germany"}).execute()

    # Select
    select_data = await supabase.table("countries", auth_client).select("*").eq("country", "IL").execute()

    # Update
    update_data = await supabase.table("countries", auth_client).update(
        {"country": "Indonesia", "capital_city": "Jakarta"}).eq("id", 1).execute()

    # Delete
    delete_data = await supabase.table("countries", auth_client).delete().eq("id", 1).execute()

    # note: every operation should be get a auth_client from access_token
    asyncio.run(data_operations())

Async Authentication

async def async_auth():
  random_email: str = "email@example.com"
  random_password: str = "supersecurepassword"
  auth_response: AuthResponse = await supabase.auth.sign_up(email=random_email, password=random_password)
asyncio.run(async_auth())

See Supabase Docs for a full list of examples.

Contributions

Welcome to the supabase-py-async package! 😊

Hello, fellow developers!

I'm excited to share that I've published an asynchronous package for Supabase designed to work smoothly with FastAPI, and it's now open for contributions! 🚀

This project is very close to my heart ❤️, cause my personal plan app is based on vue and fastapi so i need a async one,and hope it will benefit yours as well,and I believe that with your valuable contributions, we can make it even better. Whether it's improving the code, fixing bugs, writing documentation, or suggesting new features – all contributions are welcome.

If you're passionate about FastAPI, async programming in Python, or just want to lend a hand with a growing project, this is your invitation to join in. Let's collaborate to create something amazing that we're all proud of. 🤝

How to Contribute

  • Fork the repository: Start by forking the project to your GitHub account.
  • Pick an issue: Look for open issues that interest you or suggest new ones.
  • Open a pull request: After making your changes, open a pull request with a clear description of your improvements

Stay Connected

  • Join our community chat: We have a Discord channel (https://discord.com/invite/QPysZkKT) where we discuss the project and collaborate.
  • Stay updated: Watch this repository to stay informed about new issues and updates.

Contributing to open source is a rewarding way to learn, teach, and build experience. No matter your skill level, your contributions are invaluable to the project. 🌟

Thank you for considering contributing to this project. Let's make it the best it can be, together!

Happy coding! 👨‍💻👩‍💻

Atticus Zhou

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supabase_py_async-2.0.6.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

supabase_py_async-2.0.6-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file supabase_py_async-2.0.6.tar.gz.

File metadata

  • Download URL: supabase_py_async-2.0.6.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.5 Windows/10

File hashes

Hashes for supabase_py_async-2.0.6.tar.gz
Algorithm Hash digest
SHA256 5b2d1c0a489d207ca32a963e54a259570c36c5490de9b12b643096593fdd270a
MD5 7c30746ee2e5db72654a7b542023276d
BLAKE2b-256 73ec8eca06110e12bfea5afa9c53bdbecc3d53b25d663c07564082d5e5bf1c4f

See more details on using hashes here.

File details

Details for the file supabase_py_async-2.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for supabase_py_async-2.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 b68eda5886363beb633ab1e6fea23098258be1314cc871701f5ea211dfd886b3
MD5 c427f8d36fc5f841bb8fe5b24764c28f
BLAKE2b-256 828f38e7f1cb66f8be21a2f0bc6242a1337a4915abab9762ecde12762a9af048

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page