hazelcast / hazelcast-python-client

Hazelcast Python Client
https://hazelcast.com/clients/python/
Apache License 2.0
111 stars 73 forks source link

Add async & await support #364

Open Kilo59 opened 3 years ago

Kilo59 commented 3 years ago

Rather than using future.result() it would be nice if the python client could be used with async & await methods. https://docs.python.org/3.7/library/asyncio-task.html

This makes it much easier to integrate Hazelcast into a high throughput ASGI based web framework. https://asgi.readthedocs.io/en/latest/implementations.html

import hazelcast_aio

# Connect to Hazelcast cluster.
client = hazelcast_aio.HazelcastAIOClient()
await client.connect()

# Get or create the "distributed-map" on the cluster.
distributed_map = client.get_map("distributed-map")

# Put "key", "value" pair into the "distributed-map" and wait for
# the request to complete.
await distributed_map.set("key", "value")

# retrieve the value
awaited_value = await distributed_map.get("key")
print(awaited_value )

This would be much easier if support for anything before python 3.5 was dropped as many important async components were added in 3.5 (although arguably 3.7 is a better cutoff).

350

IMO a good model for this is pymongo and motor. motor is another package that depends on pymongo but adds async support.

A new aio_hazelcast package that requires python3.7/ (or 3.5 at a minimum) would be much easier to develop and maintain than trying to add to this codebase.

I wouldn't include Tornado support.

Olegt0rr commented 1 year ago

any news?

rvaidya commented 4 months ago

The Hazelcast documentation suggests that await can be used, however when I try it I just get TypeError: object Future can't be used in 'await' expression:

https://hazelcast.com/blog/getting-started-with-the-hazelcast-python-client/