Install & Compatibility
Where this runs
tested against v3.13.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.244s · 18.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.218s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
zip
✓ from asyncstdlib import zip
✗ import asyncstdlib as a
a.zip(...)
This quickstart demonstrates common `asyncstdlib` features: `map`, `zip`, and `scoped_iter`. It uses `asyncio` to run an async generator and process its output using `asyncstdlib`'s asynchronous counterparts to built-in functions. `scoped_iter` is shown for safe handling and cleanup of async iterators.
import asyncio
import asyncstdlib as a
async def async_generator():
for i in range(3):
await asyncio.sleep(0.01)
yield i
async def main():
print("Using asyncstdlib.map:")
doubled_values = [x async for x in a.map(lambda x: x * 2, async_generator())]
print(f"Doubled values: {doubled_values}")
print("\nUsing asyncstdlib.zip:")
async_gen_2 = async_generator()
zipped_values = [x async for x in a.zip(async_generator(), async_gen_2)]
print(f"Zipped values: {zipped_values}")
print("\nUsing asyncstdlib.scoped_iter for cleanup:")
long_running_iterable = (i async for i in async_generator())
async with a.asynctools.scoped_iter(long_running_iterable) as scoped_gen:
first_item = await a.anext(scoped_gen)
print(f"First item from scoped iterator: {first_item}")
# scoped_gen (and thus long_running_iterable) is guaranteed to be closed here.
if __name__ == "__main__":
asyncio.run(main())
Debug
Known issues
gotchaAsync iterators managed by `asyncstdlib` utilities (e.g., `itertools` functions) are eagerly closed to prevent resource leaks. For non-exhausting utilities like `dropwhile()`, this can be unexpected if you intend to reuse the iterator. Use `asyncstdlib.asynctools.borrow()` to prevent automatic cleanup or `asyncstdlib.asynctools.scoped_iter()` for guaranteed cleanup within a specific scope.fixWrap iterators with `asyncstdlib.asynctools.borrow(iterator)` if you need to manually manage their closure, or use `async with asyncstdlib.asynctools.scoped_iter(iterable) as scoped_iterator:` to ensure proper resource management.
affects: All versions
gotchaWhen using `asyncstdlib.itertools.groupby()`, the main group iterator and the iterators for individual groups share the same underlying asynchronous iterator. Advancing one will affect the others, making concurrent advancement of the main `groupby` iterator and any of its group iterators unsafe. This can lead to groups being skipped or incomplete.fixEnsure you fully consume each group's iterator before advancing the main `groupby` iterator to the next group. Avoid concurrent iteration over the `groupby` object and its sub-group iterators.
affects: All versions
gotcha`asyncstdlib` objects that are 'async neutral' can accept both regular (synchronous) and asynchronous arguments. However, the *result* of such operations must consistently be either synchronous or asynchronous. Incorrectly mixing argument types that lead to inconsistent result types at runtime can cause unexpected behavior or errors.fixBe mindful of the return types when using async-neutral arguments. While `asyncstdlib` handles the input flexibility, ensure your usage aligns with consistent output types (either always awaitable/async iterator or always synchronous) to avoid runtime surprises.
affects: All versions
breakingSupport for Python 3.6 and Python 3.7 has been officially deprecated and removed in upstream `asyncstdlib` v3.12.1. `asyncstdlib-fw` is expected to follow this deprecation, meaning older Python versions are no longer supported.fixUpgrade your Python environment to Python 3.8 or newer.
affects: >=3.12.1 (for upstream asyncstdlib); likely impacts asyncstdlib-fw versions built against this baseline.
gotchaUsing synchronous I/O operations (e.g., `requests`, blocking database calls) inside `async def` functions, even when using `asyncstdlib` for other parts, will block the entire event loop. This negates the benefits of asynchronous programming and can severely degrade application performance.fixAlways use asynchronous libraries for I/O operations (e.g., `httpx` instead of `requests`, async database drivers). If blocking I/O is unavoidable, offload it to a thread pool using `asyncio.to_thread()` or a process pool for CPU-bound tasks.
affects: All versions
Upgrade
Version history
3.13.2latest on PyPI · released May 19, 2025
Audit
Dependencies
pythonrequiredRequires Python 3.8 or newer.