asyncstdlib-fw: Async Standard Library Fork for Fireworks-AI

3.13.2 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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())

view raw JSON →