Code Monkey home page Code Monkey logo

Comments (15)

aavshr avatar aavshr commented on August 20, 2024 4

hi @DanielChuDC , huge thanks to @leits we have an alpha version of the sdk with async methods for Base : https://docs.deta.sh/docs/base/async_sdk

we do not have async methods for Drive yet, if you want to work on it.

from deta-python.

leits avatar leits commented on August 20, 2024 3

Looks like a plan πŸ‘

from deta-python.

abdelhai avatar abdelhai commented on August 20, 2024 2

@leits
Thanks for the offer, your help would be appreciated! 😊
We need to decide on the API first. I guess the it will stay mostly the same, the only difference could be the class name...

from deta import Base  # sync base direct import
from deta import AsyncBase  # async base direct import
from deta import Deta

db = Deta().Base("db")   # sync base
adb = Deta().AsyncBase("db")  # async base

db.get("1")
await adb.get("1")

Another way (which simplifies the API a bit) is to use a modifier method which will use the async methods:

db = Base("db")  # sync
adb = Base("db").async()  # async

I kinda prefer the latter but not sure how pythonic it is. I would like to discuss this with the team first. (we take API design seriously)

What kind of API would you like to see?

And btw, we try to not use external dependencies for our SDKs.

from deta-python.

aavshr avatar aavshr commented on August 20, 2024 1

Yeah I would like to help to contribute! May I know for the drive async, can I use the same style from the async base code base?

great πŸŽ‰ , yes please use the async base code as guide.

Or there is any specific requirements for drive async?

no nothing specific, but please keep the method signatures consistent with the current sync Drive methods. If you feel like something can/should be improved (API wise), we can make the improvements in a later version.

from deta-python.

DanielChuDC avatar DanielChuDC commented on August 20, 2024 1

Hey @harshitsinghai77 Please take on the drive async. Thank you!

from deta-python.

leits avatar leits commented on August 20, 2024

+1 here

In the tutorials, there are many FastAPI examples with asynchronous views but synchronous queries in Deta Base πŸ˜…

from deta-python.

leits avatar leits commented on August 20, 2024

Hi, @abdelhai!
I can help you with async support. Do you have some ideas? Or I can just come up with some solution in a pull request?

from deta-python.

leits avatar leits commented on August 20, 2024

Got you!

First of all, a second way is far away from python best practices because Explicit is better than implicit (from Zen of Python).

So there are two main ways in the python community for async support:

The first one is the way that you propose. Add explicit async client class in current client lib.
For example elasticsearch-py with Elasticsearch and AsyncElasticsearch:
https://elasticsearch-py.readthedocs.io/en/7.x/async.html

The second way is to create a separate async client. Like for all database clients - asyncpg, aiomysql, aiosqlite, motor (Mongo client), etc.
And also aiobotocore as an async client to AWS (sync client - botocore).
https://github.com/aio-libs

And there are two reasons for this.

  1. There is no support for asynchronous HTTP requests in python built-in. And a recommendation from the python core dev team is to use lightweight aiohttp lib supported by them.
  2. The principle of operation of asynchronous functions can be very different from synchronous, so under the hood of the library begins a terrible mess, if it supports both methods (just loot into elasticsearch-py sources).

But also, there is a third way, very clever but not popular for clients.
Write fully async client and make sync wrapper that will run async functions under-the-hood.
It's the way fastapi works.
I've already done this on a project from my work.

I can make such a client if you don't mind.

from deta-python.

abdelhai avatar abdelhai commented on August 20, 2024

@leits
Thank you for the clarification, now I have a better understanding of the industry practices.

I think we will likely keep everything in one SDK where's the "async" functionalities are optional/opt-in. You can get them by installing deta[async]/deta[all] and by importing the async service clients AsyncBase, etc.

You could start with 3rd party package where you could experiment with your ideas. I'm interested in seeing what you come up with. We could merge into our SDK if it passes our internal "rules".

We do some weird stuff with the current implementation for managing connections which we want to keep for now, so not sure how this will translate to your implementation.

from deta-python.

DanielChuDC avatar DanielChuDC commented on August 20, 2024

Hi May I know any update on this? Would like to help if can.

from deta-python.

DanielChuDC avatar DanielChuDC commented on August 20, 2024

Yeah I would like to help to contribute! May I know for the drive async, can I use the same style from the async base code base?

from deta-python.

DanielChuDC avatar DanielChuDC commented on August 20, 2024

Or there is any specific requirements for drive async?

from deta-python.

harshitsinghai77 avatar harshitsinghai77 commented on August 20, 2024

Hey, any updates on this?

I would like to work on async methods for Drive if it's not already been worked on.

@DanielChuDC are you working on this, or should I take this?

from deta-python.

harshitsinghai77 avatar harshitsinghai77 commented on August 20, 2024

Hey @harshitsinghai77 Please take on the drive async. Thank you!

cc: @aavshr

from deta-python.

abdelhai avatar abdelhai commented on August 20, 2024

hey @harshitsinghai77 feel free to propose a pr for drive async. ideally you open a new issue with the spec/sdk design.
lmk if you need any help! cheers!

from deta-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.