{"id":461,"library":"aioitertools","title":"aioitertools: itertools and builtins for AsyncIO","description":"aioitertools provides asynchronous versions of standard library `itertools` and `builtins` for AsyncIO and mixed iterables. It offers a unified interface for both standard and async iterators, wrapping standard iterables in async generators. The current version is 0.13.0, and it follows a feature release cadence.","status":"active","version":"0.13.0","language":"python","source_language":"en","source_url":"https://github.com/omnilib/aioitertools","tags":["asyncio","itertools","iterators","async","builtins"],"install":[{"cmd":"pip install aioitertools","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Aioitertools shadows standard library builtins directly at the top level for convenience.","wrong":"from aioitertools.builtins import iter","symbol":"iter","correct":"from aioitertools import iter"},{"note":"Aioitertools shadows standard library builtins directly at the top level for convenience.","wrong":"from aioitertools.builtins import map","symbol":"map","correct":"from aioitertools import map"},{"note":"Aioitertools shadows standard library itertools directly at the top level for convenience.","wrong":"from aioitertools.itertools import chain","symbol":"chain","correct":"from aioitertools import chain"},{"note":"Asynchronous specific utilities are found under the `aioitertools.asyncio` submodule.","wrong":"from aioitertools import as_completed","symbol":"as_completed","correct":"from aioitertools.asyncio import as_completed"}],"quickstart":{"code":"import asyncio\nfrom aioitertools import iter, next, map\n\nasync def async_generator():\n    for i in range(3):\n        yield i\n        await asyncio.sleep(0.01)\n\nasync def process_item(item):\n    # Simulate an async operation\n    await asyncio.sleep(0.005)\n    return item * 2\n\nasync def main():\n    # Using aioitertools.iter with a standard iterable\n    it_sync = iter([1, 2, 3])\n    first_item = await next(it_sync)\n    print(f\"First item from sync: {first_item}\")\n\n    # Using aioitertools.iter with an async iterable\n    it_async = iter(async_generator())\n    print(\"Items from async generator:\")\n    async for item in it_async:\n        print(f\"  {item}\")\n\n    # Using aioitertools.map for concurrent async operations\n    urls = [\"url1\", \"url2\", \"url3\"]\n    async def fetch_url(url):\n        # Replace with actual async HTTP request\n        await asyncio.sleep(0.01)\n        return f\"Processed {url}\"\n\n    print(\"\\nMapping async functions:\")\n    async for result in map(fetch_url, urls):\n        print(f\"  {result}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to use `aioitertools.iter` to get an async iterator from both synchronous and asynchronous iterables, `aioitertools.next` to retrieve the next item, and `aioitertools.map` to apply an asynchronous function concurrently over an iterable."},"warnings":[{"fix":"Remove the `loop` argument when calling any `aioitertools.asyncio` functions. The event loop is now managed automatically.","message":"The `loop` parameter to `aioitertools.asyncio` functions was deprecated in v0.9.0 and completely removed in v0.11.0. This aligns with modern `asyncio` practices.","severity":"deprecated","affected_versions":">=0.11.0"},{"fix":"Upgrade your Python environment to version 3.8 or newer.","message":"Support for Python 3.6 and 3.7 was dropped in version 0.12.0.","severity":"breaking","affected_versions":">=0.12.0"},{"fix":"Be aware that `aioitertools.asyncio.as_completed` directly gives you the resolved values, so you do not need to `await` on the yielded items.","message":"`aioitertools.asyncio.as_completed` yields actual results of awaitables, unlike the standard `asyncio.as_completed` which yields futures.","severity":"gotcha","affected_versions":"all"},{"fix":"For very large iterables, consider if these functions are suitable, or use them with a limited subset of data. Be mindful of memory usage.","message":"Functions like `aioitertools.permutations` or `aioitertools.combinations` may consume the entire input iterable into memory before yielding any results. This can be inefficient for very large or infinite iterables.","severity":"gotcha","affected_versions":"all"},{"fix":"Always combine infinite iterators with a 'stopping' function, such as `aioitertools.islice`, `aioitertools.takewhile`, or an explicit `break` condition in an `async for` loop, to prevent unbounded iteration.","message":"Similar to standard `itertools`, infinite iterators (e.g., `aioitertools.count`, `aioitertools.cycle`) will run indefinitely.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:57:50.388Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the package using pip: 'pip install aioitertools'.","cause":"The 'aioitertools' package is not installed in the Python environment.","error":"ModuleNotFoundError: No module named 'aioitertools'"},{"fix":"Use the standard 'iter' function from Python's built-in library instead.","cause":"The 'iter' function is not available in the 'aioitertools' module.","error":"ImportError: cannot import name 'iter' from 'aioitertools'"},{"fix":"Convert the list to an asynchronous iterable using 'aioitertools.iter()' before iterating.","cause":"Attempting to use 'async for' on a standard list, which is not an asynchronous iterable.","error":"TypeError: 'async for' requires an object with an __aiter__ method, got 'list'"},{"fix":"Ensure you use 'await' when retrieving single items from async iterators (e.g., `await ait.next(it)`) and ensure the function itself is awaited if it returns a single awaitable result. If it's an async generator, use 'async for' to iterate over it.","cause":"You are attempting to call an aioitertools asynchronous generator function as if it were a regular synchronous function, or trying to retrieve a single item from an async iterator without using 'await'.","error":"TypeError: 'async_generator' object is not callable"},{"fix":"Use 'async for' to iterate over the asynchronous generator within an 'async def' function. For example, `async for item in ait.map(func, data):`.","cause":"You are trying to iterate over an asynchronous generator returned by an aioitertools function using a standard (synchronous) 'for' loop, instead of an 'async for' loop.","error":"TypeError: 'async_generator' object is not iterable"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.09,"mem_mb":4.1,"disk_size":"18.0M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.07,"mem_mb":4.1,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.17,"mem_mb":5,"disk_size":"19.9M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":5,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.38,"mem_mb":8.2,"disk_size":"11.8M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.35,"mem_mb":8.2,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.4,"mem_mb":8.7,"disk_size":"11.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.34,"mem_mb":8.7,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.1,"mem_mb":4.3,"disk_size":"17.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.08,"mem_mb":4.3,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}