Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Simple example of stream with Asyncio operations

Open
#429 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python

Research direction

Start by reproducing the Python example from the issue with its aiohttp, asyncio, and Stream(asynchronous=True) pipeline. Read the streamz asyncio-related implementation and existing tests, if present, to determine whether async map operations are supported. Done means the reported pipeline runs correctly or the supported limitation is documented.

Written by the indexing model from the issue text.

Description

Hi,

I've been following the docs and reading through the tests, and I cannot get streamz working with Asyncio :/

Here's a very minimal example of a stream comprising of two async operation and one sync :

  1. we retrieve content via an aiohttp call
  2. return content length
  3. simulate DB write with an Asyncio sleep
  4. sink to stdout
import asyncio

import aiohttp
from streamz import Stream


async def fetch(url):
    print("fetching url {}", url)
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            print(resp.status)
            body = await resp.text()
    print("Finished w/ url {}", url)
    return body


def count(x):
    print("I", x)
    return len(x)


async def write(x):
    await asyncio.sleep(0.2)
    print("O", x)
    return x

async def f():
    print("Starting stream")
    source = Stream(asynchronous=True)
    source.map(fetch).map(count).map(write).sink(print)
    urls = [
        'https://httpstatus.io/?i=1',
        'https://httpstatus.io/?i=2',
        'https://httpstatus.io/?i=3',
        'https://httpstatus.io/?i=4',
        'https://httpstatus.io/?i=5',
        'https://httpstatus.io/?i=6',
    ]
    for u in urls:
        await source.emit(u)


if __name__ == '__main__':
    asyncio.run(f())

I've tried a lot of combinations using tornado event loop etc. but didn't manage to get anything working.
Is this supposed to be possible or is the Asyncio support still behind?
Am I missing something obvious?

Thanks for the help

Dominant language
Python
Stars
1.3k
Forks
149
Avg merge
17h 39m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-streamz/streamz

All issues in python-streamz/streamz

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.