Package: aitertools
Async versions of the itertools features.Example UsageThe behaviour of each feature in this project is designed to match, one-to-one,
the behaviour of each feature in the Pythonitertoolsmodule. The primary
difference of this package is that all features can additionally consume
async functions and async iterables in addition to the sync versions. All
functions also return async iterables.Wrapping Sync CodeWhen working with sync iterables in an async world you may want to wrap things
in an async interface for interoperability with other async tools. For example,
a typical sync call tochainmight look like:iter1=(1,2,3,4)iter2=(5,6,7,8)iter3=(9,10,11,12)forvalueinitertools.chain(iter1,iter2,iter3):print(value)The above would output numbers 1 - 12 in the order shown. However, in the async
world not all iterables are tuples and lists. The same thing can be
accomplished with the asyncchain:iter1=(1,2,3,4)iter2=(5,6,7,8)iter3=(9,10,11,12)asyncforvalueinaitertools.chain(iter1,iter2,iter3):print(value)The above behaves exactly as the sync version except that it exposes the async
iteratable interface and works withasync def.Mixing Sync and AsyncAll functions in theaitertoolspackage accept both sync and async iterables.
This allows for the combination of the two when needed:iter1=(1,2,3,4)iter2=some_async_iter()# Async resolves to 5, 6, 7, 8asyncforvalueinaitertools.chain(iter1,iter2):print(value)Ensuring Async InterfacesThis package also provides a handful of tools for working with the async
interfaces:aiterAsync function that countersiter. This function, when given an
async iterable, will return an async iterator. When given a sync
iterable it will wrap it and return an async iterator.anextAsync function that countersnext. This function calls the__anext__()method of the iterator and returns the value. It,
like thenextmethod, can optionally return a default value when
the iterator is empty.alistAsync function that counterslist. For use cases likelist(iterable)this function allows forawait alist(iterable).atupleAsync function that counterstuple. Similar to thealistabove.Development RoadmapThe current release of this package is only missing thepermutations,combinations, andcombinations_with_replacementfeatures. The next release
should contain these missing features.Additionally, several features from functools and the available globals are
slated for addition. For example, thefilter,map, andreducefeatures
are good fits for this package and already have at least oneitertoolscounterpart added.TestingAll tests are stored in the ‘/tests’ subdirectory. All tests are expected to
pass for Python 3.5 and above. To run tests create a virtualenv and install
the test-requirements.txt list. After that using thetoxcommand will launch
the test suite.LicenseCopyright 2015 Kevin ConwayLicensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.ContributingFirstly, if you’re putting in a patch then thank you! Here are some tips for
getting your patch merged:StyleAs long as the code passes the PEP8 and PyFlakes gates then the style is
acceptable.DocsThe PEP257 gate will check that all public methods have docstrings. If you’re
adding additional features from theitertoolsmodule try to preserve the
original docstrings if possible. Sometimes the original docs don’t fit well
with the PEP257 format. In those cases it is OK to modify the docstring to fit.
If you’re adding something new, like a helper function, try out thenapoleon style of docstrings.TestsMake sure the patch passes all the tests. If you’re adding a new feature fromitertoolsbe sure to add some of the original, standard library tests. The
tests used to validate the Pythonitertoolsmodule are found in the
‘/Lib/test/test_itertools.py’ file in the Python source. The orginal tests are
organized into large blocks of tests based on features. As much as possible,
break the tests up into individual units. Check out the existing tests for this
project for inspiration if needed.If you’re adding something totally new the make sure to throw in a few tests.
If you’re fixing a bug then definitely add at least one test to prevent
regressions.