Does `client.subscribe_to_all` support async events in Python?

I am trying to do something like the following using asyncio, but it’s saying that it’s not supported. Is there a way to subscribe to the events in an async manner or should I try offloading this to a separate thread somehow?

async def main():
    async with client.subscribe_to_all(filter_include=[r"icf\..*"], filter_by_stream_name=True) as subscription:
        async for event in subscription:
            await process_event_async((event.type, json.loads(event.data)))

Hi there! The library does not support async operations at the moment. There has been discussions on this in the past. You can perhaps comment on this github issue and see where John (the author of the library) is at.

The method returns a coroutine, so you need to await it.

Try changing the code to:

async with await client.subscribe_to_all(filter_include=[r"icf\..*"], filter_by_stream_name=True) as subscription:

Also, make sure that you are using the async client: AsyncKurrentDBClient.

from kurrentdbclient import AsyncKurrentDBClient

client = AsyncKurrentDBClient(uri="kurrentdb://localhost:2113?tls=false")

await client.connect()

You can find more detailed information in the client’s README

1 Like