aerospike / aerospike-client-python

Aerospike Python Client
Apache License 2.0
134 stars 111 forks source link

async support #263

Open databasedav opened 4 years ago

databasedav commented 4 years ago

This is a bump for these 2 old issues https://github.com/aerospike/aerospike-client-python/issues/51, https://github.com/aerospike/aerospike-client-python/issues/52.

Based on this comment https://github.com/aerospike/aerospike-client-python/issues/52#issuecomment-147862504, it sounds like async C support was the prereq for adding async python support which seems to have been added a few months ago. Has there been any progress on async python support? Thanks!

rbotzer commented 3 years ago

This is on the way for the next version of the Python client.

leos commented 2 years ago

That's great to hear @rbotzer - any ETA on that release? It looks like it's been quite a while since 6.0.0.

riteshpallod commented 2 years ago

is there any update on this ?

dimaqq commented 2 years ago

πŸ™πŸΏ

dimaqq commented 1 year ago

Poke πŸ–€

KimSoungRyoul commented 11 months ago

πŸ™πŸΏ

KimSoungRyoul commented 8 months ago

is there any update? since https://github.com/aerospike/aerospike-client-python/pull/462

Looking forward to async support πŸ™

P.S. I always thanks to Aerospike Team for great opensource

Lior-Balabanovsky-Forter commented 1 week ago

Hey, is there any update?

dimaqq commented 1 week ago

In all likelihood, someone will develop a new database, written in, say, rust with native, say, rust bindings and then it will be trivial to map those to Python.

databasedav commented 1 week ago

the new client will be a layer on top of a rust base, see https://github.com/aerospike/aerospike-client-rust/issues/147#issuecomment-2042516928

in the meantime, simply make all aerospike calls in a thread pool, which is what i've been doing since asking this question, here's the code, which is on python 3.9, but should be easy to upgrade

class AerospikeClient:
    def __init__(self, address):
        self._address = address

    async def connect(self) -> None:
        hosts = list()
        for addr in self._address.split(','):
            host, port = addr.split(':')
            hosts.append((host, int(port)))
        connect_args = dict()
        if username := os.getenv('AEROSPIKE_USERNAME'):
            connect_args['user'] = username
            connect_args['policies'] = {'auth_mode': aerospike.AUTH_INTERNAL},
            connect_args['password'] = os.getenv('AEROSPIKE_PASSWORD')
        if len(hosts) > 1:
            connect_args['shm'] = {}
        self._aerospike = aerospike.client({
            'hosts': hosts,
            'use_shared_connection': True,
            **connect_args
        })
        # TODO: can get rid of this when client is async
        class async_aerospike:
            def __init__(self, a):
                self._aerospike = a
                self._loop = None

            @property
            def loop(self):
                if not self._loop:
                    self._loop = asyncio.get_running_loop()
                return self._loop

            def __getattr__(self, attr: str):
                async def meth(*args, **kwargs):
                    return await self.loop.run_in_executor(
                        None,
                        functools.partial(
                            getattr(self._aerospike, attr), *args, **kwargs
                        ),
                    )
                return meth
        self.aerospike: aerospike.Client = async_aerospike(self._aerospike)
        await self.aerospike.connect()

    async def disconnect(self) -> None:
        await self.aerospike.close()

    @property
    def connected(self) -> bool:
        return self._aerospike.is_connected()

    def __getattr__(self, attr: str):
        return getattr(self.aerospike, attr)
juliannguyen4 commented 1 week ago

Async support is not coming in 2024 and we don’t have a delivery date scheduled yet, but we will respond back again once we solidify our 2025 roadmap