{"id":4886,"library":"asyncstdlib-fw","title":"asyncstdlib-fw: Async Standard Library Fork for Fireworks-AI","description":"asyncstdlib-fw is a fork of the `asyncstdlib` library, tailored to work with `fireworks-ai`. It provides asynchronous re-implementations of many Python standard library functions and classes, making them compatible with async callables, iterables, and context managers. It aims to be event loop agnostic, supporting `asyncio`, `trio`, and custom event loops. The library generally follows the release cadence of its upstream `asyncstdlib` project, often updating to match new Python versions, and is currently at version 3.13.2.","status":"active","version":"3.13.2","language":"en","source_language":"en","source_url":"https://github.com/maxfischer2781/asyncstdlib","tags":["async","asyncio","stdlib","concurrency","iterators","context-managers"],"install":[{"cmd":"pip install asyncstdlib-fw","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.8 or newer.","package":"python","optional":false}],"imports":[{"symbol":"zip","correct":"import asyncstdlib as a\nawait a.zip(...)"},{"symbol":"map","correct":"from asyncstdlib import map\nasync for item in map(...):"},{"symbol":"enumerate","correct":"from asyncstdlib.builtins import enumerate\nasync for idx, item in enumerate(...):"},{"symbol":"scoped_iter","correct":"from asyncstdlib.asynctools import scoped_iter\nasync with scoped_iter(...) as async_iterator:"}],"quickstart":{"code":"import asyncio\nimport asyncstdlib as a\n\nasync def async_generator():\n    for i in range(3):\n        await asyncio.sleep(0.01)\n        yield i\n\nasync def main():\n    print(\"Using asyncstdlib.map:\")\n    doubled_values = [x async for x in a.map(lambda x: x * 2, async_generator())]\n    print(f\"Doubled values: {doubled_values}\")\n\n    print(\"\\nUsing asyncstdlib.zip:\")\n    async_gen_2 = async_generator()\n    zipped_values = [x async for x in a.zip(async_generator(), async_gen_2)]\n    print(f\"Zipped values: {zipped_values}\")\n\n    print(\"\\nUsing asyncstdlib.scoped_iter for cleanup:\")\n    long_running_iterable = (i async for i in async_generator())\n    async with a.asynctools.scoped_iter(long_running_iterable) as scoped_gen:\n        first_item = await a.anext(scoped_gen)\n        print(f\"First item from scoped iterator: {first_item}\")\n    # scoped_gen (and thus long_running_iterable) is guaranteed to be closed here.\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"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."},"warnings":[{"fix":"Wrap 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.","message":"Async 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure 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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be 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.","message":"`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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to Python 3.8 or newer.","message":"Support 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.","severity":"breaking","affected_versions":">=3.12.1 (for upstream asyncstdlib); likely impacts asyncstdlib-fw versions built against this baseline."},{"fix":"Always 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.","message":"Using 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}