2018-06-27 02:56:33 +00:00
|
|
|
|
aioitertools
|
|
|
|
|
============
|
|
|
|
|
|
2019-10-20 02:51:57 +00:00
|
|
|
|
Implementation of itertools, builtins, and more for AsyncIO and mixed-type iterables.
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
2022-02-07 05:45:33 +00:00
|
|
|
|
[![documentation](https://readthedocs.org/projects/aioitertools/badge/?version=latest)](https://aioitertools.omnilib.dev)
|
2018-06-27 02:56:33 +00:00
|
|
|
|
[![version](https://img.shields.io/pypi/v/aioitertools.svg)](https://pypi.org/project/aioitertools)
|
2022-02-07 05:45:33 +00:00
|
|
|
|
[![changelog](https://img.shields.io/badge/change-log-blue)](https://aioitertools.omnilib.dev/en/latest/changelog.html)
|
2020-04-29 06:20:12 +00:00
|
|
|
|
[![license](https://img.shields.io/pypi/l/aioitertools.svg)](https://github.com/omnilib/aioitertools/blob/master/LICENSE)
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Install
|
|
|
|
|
-------
|
|
|
|
|
|
|
|
|
|
aioitertools requires Python 3.6 or newer.
|
|
|
|
|
You can install it from PyPI:
|
|
|
|
|
|
2019-10-20 02:51:57 +00:00
|
|
|
|
$ pip install aioitertools
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Usage
|
|
|
|
|
-----
|
|
|
|
|
|
|
|
|
|
aioitertools shadows the standard library whenever possible to provide
|
|
|
|
|
asynchronous version of the modules and functions you already know. It's
|
|
|
|
|
fully compatible with standard iterators and async iterators alike, giving
|
|
|
|
|
you one unified, familiar interface for interacting with iterable objects:
|
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
```python
|
|
|
|
|
from aioitertools import iter, next, map, zip
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
something = iter(...)
|
|
|
|
|
first_item = await next(something)
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
async for item in iter(something):
|
|
|
|
|
...
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
async def fetch(url):
|
|
|
|
|
response = await aiohttp.request(...)
|
|
|
|
|
return response.json
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
async for value in map(fetch, MANY_URLS):
|
|
|
|
|
...
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
async for a, b in zip(something, something_else):
|
|
|
|
|
...
|
|
|
|
|
```
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
2018-06-28 06:25:54 +00:00
|
|
|
|
aioitertools emulates the entire `itertools` module, offering the same
|
|
|
|
|
function signatures, but as async generators. All functions support
|
|
|
|
|
standard iterables and async iterables alike, and can take functions or
|
|
|
|
|
coroutines:
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
```python
|
|
|
|
|
from aioitertools import chain, islice
|
2018-06-28 06:25:54 +00:00
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
async def generator1(...):
|
|
|
|
|
yield ...
|
2018-06-28 06:25:54 +00:00
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
async def generator2(...):
|
|
|
|
|
yield ...
|
2018-06-28 06:25:54 +00:00
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
async for value in chain(generator1(), generator2()):
|
|
|
|
|
...
|
2018-06-28 06:25:54 +00:00
|
|
|
|
|
2019-10-20 01:50:02 +00:00
|
|
|
|
async for value in islice(generator1(), 2, None, 2):
|
|
|
|
|
...
|
|
|
|
|
```
|
2018-06-28 06:25:54 +00:00
|
|
|
|
|
|
|
|
|
|
2020-03-26 22:21:50 +00:00
|
|
|
|
See [builtins.py][], [itertools.py][], and [more_itertools.py][] for full
|
|
|
|
|
documentation of functions and abilities.
|
2018-06-27 02:56:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
License
|
|
|
|
|
-------
|
|
|
|
|
|
2022-08-24 04:48:43 +00:00
|
|
|
|
aioitertools is copyright [Amethyst Reese](https://jreese.sh), and licensed under
|
2018-06-27 02:56:33 +00:00
|
|
|
|
the MIT license. I am providing code in this repository to you under an open
|
|
|
|
|
source license. This is my personal repository; the license you receive to
|
|
|
|
|
my code is from me and not from my employer. See the `LICENSE` file for details.
|
|
|
|
|
|
|
|
|
|
|
2020-04-29 06:20:12 +00:00
|
|
|
|
[builtins.py]: https://github.com/omnilib/aioitertools/blob/master/aioitertools/builtins.py
|
|
|
|
|
[itertools.py]: https://github.com/omnilib/aioitertools/blob/master/aioitertools/itertools.py
|
|
|
|
|
[more_itertools.py]: https://github.com/omnilib/aioitertools/blob/master/aioitertools/more_itertools.py
|