{"id":2394,"library":"asyncstdlib","title":"Async Standard Library (asyncstdlib)","description":"asyncstdlib provides async equivalents for functions and classes found in Python's standard library modules like itertools, functools, contextlib, builtins, and os. It aims to make writing asynchronous code more concise and familiar by mirroring the API of their synchronous counterparts. The current version is 3.14.0, maintaining feature parity with Python 3.14. New major versions are typically released to align with new Python releases.","status":"active","version":"3.14.0","language":"en","source_language":"en","source_url":"https://github.com/maxfischer2781/asyncstdlib","tags":["async","concurrency","itertools","stdlib","utilities","python3"],"install":[{"cmd":"pip install asyncstdlib","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Use 'amap' (or similar alias) for async iterables, not the standard 'itertools.map'.","wrong":"from itertools import map","symbol":"map","correct":"from asyncstdlib.itertools import map as amap"},{"note":"Use 'anext' for consuming async iterators, not the standard 'next'.","wrong":"from builtins import next","symbol":"anext","correct":"from asyncstdlib.builtins import anext"},{"note":"Common practice to import the whole library under an alias 'a' for convenience.","symbol":"AsyncStandardLibrary","correct":"import asyncstdlib as a"}],"quickstart":{"code":"import asyncio\nimport asyncstdlib as a\n\nasync def async_counter(limit: int):\n    \"\"\"An async generator that yields numbers up to a limit.\"\"\"\n    for i in range(limit):\n        await asyncio.sleep(0.01) # Simulate async work\n        yield i\n\nasync def main():\n    print(\"\\nMapping values (doubling):\")\n    doubled_values = a.itertools.map(lambda x: x * 2, async_counter(5))\n    async for item in doubled_values:\n        print(item)\n\n    print(\"\\nFiltering values (evens only):\")\n    even_values = a.itertools.filter(lambda x: x % 2 == 0, async_counter(6))\n    async for item in even_values:\n        print(item)\n\n    print(\"\\nConsuming with anext:\")\n    it = a.builtins.aiter(async_counter(3))\n    print(await a.builtins.anext(it))\n    print(await a.builtins.anext(it))\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates using `asyncstdlib`'s async versions of `map`, `filter`, and `anext` with an async generator. It highlights how to apply common iteration patterns in an asynchronous context."},"warnings":[{"fix":"Always use the `asyncstdlib` equivalent (e.g., `asyncstdlib.itertools.map`, `asyncstdlib.builtins.anext`) when working with async generators and iterables.","message":"Mixing `asyncstdlib` functions with built-in or synchronous standard library functions (e.g., `itertools.map` on an async iterable) will lead to `TypeError` or incorrect behavior, as asyncstdlib functions expect and return async iterables/awaitables.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review code using `islice` and `accumulate` and adjust parameter passing or expectations to align with the standard `itertools` behavior.","message":"In `v3.13.3`, the signatures and behavior of `asyncstdlib.itertools.islice` and `asyncstdlib.itertools.accumulate` were updated to match their synchronous `itertools` counterparts more closely. This primarily affects `islice` overloads and `accumulate`'s `initial` parameter, potentially causing subtle breaking changes if your code relied on previous divergent behavior.","severity":"breaking","affected_versions":">=3.13.3"},{"fix":"Understand that `tee` iterators consume from a shared underlying iterable and buffer. Ensure your logic handles this standard `tee` behavior, which typically implies immutable consumption.","message":"As of `v3.13.3`, `asyncstdlib.itertools.tee` instances now share an internal buffer for improved efficiency, mirroring `itertools.tee` in CPython. While generally a performance enhancement, this can subtly change behavior if you were relying on independent buffering or specific mutation patterns of yielded items across `tee` branches in earlier versions.","severity":"gotcha","affected_versions":">=3.13.3"},{"fix":"Upgrade your Python environment to 3.8 or newer.","message":"`asyncstdlib` versions from `3.12.1` onwards no longer support Python 3.6 and 3.7. The `requires_python` specification is `~=3.8`.","severity":"deprecated","affected_versions":">=3.12.1"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}