asyncutils.iters

Functional and chainable interface to get async generators from (async) iterables. Many of the algorithms here are taken from more_itertools.
However, since they must support both sync and async iterables, they are much less efficient than their sync counterparts.

Functions

aaccumulate(→ collections.abc.AsyncGenerator[T])

Async version of itertools.accumulate that is not a class.

aall(→ bool)

Async version of all().

aallequal(→ bool)

Whether all items in the (async) iterable are equal to each other according to the key function. Check for identity rather than equality if strict is True.

aany(→ bool)

Async version of any().

aappend(→ collections.abc.AsyncGenerator[T])

Append val to the (async) iterable it.

aargmax(…)

Return the index of the first occurrence of the maximum element in the (async) iterable it according to key, or default if empty.

aargmin(…)

Return the index of the first occurrence of the minimum element in the (async) iterable it according to key, or default if empty.

aawgenf2agenf(→ collections.abc.Callable[P, ...)

Convert a function that returns an awaitable resolving to an async iterable into one returning an async generator.

abefore_and_after(...)

atakewhile(), but return all remaining items in the second async generator (after the first is consumed).

abfs(→ collections.abc.AsyncGenerator[H])

Breadth-first search on a start node start, given a function neighbours that returns an (async) iterable of neighbours to be traversed in order. If include_start is True, the start node is yielded first.

abrent(→ tuple[T, int, int])

Brent's algorithm for cycle detection, assuming that a cycle is indeed present, given a function next_node returning the next node from the previous. Return a tuple (node, la, mu), where node is the first node involved in a cycle. next_node should be deterministic.

ac3merge(→ collections.abc.AsyncGenerator[T])

Async version of functools._c3_merge that doesn't assume the input is an synchronous iterable of mutable sequences of classes.

acanonical(→ list[T])

Return a canonicalized ordering of the items in it, which may change across different Python invocations or sessions.

acat(…)

An async generator that yields the sent value, starting with first (default None).

acollapse(→ collections.abc.AsyncGenerator[Any])

Flatten the (async) iterable it by at most levels levels, without collapsing objects of types specified in base_typ.

acombinations(...)

Async version of itertools.combinations() that is not a class.

acombinations_with_replacement(...)

Async version of itertools.combinations_with_replacement() that is not a class.

acompress(→ collections.abc.AsyncGenerator[T])

Async version of itertools.compress that is not a class.

aconsume(→ None)

Advance the (async) iterable it by n steps, using a function-scoped executor created on demand where appropriate. If you want the item at the final position, use anth() instead.

aconvolve(→ collections.abc.AsyncGenerator[X])

Polynomial multiplication with coefficients from the two iterables. The first iterable is advanced on demand, meaning it may be infinite, but the second iterable is exhausted immediately, storing all its items in memory.

acount(…)

Async version of itertools.count that is not a class.

acountdown(→ collections.abc.AsyncGenerator[int])

Count down from n to zero, excluding zero if it is to appear and include_zero is False (the default), by a step size of step.

acycle(→ collections.abc.AsyncGenerator[T])

Async version of itertools.cycle that is not a class.

aderangements(→ collections.abc.AsyncGenerator[T])

Successive derangements of the elements in it of size r, or all sizes if not passed. Derangements are permutations with no fixed points.

adfs(→ collections.abc.AsyncGenerator[H])

Depth-first search on a start node start, given a function neighbours that returns an (async) iterable of neighbours to be traversed in order. If include_start is True, the start node is yielded first.

adft(→ collections.abc.AsyncGenerator[complex])

The discrete Fourier transform. O(n^2), since this library does not specialize in these operations.

adistinct_permutations(...)

Successive distinct permutations of the elements in it of size r, or all sizes if not passed.

adoublestarmap(→ collections.abc.AsyncGenerator[T])

Like amap(), but the iterables should yield mappings that are unpacked as arguments to the function.

adropwhile(→ collections.abc.AsyncGenerator[T])

aevery(→ collections.abc.AsyncGenerator[T])

Yield every n-th item from an (async) iterable, optionally skipping the first item.

aeveryother(→ collections.abc.AsyncGenerator[T])

Yield every other item from an (async) iterable, optionally skipping the first item.

afactor(→ collections.abc.AsyncGenerator[int])

Generate the prime factors of n asynchronously. Do not rely on the resultant order.

afilter(→ collections.abc.AsyncGenerator[T])

Async version of filter that is not a class.

afilterfalse(→ collections.abc.AsyncGenerator[T])

Async version of itertools.filterfalse that is not a class.

afirst(→ T)

Return the first item in the (async) iterable it, or default if passed and it is empty.

afirsttrue(→ T)

Return the first item in the (async) iterable it

aflatten(→ collections.abc.AsyncGenerator[T])

Flatten one level of nesting using achain and return an async iterator over it.

aflatten_tensor(→ collections.abc.AsyncGenerator[Any])

acollapse(), but using a different, more memory-efficient strategy that does not support the levels parameter.

aforever(→ collections.abc.AsyncGenerator[None])

An async generator that yields None forever. Equivalent to arepeat(None).

afreivalds(→ bool)

The probabilistic Freivalds algorithm to determine if the matrix product of A and B equals C. O(kn^2) time, with a false positive rate of at most 2^(-k) and no false negatives.

agather(→ list[T])

Wraps asyncio.gather() to accept (async) iterables as the first argument, so that unpacking is not needed.

agetitems_from_indices(→ list[asyncio.Future[T]])

agives(→ collections.abc.AsyncGenerator[T])

Yield the given value, then return.

agroupby(…)

Async version of itertools.groupby that is not a class.

agrouper(...)

aguessmax(→ T)

Optimal solution to the secretary problem, using key to guess the maximum item, which is the candidate chosen, with 36.8% accuracy by consuming 36.8% of the (async) iterable.

aguessmin(→ T)

Optimal solution to the secretary problem, using key to guess the minimum item, which is the candidate chosen, with 36.8% accuracy by consuming 36.8% of the (async) iterable.

ahammingdist(→ int)

Return the Hamming distance between two (async) iterables, using cmpeq to check for equality if passed.

aidft(→ collections.abc.AsyncGenerator[complex])

The inverse discrete Fourier transform. O(n^2) just like adft().

ailen(→ int)

Return the length of the (async) iterable it, consuming it entirely.

ainterleave_evenly(→ collections.abc.AsyncGenerator[T])

Interleave items of the iterables evenly according to the lengths if passed, and determined by calling the __len__() method on the iterables if present otherwise.

ainterleave_randomly(→ collections.abc.AsyncGenerator[T])

Interleave items of the iterables randomly, skipping exhausted iterables.

ainterleave_stopearly(→ collections.abc.AsyncGenerator[T])

Yield the items from the iterables in a round-robin fashion until at least one is exhausted.

aintersend(→ collections.abc.AsyncGenerator[tuple[T, R]])

Feed i1 and i2 into each other and yield tuples of the form (yielded_from_i1, yielded_from_i2).

aintersperse(→ collections.abc.AsyncGenerator[T])

Yield e, then the next n items in it, and repeat until it is exhausted.

aisempty(→ bool)

Whether the (async) iterable it is empty.

aislice(…)

Async version of itertools.islice that is not a class.

aisprime(→ bool)

Probabilistically test for primality of n. O(log^3 n), with false-positive rate below 2^(-128) for integers above 10^24.

aiter_idx(→ collections.abc.AsyncGenerator[int])

Yield the indices at which value occurs in it within start and stop.

aiterate(→ collections.abc.AsyncGenerator[T])

Yield start, then the awaited output of f called on the previous output repeatedly.

aiterexcept(→ collections.abc.AsyncGenerator[T])

Yield the awaited output of first, then f called with no arguments repeatedly until an exception present in exc occurs.

alast(→ T)

Return the last item in the (async) iterable it, or default if passed and it is empty.

aloops(→ collections.abc.AsyncGenerator[None])

Yield None n times. Equivalent to base.take(aforever(), n) and arepeat(None, n), but without creating intermediate integers.

amap(…)

Async version of map that is not a class, with await_ dictating whether the return value of the function is to be awaited before yielding.

amapif(…)

Essentially the restriction of amultimapif() to one (async) iterable, which allows for more flexibility.

amatmul(→ collections.abc.AsyncGenerator[tuple[X, ...)

Matrix multiplication of M and N. O(n^3) time, since this library does not specialize in these operations.

amatprod(→ M)

Return the product of the matrices in the (async) iterable, preceded by start if passed.

amax(…)

Async version of max().

amergesortedby(…)

Async version of heapq.merge().

amin(…)

Async version of min().

amultifilter(…)

Composition of afilter() and azip().

amultifilterfalse(…)

Composition of afilterfalse() and azip().

amultimapif(…)

Composition of astarmap(), afilter() and azip().

amultistarfilter(…)

Composition of astarfilter() and azip().

amultistarfilterfalse(…)

Composition of astarfilterfalse() and azip().

ancycles(→ collections.abc.AsyncGenerator[T])

Yield the items in the (async) iterable it over and over for a total of n cycles.

anth(→ T)

Return the n-th item of the (async) iterable it, or default if passed and there is no such item.

anth_or_last(→ T)

Return the n-th item in the (async) iterable it, or the last item if out of bounds, or default if passed and it is empty.

anthcombination(→ collections.abc.AsyncGenerator[T])

Return the idx-th combination of r elements from the input iterable it, in lexicographic order.

aonline_sorter(…)

apadnone(→ collections.abc.AsyncGenerator[T | None])

Yield the items in the (async) iterable it, followed by None indefinitely.

apairwise(→ collections.abc.AsyncGenerator[tuple[T, T]])

Async version of itertools.pairwise() that is not a class.

apartition(→ tuple[collections.abc.AsyncGenerator[T], ...)

Return a tuple (fgen, tgen). tgen is an async generator yielding the items in it passing the predicate, and fgen the others.

apermutations(...)

Async version of itertools.permutations() that is not a class.

apolynomial_derivative(→ collections.abc.AsyncGenerator[X])

Compute the coefficients of the derivative of a polynomial. Both input and output iterables are in order of descending powers.

apolynomial_eval(→ X)

Evaluate a polynomial at x given its coefficients in order of descending powers.

apolynomial_from_roots(→ collections.abc.AsyncGenerator[X])

Generate the coefficients of a polynomial given its roots in order of descending powers.

apowers(→ collections.abc.AsyncGenerator[X])

Yield start, start*base, start*base*base, ...

apowers_of_two(→ collections.abc.AsyncGenerator[int])

Optimized version of apowers() using bit shift operations for powers of two, four, eight, etc. Yield init<<init_shift, init<<init_shift+shift, init<<init_shift+2*shift, ...

apowerset(→ collections.abc.AsyncGenerator[tuple[T, ...)

Yield all the subsets of the (async) iterable it (by index!) as tuples, starting with the empty tuple.

apowersetofsets(…)

Yield all the subsets of the items in the (async) iterable of hashable objects after consuming it at once and removing duplicates, as frozenset's if frozen is True (the default) and set's otherwise.

aprepend(→ collections.abc.AsyncGenerator[T])

Prepend val to the (async) iterable it.

aprod(→ X)

Return the product of the items in the (async) iterable, preceded by start if passed.

aproduct(…)

Async version of itertools.product that is not a class.

aquantify(→ int)

Return the number of items in the (async) iterable for which the predicate is true.

arandom_combination_with_replacement(...)

Draw r items at random from the input iterable it, with replacement.

arandom_derangement(→ tuple[T, Ellipsis])

Generate a random derangement of items in the (async) iterable it.

arandom_permutation(→ collections.abc.AsyncGenerator[T])

Choose a random permutation of the elements in it of size r, or all sizes if not passed.

arandomcombination(→ collections.abc.AsyncGenerator[T])

Draw r items at random from the input iterable it, without replacement.

arandomproduct(→ collections.abc.AsyncGenerator[T])

Draw n items from each of the input iterables its at random.

arange(…)

Async version of range that is not a class.

arepeat(→ collections.abc.AsyncGenerator[T])

Async version of itertools.repeat that is not a class.

arepeatfunc(→ collections.abc.AsyncGenerator[T])

Call the async function f with arguments a repeatedly for times times, or indefinitely if times is not passed, and yield the results awaited.

areshape(…)

Change the shape of a tensor according to shape. For an integer shape, the matrix must be 2D and shape is the number of output columns.

areversed(→ collections.abc.AsyncGenerator[T])

Reverse an (async) iterable, calling its __reversed__() method if present, falling back to consuming all the items and yielding them in reverse order.

aroundrobin(→ collections.abc.AsyncGenerator[T])

Yield items from the given (async) iterables in round-robin order, skipping exhausted iterables. Prefer over aroundrobin2() for less iterables.

aroundrobin2(→ collections.abc.AsyncGenerator[T])

Yield items from the given (async) iterables in round-robin order, skipping exhausted iterables. Prefer over aroundrobin() for more iterables.

arunlength_decode(→ collections.abc.AsyncGenerator[T])

Inverse of the above.

arunlength_encode(...)

Compress an (async) iterable into an async generator of pairs with run-length encoding. Items in the result are in the form (item, count), where item is an item from the input iterable and count is the number of times it is repeated consecutively.

arunning_median(→ collections.abc.AsyncGenerator[N])

Yield the median of all the items seen from it within a window of size maxlen, then advance it.

arunningmean(→ collections.abc.AsyncGenerator[X])

Repeatedly yield the mean of the items in the iterable so far, and advance the iterable.

asample_weighted(→ list[T])

The A-Chao with Jumps reservoir sampling algorithm. Chooses k items from an (async) iterable of (item, weight) pairs, where the probability of each item being chosen is proportional to its weight. rrange and rand should be the randrange() and random() methods of a random device respectively.

asamplel(→ list[T])

Algorithm L. Chooses k items from an (async) iterable of items, where each item is chosen with equal probability. rrange and rand should be the randrange() and random() methods of a random device respectively.

asattolo(→ list[T])

Return a list representing a random full-length permutation of the items in it.

asendstream(→ collections.abc.AsyncGenerator[T])

Feed i2 into i1 and yield the results.

aserialize(→ collections.abc.AsyncGenerator[T])

Protect an (async) iterable from being consumed by many parties concurrently by applying an async lock.

aside_effect(…)

asieve(→ collections.abc.AsyncGenerator[int])

Implementation of the Sieve of Eratosthenes, yielding prime numbers strictly smaller than n in order in an async generator.

asliced(→ collections.abc.AsyncGenerator[T])

asorted(…)

Async version of sorted(). O(n log n) time and O(n) space, but nowhere near as optimized as the builtin version.

asplitat(→ collections.abc.AsyncGenerator[list[T]])

Split an async iterator at each item satisfying pred, with keep_sep dictating whether the separator is to be included as the last item of each list.

aspy(→ tuple[collections.abc.AsyncGenerator[T], ...)

Return an async generator containing the first n items, and another containing all the original items.

asquaresum(→ X)

Return the sum of squares of items in an (async) iterable of numbers as a number of the same type.

astarfilter(→ collections.abc.AsyncGenerator[tuple[T, ...)

Filter an (async) iterable of tuples of items, yielding only those tuples for which the predicate returns a truthy value when called on the tuple unpacked.

astarfilterfalse(...)

Filter an (async) iterable of tuples of items, yielding only those tuples for which the predicate returns a falsy value when called on the tuple unpacked.

astarmap(…)

Async version of itertools.starmap that is not a class. await_ specifies whether to await the return value of the transformation function.

astarmap_with_kwds(→ collections.abc.AsyncGenerator[T])

Like amap(), but the iterable should yield tuples of the form (args, kwargs), where args is an iterable of positional arguments and kwargs is a mapping of keyword arguments.

asubslices(→ collections.abc.AsyncGenerator[tuple[T, ...)

asubstrings(), but yield all subslices containing the first item first in ascending order of length, then all subslices containing the second item but not the first, and so on.

asubstr_indices(…)

Yield tuples of the form (substr, start, end), where substr is a contiguous subsequence of seq starting at index start and ending at index end-1 (such that its length is end-start).

asubstrings(→ collections.abc.AsyncGenerator[tuple[T, ...)

Yield all the contiguous subsequences of the (async) iterable it as tuples, in increasing order of length.

asum(→ X)

Return the sum of the items in the (async) iterable, preceded by start if passed.

asumprod(→ X)

Return the sum of products of items in two iterables of numbers as a number of the same type. Not as precise as math.fsumprod() for floating-point numbers, but supports async iterables.

atabulate(…)

Composition of amap() and acount().

atail(→ collections.abc.AsyncGenerator[T])

Yield the last n items from the (async) iterable it.

atakewhile(→ collections.abc.AsyncGenerator[T])

Async version of itertools.takewhile that is not a class.

atakewhile_inclusive(→ collections.abc.AsyncGenerator[T])

atakewhile(), but yielding the first falsy item last.

atakewhilenot(→ collections.abc.AsyncGenerator[T])

Take items from the iterable while the predicate called on the item does not hold.

atakewhilenot_inclusive(...)

atakewhilenot(), but yielding the first truthy item last.

atranspose(→ collections.abc.AsyncGenerator[tuple[T, ...)

Compute the transpose of a matrix.

atriplewise(→ collections.abc.AsyncGenerator[tuple[T, ...)

Yield overlapping triples of items from an (async) iterable.

aunique(→ collections.abc.AsyncGenerator[T])

Yield unique elements from it in sorted order, according to key, which should not be too expensive. If reverse is True, yield in descending order.

aunique_everseen(→ collections.abc.AsyncGenerator[T])

Yield items from the (async) iterable it, without yielding items already previously yielded.

aunique_justseen(→ collections.abc.AsyncGenerator[T])

Yield items from the (async) iterable it, without yielding consecutive duplicate items.

aunique_to_each(→ collections.abc.AsyncGenerator[H])

Given multiple (async) iterables, yield every item that is only seen in exactly one of the iterables.

aunzip(…)

azip(…)

Async version of zip that is not a class.

aziplongest(…)

Async version of itertools.zip_longest that is not a class. The first overload does not accept fillvalue, because passing it with only one iterable does not make sense.

basic_collect(→ list[T])

Return a list of the first n items in the (async) iterable it, signalling no error if there are not enough items.

batch(→ collections.abc.AsyncGenerator[list[T]])

More flexible but slightly slower implementation of batch2(), supporting timeouts waiting for each item, that raises ValueError instead of ItemsExhausted in the case of the length of the iterable being indivisible by the batch size.

batch2(…)

Batch an (async) iterable into an async generator of lists. If strict=True is specified, raise ItemsExhausted on the last batch if it is discovered then that the iterable does not have enough items for a complete batch.

batch_process(→ collections.abc.AsyncGenerator[R])

Apply processor to each batch of size size in items and yield the results awaited.

buffer(→ collections.abc.AsyncGenerator[T])

empty_agen(→ collections.abc.AsyncGenerator[Never])

Return an async generator that yields nothing. Due to async generator finalization issues, this is not a constant like yield_to_event_loop.

fmap(→ list[T])

Return a list of the results of calling each async function in the first argument (an (async) iterable of functions), with the provided arguments.

fmap_parallel(→ collections.abc.AsyncGenerator[T])

Like fmap_sequential(), but starts background tasks for each call.

fmap_sequential(→ collections.abc.AsyncGenerator[T])

Like fmap(), but only call a function after the last completes and the result is gotten.

iter_task(→ asyncio.Task[float])

Return a task that calls summaryf on the passed (async) iterable and returns the time taken to run it. By default, summaryf consumes it fully.

map_on_map(…)

Apply a transformation on an (async) iterable on top of another.

mat_vec_mul(→ collections.abc.AsyncGenerator[int])

Multiplication of a matrix M and a vector V. O(n^2).

merge(→ collections.abc.AsyncGenerator[T])

tee(…)

to_list(→ list[T])

Collect all items of an async iterable into a list. Faster than base.collect().

to_set(…)

Convert the output of to_list() into a set or frozenset depending on the frozen parameter (False by default).

to_tuple(→ tuple[T, Ellipsis])

Convert the output of to_list() into a tuple.

vecs_eq(→ bool)

Whether the vectors u and v are equal according to cmpeq called on each pair of items from iterating through them in parallel. If strict is False (default True), may return True even for differently-sized vectors.

window(→ collections.abc.AsyncGenerator[tuple[T, ...)

Window an async iterable into an async generator of tuples of the specified size and step. You can send in a tuple (size, step) to change the behaviour of the iterator.

Module Contents

asyncutils.iters.aaccumulate[T](
it: asyncutils._internal.types.SupportsIteration[T],
func: collections.abc.Callable[[T, T], T] = ...,
*,
initial: T | None = ...,
) collections.abc.AsyncGenerator[T][source]

Async version of itertools.accumulate that is not a class.

async asyncutils.iters.aall(it: asyncutils._internal.types.SupportsIteration[object]) bool[source]

Async version of all().

async asyncutils.iters.aallequal[T](
it: asyncutils._internal.types.SupportsIteration[T],
key: collections.abc.Callable[[T], object] = ...,
strict: bool = ...,
) bool[source]

Whether all items in the (async) iterable are equal to each other according to the key function. Check for identity rather than equality if strict is True.

async asyncutils.iters.aany(it: asyncutils._internal.types.SupportsIteration[object]) bool[source]

Async version of any().

asyncutils.iters.aappend[T](val: T, it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]

Append val to the (async) iterable it.

async asyncutils.iters.aargmax[T](
it: asyncutils._internal.types.SupportsIteration[T],
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
default: int = ...,
) int[source]
async asyncutils.iters.aargmax(it: asyncutils._internal.types.SupportsIteration[C], *, default: int = ...) int

Return the index of the first occurrence of the maximum element in the (async) iterable it according to key, or default if empty.

async asyncutils.iters.aargmin[T](
it: asyncutils._internal.types.SupportsIteration[T],
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
default: int = ...,
) int[source]
async asyncutils.iters.aargmin(it: asyncutils._internal.types.SupportsIteration[C], *, default: int = ...) int

Return the index of the first occurrence of the minimum element in the (async) iterable it according to key, or default if empty.

asyncutils.iters.aawgenf2agenf[T, **P](
f: collections.abc.Callable[P, collections.abc.AsyncIterable[T]],
/,
) collections.abc.Callable[P, collections.abc.AsyncGenerator[T]][source]

Convert a function that returns an awaitable resolving to an async iterable into one returning an async generator.

asyncutils.iters.abefore_and_after[T](
pred: collections.abc.Callable[[T], object],
it: asyncutils._internal.types.SupportsIteration[T],
) tuple[collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T]][source]

atakewhile(), but return all remaining items in the second async generator (after the first is consumed).

asyncutils.iters.abfs[H: collections.abc.Hashable](
start: H,
neighbours: collections.abc.Callable[[H], asyncutils._internal.types.SupportsIteration[H]],
*,
include_start: bool = ...,
) collections.abc.AsyncGenerator[H][source]

Breadth-first search on a start node start, given a function neighbours that returns an (async) iterable of neighbours to be traversed in order. If include_start is True, the start node is yielded first.

async asyncutils.iters.abrent[T](
next_node: collections.abc.Callable[[T], asyncutils._internal.types.SupportsIteration[T]],
start: T,
/,
) tuple[T, int, int][source]

Brent’s algorithm for cycle detection, assuming that a cycle is indeed present, given a function next_node returning the next node from the previous. Return a tuple (node, la, mu), where node is the first node involved in a cycle. next_node should be deterministic.

asyncutils.iters.ac3merge[T](
seqs: asyncutils._internal.types.SupportsIteration[collections.abc.MutableSequence[T]],
) collections.abc.AsyncGenerator[T][source]

Async version of functools._c3_merge that doesn’t assume the input is an synchronous iterable of mutable sequences of classes.

asyncutils.iters.acanonical[T](it: asyncutils._internal.types.SupportsIteration[T]) list[T][source]

Return a canonicalized ordering of the items in it, which may change across different Python invocations or sessions.

asyncutils.iters.acat[T](first: T) collections.abc.AsyncGenerator[T, T][source]
asyncutils.iters.acat(first: None = ...) collections.abc.AsyncGenerator[T | None, T | None]

An async generator that yields the sent value, starting with first (default None).

asyncutils.iters.acollapse(
it: asyncutils._internal.types.SupportsIteration[object],
base_typ: tuple[type, Ellipsis] | type = ...,
levels: int | None = ...,
) collections.abc.AsyncGenerator[Any][source]

Flatten the (async) iterable it by at most levels levels, without collapsing objects of types specified in base_typ.

asyncutils.iters.acombinations[T](
it: asyncutils._internal.types.SupportsIteration[T],
r: int,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Async version of itertools.combinations() that is not a class.

asyncutils.iters.acombinations_with_replacement[T](
it: asyncutils._internal.types.SupportsIteration[T],
r: int,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Async version of itertools.combinations_with_replacement() that is not a class.

asyncutils.iters.acompress[T](
data: asyncutils._internal.types.SupportsIteration[T],
selectors: asyncutils._internal.types.SupportsIteration[object],
) collections.abc.AsyncGenerator[T][source]

Async version of itertools.compress that is not a class.

async asyncutils.iters.aconsume[T](it: asyncutils._internal.types.SupportsIteration[T], n: int | None = ...) None[source]

Advance the (async) iterable it by n steps, using a function-scoped executor created on demand where appropriate. If you want the item at the final position, use anth() instead.

asyncutils.iters.aconvolve[X: (int, float, complex)](
signal: asyncutils._internal.types.SupportsIteration[X],
kernel: asyncutils._internal.types.SupportsIteration[X],
) collections.abc.AsyncGenerator[X][source]

Polynomial multiplication with coefficients from the two iterables. The first iterable is advanced on demand, meaning it may be infinite, but the second iterable is exhausted immediately, storing all its items in memory.

asyncutils.iters.acount(start: int = ..., step: int = ...) collections.abc.AsyncGenerator[int][source]
asyncutils.iters.acount(start: float, step: int = ...) collections.abc.AsyncGenerator[float]
asyncutils.iters.acount(start: float, step: float) collections.abc.AsyncGenerator[float]
asyncutils.iters.acount(*, step: float) collections.abc.AsyncGenerator[float]

Async version of itertools.count that is not a class.

asyncutils.iters.acountdown(n: int, step: int = ..., *, include_zero: bool = ...) collections.abc.AsyncGenerator[int][source]

Count down from n to zero, excluding zero if it is to appear and include_zero is False (the default), by a step size of step.

asyncutils.iters.acycle[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]

Async version of itertools.cycle that is not a class.

asyncutils.iters.aderangements[T](
it: asyncutils._internal.types.SupportsIteration[T],
r: int | None = ...,
) collections.abc.AsyncGenerator[T][source]

Successive derangements of the elements in it of size r, or all sizes if not passed. Derangements are permutations with no fixed points.

asyncutils.iters.adfs[H: collections.abc.Hashable](
start: H,
neighbours: collections.abc.Callable[[H], asyncutils._internal.types.SupportsIteration[H]],
*,
include_start: bool = ...,
) collections.abc.AsyncGenerator[H][source]

Depth-first search on a start node start, given a function neighbours that returns an (async) iterable of neighbours to be traversed in order. If include_start is True, the start node is yielded first.

asyncutils.iters.adft(xarr: asyncutils._internal.types.SupportsIteration[complex], /) collections.abc.AsyncGenerator[complex][source]

The discrete Fourier transform. O(n^2), since this library does not specialize in these operations.

asyncutils.iters.adistinct_permutations[T](
it: asyncutils._internal.types.SupportsIteration[T],
r: int | None = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Successive distinct permutations of the elements in it of size r, or all sizes if not passed.

asyncutils.iters.adoublestarmap[T](
f: collections.abc.Callable[Ellipsis, T],
it: asyncutils._internal.types.SupportsIteration[collections.abc.Mapping[str, Any]],
/,
) collections.abc.AsyncGenerator[T][source]

Like amap(), but the iterables should yield mappings that are unpacked as arguments to the function.

asyncutils.iters.adropwhile[T](
pred: collections.abc.Callable[[T], object],
it: asyncutils._internal.types.SupportsIteration[T],
*,
skip_first: bool = ...,
) collections.abc.AsyncGenerator[T][source]
Async version of itertools.dropwhile that is not a class.
If skip_first is True, drop also the first item that fails the predicate.
asyncutils.iters.aevery[T](
it: asyncutils._internal.types.SupportsIteration[T],
n: int,
*,
skip_first: bool = ...,
) collections.abc.AsyncGenerator[T][source]

Yield every n-th item from an (async) iterable, optionally skipping the first item.

asyncutils.iters.aeveryother[T](
it: asyncutils._internal.types.SupportsIteration[T],
*,
skip_first: bool = ...,
) collections.abc.AsyncGenerator[T][source]

Yield every other item from an (async) iterable, optionally skipping the first item.

asyncutils.iters.afactor(n: int) collections.abc.AsyncGenerator[int][source]

Generate the prime factors of n asynchronously. Do not rely on the resultant order.

asyncutils.iters.afilter[T](
f: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
) collections.abc.AsyncGenerator[T][source]

Async version of filter that is not a class.

asyncutils.iters.afilterfalse[T](
f: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
) collections.abc.AsyncGenerator[T][source]

Async version of itertools.filterfalse that is not a class.

async asyncutils.iters.afirst[T](it: asyncutils._internal.types.SupportsIteration[T], default: T = ...) T[source]

Return the first item in the (async) iterable it, or default if passed and it is empty.

async asyncutils.iters.afirsttrue[T](
it: asyncutils._internal.types.SupportsIteration[T],
default: T | None = ...,
pred: collections.abc.Callable[[T], object] = ...,
) T[source]

Return the first item in the (async) iterable it

asyncutils.iters.aflatten[T](
it: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
) collections.abc.AsyncGenerator[T][source]

Flatten one level of nesting using achain and return an async iterator over it.

asyncutils.iters.aflatten_tensor(
tensor: asyncutils._internal.types.SupportsIteration[object],
base_typ: tuple[type, Ellipsis] | type = ...,
) collections.abc.AsyncGenerator[Any][source]

acollapse(), but using a different, more memory-efficient strategy that does not support the levels parameter.

asyncutils.iters.aforever() collections.abc.AsyncGenerator[None][source]

An async generator that yields None forever. Equivalent to arepeat(None).

async asyncutils.iters.afreivalds(
A: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[int]],
B: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[int]],
C: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[int]],
k: int = ...,
) bool[source]

The probabilistic Freivalds algorithm to determine if the matrix product of A and B equals C. O(kn^2) time, with a false positive rate of at most 2^(-k) and no false negatives.

async asyncutils.iters.agather[T](
it_of_its: asyncutils._internal.types.SupportsIteration[collections.abc.Awaitable[T]],
return_exceptions: bool = ...,
) list[T][source]

Wraps asyncio.gather() to accept (async) iterables as the first argument, so that unpacking is not needed.

asyncutils.iters.agetitems_from_indices[T](
it: asyncutils._internal.types.SupportsIteration[T],
indices: asyncutils._internal.types.SupportsIteration[SupportsIndex],
setatend: asyncio.Future[float] | None = ...,
finish: bool = ...,
) list[asyncio.Future[T]][source]
Take an (async) iterable and an (async) iterable of integers interpreted as indices, and immediately returns a list of futures.
Their eventual results represent the items of that iterable at the corresponding index.
Also begin consumption of the iterable in the background.
Exceptions will be set in the futures that are not done if results are encountered during iteration or if the index is out of bounds.
Pass in a Future for the setatend parameter, which cancels the background consumption of the async iterable once
it is done and cancels the undone futures.

Attention

Negative indices would consume the whole iterable at once if not already consumed.

Warning

Do not set the result of any returned future; instead, if the result is no longer relevant, cancel the future.

Note

The consumption stops as soon as all the required results are pushed into the respective futures.

asyncutils.iters.agives[T](x: T) collections.abc.AsyncGenerator[T][source]

Yield the given value, then return.

asyncutils.iters.agroupby[T](
it: asyncutils._internal.types.SupportsIteration[T],
key: collections.abc.Callable[[T], T] = ...,
) collections.abc.AsyncGenerator[tuple[T, collections.abc.AsyncGenerator[T]]][source]
asyncutils.iters.agroupby(
it: asyncutils._internal.types.SupportsIteration[T],
key: collections.abc.Callable[[T], R],
) collections.abc.AsyncGenerator[tuple[R, collections.abc.AsyncGenerator[T]]]

Async version of itertools.groupby that is not a class.

asyncutils.iters.agrouper[T](
it: asyncutils._internal.types.SupportsIteration[T],
n: int,
fillvalue: T | asyncutils._internal.types.RaiseType = ...,
) collections.abc.AsyncGenerator[tuple[T | None, Ellipsis]][source]
Collect items of the (async) iterable it into tuples of length n each.
If fillvalue is constants.RAISE, raise ValueError if the last group is not of length n.
Otherwise, pad the last group with fillvalue to length n if needed. No padding is done if not passed.
async asyncutils.iters.aguessmax[T](
it: asyncutils._internal.types.SupportsIteration[T],
estlen: int,
*,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison] = ...,
default: T = ...,
finish_event: asyncutils._internal.types.EventProt | None = ...,
) T[source]

Optimal solution to the secretary problem, using key to guess the maximum item, which is the candidate chosen, with 36.8% accuracy by consuming 36.8% of the (async) iterable.

async asyncutils.iters.aguessmin[T](
it: asyncutils._internal.types.SupportsIteration[T],
estlen: int,
*,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison] = ...,
default: T = ...,
finish_event: asyncutils._internal.types.EventProt | None = ...,
) T[source]

Optimal solution to the secretary problem, using key to guess the minimum item, which is the candidate chosen, with 36.8% accuracy by consuming 36.8% of the (async) iterable.

async asyncutils.iters.ahammingdist[T](
a: asyncutils._internal.types.SupportsIteration[T],
b: asyncutils._internal.types.SupportsIteration[T],
/,
cmpeq: collections.abc.Callable[[T, T], object] = ...,
) int[source]

Return the Hamming distance between two (async) iterables, using cmpeq to check for equality if passed.

asyncutils.iters.aidft(Xarr: asyncutils._internal.types.SupportsIteration[complex], /) collections.abc.AsyncGenerator[complex][source]

The inverse discrete Fourier transform. O(n^2) just like adft().

async asyncutils.iters.ailen(it: asyncutils._internal.types.SupportsIteration[object]) int[source]

Return the length of the (async) iterable it, consuming it entirely.

asyncutils.iters.ainterleave_evenly[T](
its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
lengths: asyncutils._internal.types.SupportsIteration[int] | None = ...,
) collections.abc.AsyncGenerator[T][source]

Interleave items of the iterables evenly according to the lengths if passed, and determined by calling the __len__() method on the iterables if present otherwise.

asyncutils.iters.ainterleave_randomly[T](
its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
) collections.abc.AsyncGenerator[T][source]

Interleave items of the iterables randomly, skipping exhausted iterables.

asyncutils.iters.ainterleave_stopearly[T](*it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]

Yield the items from the iterables in a round-robin fashion until at least one is exhausted.

asyncutils.iters.aintersend[T, R](
i1: collections.abc.AsyncGenerator[T, R],
i2: collections.abc.AsyncGenerator[R, T],
) collections.abc.AsyncGenerator[tuple[T, R]][source]

Feed i1 and i2 into each other and yield tuples of the form (yielded_from_i1, yielded_from_i2).

asyncutils.iters.aintersperse[T](e: T, it: asyncutils._internal.types.SupportsIteration[T], n: int = ...) collections.abc.AsyncGenerator[T][source]

Yield e, then the next n items in it, and repeat until it is exhausted.

async asyncutils.iters.aisempty(it: asyncutils._internal.types.SupportsIteration[object]) bool[source]

Whether the (async) iterable it is empty.

asyncutils.iters.aislice[T](
it: asyncutils._internal.types.SupportsIteration[T],
stop: SupportsIndex | None = ...,
/,
) collections.abc.AsyncGenerator[T][source]
asyncutils.iters.aislice(
it: asyncutils._internal.types.SupportsIteration[T],
start: SupportsIndex | None,
stop: SupportsIndex | None,
step: SupportsIndex | None = ...,
/,
) collections.abc.AsyncGenerator[T]

Async version of itertools.islice that is not a class.

async asyncutils.iters.aisprime(n: int) bool[source]

Probabilistically test for primality of n. O(log^3 n), with false-positive rate below 2^(-128) for integers above 10^24.

asyncutils.iters.aiter_idx[T](
it: asyncutils._internal.types.SupportsIteration[T],
value: T,
start: int = ...,
stop: int | None = ...,
) collections.abc.AsyncGenerator[int][source]

Yield the indices at which value occurs in it within start and stop.

asyncutils.iters.aiterate[T](f: collections.abc.Callable[[T], collections.abc.Awaitable[T]], start: T) collections.abc.AsyncGenerator[T][source]

Yield start, then the awaited output of f called on the previous output repeatedly.

asyncutils.iters.aiterexcept[T](
f: collections.abc.Callable[[], collections.abc.Awaitable[T]],
exc: asyncutils._internal.types.Exceptable,
first: collections.abc.Callable[[], collections.abc.Awaitable[T]] = ...,
) collections.abc.AsyncGenerator[T][source]

Yield the awaited output of first, then f called with no arguments repeatedly until an exception present in exc occurs.

async asyncutils.iters.alast[T](it: asyncutils._internal.types.SupportsIteration[T], default: T = ...) T[source]

Return the last item in the (async) iterable it, or default if passed and it is empty.

asyncutils.iters.aloops(n: int) collections.abc.AsyncGenerator[None][source]

Yield None n times. Equivalent to base.take(aforever(), n) and arepeat(None, n), but without creating intermediate integers.

asyncutils.iters.amap[T, R](
f: collections.abc.Callable[[T], collections.abc.Awaitable[R]],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
await_: Literal[True],
strict: Literal[False] = ...,
) collections.abc.AsyncGenerator[R][source]
asyncutils.iters.amap(
f: collections.abc.Callable[[T], R],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
await_: Literal[False] = ...,
strict: Literal[False] = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[[T, S], collections.abc.Awaitable[R]],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[S],
/,
*,
await_: Literal[True],
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[[T, S], R],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[S],
/,
*,
await_: Literal[False] = ...,
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[[T, S, V], collections.abc.Awaitable[R]],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[S],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
await_: Literal[True],
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[[T, S, V], R],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[S],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
await_: Literal[False] = ...,
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[[T, S, V, U], collections.abc.Awaitable[R]],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[S],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
await_: Literal[True],
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[[T, S, V, U], R],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[S],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
await_: Literal[False] = ...,
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[[*tuple[T, ...]], collections.abc.Awaitable[R]],
/,
*its: asyncutils._internal.types.SupportsIteration[T],
await_: Literal[True],
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[[*tuple[T, ...]], R],
/,
*its: asyncutils._internal.types.SupportsIteration[T],
await_: Literal[False] = ...,
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[Ellipsis, collections.abc.Awaitable[R]],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
await_: Literal[True],
strict: bool = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amap(
f: collections.abc.Callable[Ellipsis, R],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
await_: Literal[False] = ...,
strict: bool = ...,
) collections.abc.AsyncGenerator[R]

Async version of map that is not a class, with await_ dictating whether the return value of the function is to be awaited before yielding.

asyncutils.iters.amapif[T, R](
f: collections.abc.Callable[[T], R],
pred: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
/,
await_: Literal[False] = ...,
) collections.abc.AsyncGenerator[R][source]
asyncutils.iters.amapif(
f: collections.abc.Callable[[T], collections.abc.Awaitable[R]],
pred: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
/,
await_: Literal[True],
) collections.abc.AsyncGenerator[R]

Essentially the restriction of amultimapif() to one (async) iterable, which allows for more flexibility.

asyncutils.iters.amatmul[X: (int, float, complex)](
M: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[X]],
N: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[X]],
) collections.abc.AsyncGenerator[tuple[X, Ellipsis]][source]

Matrix multiplication of M and N. O(n^3) time, since this library does not specialize in these operations.

async asyncutils.iters.amatprod[M: asyncutils._internal.types.SupportsMatMul](it: asyncutils._internal.types.SupportsIteration[M], start: M) M[source]

Return the product of the matrices in the (async) iterable, preceded by start if passed.

async asyncutils.iters.amax[C: asyncutils._internal.types.SupportsRichComparison](it: asyncutils._internal.types.SupportsIteration[C], *, default: C = ...) C[source]
async asyncutils.iters.amax(arg1: C, arg2: C, /, *args: C, default: C = ...) C
async asyncutils.iters.amax(
it: asyncutils._internal.types.SupportsIteration[T],
*,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
default: T = ...,
) T
async asyncutils.iters.amax(
arg1: T,
arg2: T,
/,
*args: T,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
default: T = ...,
) T

Async version of max().

asyncutils.iters.amergesortedby[C: asyncutils._internal.types.SupportsRichComparison](
its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[C]],
*,
key: collections.abc.Callable[[C], C] = ...,
await_: Literal[False] = ...,
reverse: bool = ...,
) collections.abc.AsyncGenerator[C][source]
asyncutils.iters.amergesortedby(
its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
*,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
await_: Literal[False] = ...,
reverse: bool = ...,
) collections.abc.AsyncGenerator[T]
asyncutils.iters.amergesortedby(
its: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
*,
key: collections.abc.Callable[[T], collections.abc.Awaitable[asyncutils._internal.types.SupportsRichComparison]],
await_: Literal[True],
reverse: bool = ...,
) collections.abc.AsyncGenerator[T]

Async version of heapq.merge().

async asyncutils.iters.amin[C: asyncutils._internal.types.SupportsRichComparison](it: asyncutils._internal.types.SupportsIteration[C], *, default: C = ...) C[source]
async asyncutils.iters.amin(arg1: C, arg2: C, /, *args: C, default: C = ...) C
async asyncutils.iters.amin(
it: asyncutils._internal.types.SupportsIteration[T],
*,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
default: T = ...,
) T
async asyncutils.iters.amin(
arg1: T,
arg2: T,
/,
*args: T,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
default: T = ...,
) T

Async version of min().

asyncutils.iters.amultifilter[T](
pred: collections.abc.Callable[[tuple[T]], object],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T]][source]
asyncutils.iters.amultifilter(
pred: collections.abc.Callable[[tuple[T, R]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R]]
asyncutils.iters.amultifilter(
pred: collections.abc.Callable[[tuple[T, R, V]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V]]
asyncutils.iters.amultifilter(
pred: collections.abc.Callable[[tuple[T, R, V, U]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U]]
asyncutils.iters.amultifilter(
pred: collections.abc.Callable[[tuple[T, R, V, U, S]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U, S]]
asyncutils.iters.amultifilter(
pred: collections.abc.Callable[[tuple[T, Ellipsis]], object],
/,
*its: asyncutils._internal.types.SupportsIteration[T],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]]
asyncutils.iters.amultifilter(
pred: collections.abc.Callable[[tuple[Any, Ellipsis]], object],
i1: asyncutils._internal.types.SupportsIteration[object],
i2: asyncutils._internal.types.SupportsIteration[object],
i3: asyncutils._internal.types.SupportsIteration[object],
i4: asyncutils._internal.types.SupportsIteration[object],
i5: asyncutils._internal.types.SupportsIteration[object],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[Any, Ellipsis]]

Composition of afilter() and azip().

asyncutils.iters.amultifilterfalse[T](
pred: collections.abc.Callable[[tuple[T]], object],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T]][source]
asyncutils.iters.amultifilterfalse(
pred: collections.abc.Callable[[tuple[T, R]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R]]
asyncutils.iters.amultifilterfalse(
pred: collections.abc.Callable[[tuple[T, R, V]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V]]
asyncutils.iters.amultifilterfalse(
pred: collections.abc.Callable[[tuple[T, R, V, U]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U]]
asyncutils.iters.amultifilterfalse(
pred: collections.abc.Callable[[tuple[T, R, V, U, S]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U, S]]
asyncutils.iters.amultifilterfalse(
pred: collections.abc.Callable[[tuple[T, Ellipsis]], object],
/,
*its: asyncutils._internal.types.SupportsIteration[T],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]]
asyncutils.iters.amultifilterfalse(
pred: collections.abc.Callable[[tuple[Any, Ellipsis]], object],
i1: asyncutils._internal.types.SupportsIteration[object],
i2: asyncutils._internal.types.SupportsIteration[object],
i3: asyncutils._internal.types.SupportsIteration[object],
i4: asyncutils._internal.types.SupportsIteration[object],
i5: asyncutils._internal.types.SupportsIteration[object],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[Any, Ellipsis]]

Composition of afilterfalse() and azip().

asyncutils.iters.amultimapif[T, R](
f: collections.abc.Callable[[T], R],
pred: collections.abc.Callable[[tuple[T]], object],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
await_: Literal[False] = ...,
) collections.abc.AsyncGenerator[R][source]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[T], collections.abc.Awaitable[R]],
pred: collections.abc.Callable[[tuple[T]], object],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
await_: Literal[True],
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[T, V], R],
pred: collections.abc.Callable[[tuple[T, V]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[V],
/,
*,
await_: Literal[False] = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[T, V], collections.abc.Awaitable[R]],
pred: collections.abc.Callable[[tuple[T, V]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[V],
/,
*,
await_: Literal[True],
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[T, V, S], R],
pred: collections.abc.Callable[[tuple[T, V, S]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[V],
i3: asyncutils._internal.types.SupportsIteration[S],
/,
*,
await_: Literal[False] = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[T, V, S], collections.abc.Awaitable[R]],
pred: collections.abc.Callable[[tuple[T, V, S]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[V],
i3: asyncutils._internal.types.SupportsIteration[S],
/,
*,
await_: Literal[True],
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[T, V, S, U], R],
pred: collections.abc.Callable[[tuple[T, V, S, U]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[V],
i3: asyncutils._internal.types.SupportsIteration[S],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
await_: Literal[False] = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[T, V, S, U], collections.abc.Awaitable[R]],
pred: collections.abc.Callable[[tuple[T, V, S, U]], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[V],
i3: asyncutils._internal.types.SupportsIteration[S],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
await_: Literal[True],
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[*Ts], R],
pred: collections.abc.Callable[[tuple[*Ts]], object],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
await_: Literal[False] = ...,
) collections.abc.AsyncGenerator[R]
asyncutils.iters.amultimapif(
f: collections.abc.Callable[[*Ts], collections.abc.Awaitable[R]],
pred: collections.abc.Callable[[tuple[*Ts]], object],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
await_: Literal[True],
) collections.abc.AsyncGenerator[R]

Composition of astarmap(), afilter() and azip().

asyncutils.iters.amultistarfilter[T](
pred: collections.abc.Callable[[T], object],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T]][source]
asyncutils.iters.amultistarfilter(
pred: collections.abc.Callable[[T, R], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R]]
asyncutils.iters.amultistarfilter(
pred: collections.abc.Callable[[T, R, V], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V]]
asyncutils.iters.amultistarfilter(
pred: collections.abc.Callable[[T, R, V, U], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U]]
asyncutils.iters.amultistarfilter(
pred: collections.abc.Callable[[T, R, V, U, S], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U, S]]
asyncutils.iters.amultistarfilter(
pred: collections.abc.Callable[[*tuple[T, ...]], object],
/,
*its: asyncutils._internal.types.SupportsIteration[T],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]]
asyncutils.iters.amultistarfilter(
pred: collections.abc.Callable[[*tuple[Any, ...]], object],
i1: asyncutils._internal.types.SupportsIteration[object],
i2: asyncutils._internal.types.SupportsIteration[object],
i3: asyncutils._internal.types.SupportsIteration[object],
i4: asyncutils._internal.types.SupportsIteration[object],
i5: asyncutils._internal.types.SupportsIteration[object],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[Any, Ellipsis]]

Composition of astarfilter() and azip().

asyncutils.iters.amultistarfilterfalse[T](
pred: collections.abc.Callable[[T], object],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T]][source]
asyncutils.iters.amultistarfilterfalse(
pred: collections.abc.Callable[[T, R], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R]]
asyncutils.iters.amultistarfilterfalse(
pred: collections.abc.Callable[[T, R, V], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V]]
asyncutils.iters.amultistarfilterfalse(
pred: collections.abc.Callable[[T, R, V, U], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U]]
asyncutils.iters.amultistarfilterfalse(
pred: collections.abc.Callable[[T, R, V, U, S], object],
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
*,
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U, S]]
asyncutils.iters.amultistarfilterfalse(
pred: collections.abc.Callable[[*tuple[T, ...]], object],
/,
*its: asyncutils._internal.types.SupportsIteration[T],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]]
asyncutils.iters.amultistarfilterfalse(
pred: collections.abc.Callable[[*tuple[Any, ...]], object],
i1: asyncutils._internal.types.SupportsIteration[object],
i2: asyncutils._internal.types.SupportsIteration[object],
i3: asyncutils._internal.types.SupportsIteration[object],
i4: asyncutils._internal.types.SupportsIteration[object],
i5: asyncutils._internal.types.SupportsIteration[object],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[Any, Ellipsis]]

Composition of astarfilterfalse() and azip().

asyncutils.iters.ancycles[T](it: asyncutils._internal.types.SupportsIteration[T], n: int) collections.abc.AsyncGenerator[T][source]

Yield the items in the (async) iterable it over and over for a total of n cycles.

async asyncutils.iters.anth[T](it: asyncutils._internal.types.SupportsIteration[T], n: int, default: T = ...) T[source]

Return the n-th item of the (async) iterable it, or default if passed and there is no such item.

async asyncutils.iters.anth_or_last[T](it: asyncutils._internal.types.SupportsIteration[T], n: int, default: T = ...) T[source]

Return the n-th item in the (async) iterable it, or the last item if out of bounds, or default if passed and it is empty.

asyncutils.iters.anthcombination[T](it: asyncutils._internal.types.SupportsIteration[T], r: int, idx: int) collections.abc.AsyncGenerator[T][source]

Return the idx-th combination of r elements from the input iterable it, in lexicographic order.

asyncutils.iters.aonline_sorter[T](
it: asyncutils._internal.types.SupportsIteration[T],
*,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
reverse: bool = ...,
slow: bool = ...,
) collections.abc.AsyncGenerator[T, T | None][source]
asyncutils.iters.aonline_sorter(
it: asyncutils._internal.types.SupportsIteration[C],
*,
reverse: bool = ...,
slow: bool = ...,
) collections.abc.AsyncGenerator[C, C | None]
Sort items from an (async) iterable and those sent in on the fly in the async generator interface (i.e. by awaiting
the return value of asend()), according to key and reverse.
Does not work well with items that are None.
Evaluates the truthiness of the slow parameter every time a new item is received, and if it is True, offloads the evaluation of the
key for that item to an executor, such that the __bool__() method on slow may reflect the state of the program but can also be
a plain boolean.

Note

Uses a stable variant of heap sort internally, which is O(n log n) time and O(n) space.

Changed in version 0.9.9: The it parameter is now required because an async generator can only be primed asynchronously, and a non-None value cannot be sent in to start the async generator, causing the resultant generator to always be empty. If it itself is empty, the generator will also be empty.

asyncutils.iters.apadnone[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T | None][source]

Yield the items in the (async) iterable it, followed by None indefinitely.

asyncutils.iters.apairwise[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, T]][source]

Async version of itertools.pairwise() that is not a class.

asyncutils.iters.apartition[T](
pred: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
) tuple[collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T]][source]

Return a tuple (fgen, tgen). tgen is an async generator yielding the items in it passing the predicate, and fgen the others.

asyncutils.iters.apermutations[T](
it: asyncutils._internal.types.SupportsIteration[T],
r: int | None = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Async version of itertools.permutations() that is not a class.

asyncutils.iters.apolynomial_derivative[X: (int, float, complex)](coeff: asyncutils._internal.types.SupportsIteration[X]) collections.abc.AsyncGenerator[X][source]

Compute the coefficients of the derivative of a polynomial. Both input and output iterables are in order of descending powers.

async asyncutils.iters.apolynomial_eval[X: (int, float, complex)](coeff: asyncutils._internal.types.SupportsIteration[X], x: X) X[source]

Evaluate a polynomial at x given its coefficients in order of descending powers.

asyncutils.iters.apolynomial_from_roots[X: (int, float, complex)](roots: asyncutils._internal.types.SupportsIteration[X]) collections.abc.AsyncGenerator[X][source]

Generate the coefficients of a polynomial given its roots in order of descending powers.

asyncutils.iters.apowers[X: (int, float, complex)](base: X, start: X = ...) collections.abc.AsyncGenerator[X][source]

Yield start, start*base, start*base*base, …

Changed in version 0.9.9: When it is found that the base is a perfect power of two, this will delegate to apowers_of_two() as an optimization.

asyncutils.iters.apowers_of_two(*, init: int = ..., init_shift: int = ..., shift: int = ...) collections.abc.AsyncGenerator[int][source]

Optimized version of apowers() using bit shift operations for powers of two, four, eight, etc. Yield init<<init_shift, init<<init_shift+shift, init<<init_shift+2*shift, …

asyncutils.iters.apowerset[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Yield all the subsets of the (async) iterable it (by index!) as tuples, starting with the empty tuple.

asyncutils.iters.apowersetofsets[H: collections.abc.Hashable](
it: asyncutils._internal.types.SupportsIteration[H],
*,
frozen: Literal[True] = ...,
) collections.abc.AsyncGenerator[frozenset[H]][source]
asyncutils.iters.apowersetofsets(
it: asyncutils._internal.types.SupportsIteration[H],
*,
frozen: Literal[False],
) collections.abc.AsyncGenerator[set[H]]

Yield all the subsets of the items in the (async) iterable of hashable objects after consuming it at once and removing duplicates, as frozenset’s if frozen is True (the default) and set’s otherwise.

asyncutils.iters.aprepend[T](val: T, it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]

Prepend val to the (async) iterable it.

async asyncutils.iters.aprod[X: (int, float, complex)](it: asyncutils._internal.types.SupportsIteration[X], start: X = ...) X[source]

Return the product of the items in the (async) iterable, preceded by start if passed.

asyncutils.iters.aproduct[T](
i1: asyncutils._internal.types.SupportsIteration[T],
/,
*,
repeat: Literal[1] = ...,
) collections.abc.AsyncGenerator[tuple[T]][source]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
/,
*,
repeat: int,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
*,
repeat: Literal[1] = ...,
) collections.abc.AsyncGenerator[tuple[T, R]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
*,
repeat: int,
) collections.abc.AsyncGenerator[tuple[T | R, Ellipsis]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
repeat: Literal[1] = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
repeat: int,
) collections.abc.AsyncGenerator[tuple[T | R | V, Ellipsis]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
repeat: Literal[1] = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
repeat: int,
) collections.abc.AsyncGenerator[tuple[T | R | V | U, Ellipsis]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
*,
repeat: Literal[1] = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U, S]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
*,
repeat: int,
) collections.abc.AsyncGenerator[tuple[T | R | V | U | S, Ellipsis]]
asyncutils.iters.aproduct(
i1: asyncutils._internal.types.SupportsIteration[object],
i2: asyncutils._internal.types.SupportsIteration[object],
i3: asyncutils._internal.types.SupportsIteration[object],
i4: asyncutils._internal.types.SupportsIteration[object],
i5: asyncutils._internal.types.SupportsIteration[object],
/,
*its: asyncutils._internal.types.SupportsIteration[object],
repeat: int = ...,
) collections.abc.AsyncGenerator[tuple[Any, Ellipsis]]
asyncutils.iters.aproduct(
*its: asyncutils._internal.types.SupportsIteration[T],
repeat: int = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]]

Async version of itertools.product that is not a class.

async asyncutils.iters.aquantify[T](it: asyncutils._internal.types.SupportsIteration[T], pred: collections.abc.Callable[[T], object] = ...) int[source]

Return the number of items in the (async) iterable for which the predicate is true.

asyncutils.iters.arandom_combination_with_replacement[T](
it: asyncutils._internal.types.SupportsIteration[T],
r: int,
) collections.abc.AsyncGenerator[T][source]

Draw r items at random from the input iterable it, with replacement.

async asyncutils.iters.arandom_derangement[T](it: asyncutils._internal.types.SupportsIteration[T]) tuple[T, Ellipsis][source]

Generate a random derangement of items in the (async) iterable it.

asyncutils.iters.arandom_permutation[T](
it: asyncutils._internal.types.SupportsIteration[T],
r: int | None = ...,
) collections.abc.AsyncGenerator[T][source]

Choose a random permutation of the elements in it of size r, or all sizes if not passed.

asyncutils.iters.arandomcombination[T](it: asyncutils._internal.types.SupportsIteration[T], r: int) collections.abc.AsyncGenerator[T][source]

Draw r items at random from the input iterable it, without replacement.

asyncutils.iters.arandomproduct[T](*its: asyncutils._internal.types.SupportsIteration[T], n: int = ...) collections.abc.AsyncGenerator[T][source]

Draw n items from each of the input iterables its at random.

asyncutils.iters.arange(stop: int, /) collections.abc.AsyncGenerator[int][source]
asyncutils.iters.arange(start: int, stop: int, /) collections.abc.AsyncGenerator[int]
asyncutils.iters.arange(start: int, stop: int, step: int, /) collections.abc.AsyncGenerator[int]

Async version of range that is not a class.

asyncutils.iters.arepeat[T](elem: T, n: int = ...) collections.abc.AsyncGenerator[T][source]

Async version of itertools.repeat that is not a class.

asyncutils.iters.arepeatfunc[T, *Ts](
f: collections.abc.Callable[[*Ts], collections.abc.Awaitable[T]],
times: int | None = ...,
*a: *Ts,
) collections.abc.AsyncGenerator[T][source]

Call the async function f with arguments a repeatedly for times times, or indefinitely if times is not passed, and yield the results awaited.

asyncutils.iters.areshape[T](
mat: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
shape: int,
) collections.abc.AsyncGenerator[list[T]][source]
asyncutils.iters.areshape(
mat: asyncutils._internal.types.SupportsIteration[object],
shape: asyncutils._internal.types.SupportsIteration[int],
) collections.abc.AsyncGenerator[list[Any]]

Change the shape of a tensor according to shape. For an integer shape, the matrix must be 2D and shape is the number of output columns.

asyncutils.iters.areversed[T](
it: asyncutils._internal.types.SupportsIteration[T] | collections.abc.Reversible[T],
/,
) collections.abc.AsyncGenerator[T][source]

Reverse an (async) iterable, calling its __reversed__() method if present, falling back to consuming all the items and yielding them in reverse order.

asyncutils.iters.aroundrobin[T](*its: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]

Yield items from the given (async) iterables in round-robin order, skipping exhausted iterables. Prefer over aroundrobin2() for less iterables.

asyncutils.iters.aroundrobin2[T](*its: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]

Yield items from the given (async) iterables in round-robin order, skipping exhausted iterables. Prefer over aroundrobin() for more iterables.

asyncutils.iters.arunlength_decode[T](it: asyncutils._internal.types.SupportsIteration[tuple[T, int]], /) collections.abc.AsyncGenerator[T][source]

Inverse of the above.

asyncutils.iters.arunlength_encode[T](it: asyncutils._internal.types.SupportsIteration[T], /) collections.abc.AsyncGenerator[tuple[T, int]][source]

Compress an (async) iterable into an async generator of pairs with run-length encoding. Items in the result are in the form (item, count), where item is an item from the input iterable and count is the number of times it is repeated consecutively.

asyncutils.iters.arunning_median[N: (int, float)](
it: asyncutils._internal.types.SupportsIteration[N],
*,
maxlen: SupportsIndex | None = ...,
) collections.abc.AsyncGenerator[N][source]

Yield the median of all the items seen from it within a window of size maxlen, then advance it.

asyncutils.iters.arunningmean[X: (int | float, complex)](it: asyncutils._internal.types.SupportsIteration[X]) collections.abc.AsyncGenerator[X][source]

Repeatedly yield the mean of the items in the iterable so far, and advance the iterable.

async asyncutils.iters.asample_weighted[T](
it: asyncutils._internal.types.SupportsIteration[tuple[T, float]],
k: int,
*,
rrange: collections.abc.Callable[[int], int] = ...,
rand: collections.abc.Callable[[], float] = ...,
) list[T][source]

The A-Chao with Jumps reservoir sampling algorithm. Chooses k items from an (async) iterable of (item, weight) pairs, where the probability of each item being chosen is proportional to its weight. rrange and rand should be the randrange() and random() methods of a random device respectively.

async asyncutils.iters.asamplel[T](
it: asyncutils._internal.types.SupportsIteration[T],
k: int,
*,
rrange: collections.abc.Callable[[int], int] = ...,
rand: collections.abc.Callable[[], float] = ...,
) list[T][source]

Algorithm L. Chooses k items from an (async) iterable of items, where each item is chosen with equal probability. rrange and rand should be the randrange() and random() methods of a random device respectively.

async asyncutils.iters.asattolo[T](it: asyncutils._internal.types.SupportsIteration[T], /) list[T][source]

Return a list representing a random full-length permutation of the items in it.

asyncutils.iters.asendstream[T, R](
i1: collections.abc.AsyncGenerator[T, R],
i2: asyncutils._internal.types.SupportsIteration[R],
) collections.abc.AsyncGenerator[T][source]

Feed i2 into i1 and yield the results.

asyncutils.iters.aserialize[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[T][source]

Protect an (async) iterable from being consumed by many parties concurrently by applying an async lock.

asyncutils.iters.aside_effect[T](
f: collections.abc.Callable[[list[T]], object],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
size: int,
before: collections.abc.Callable[[], object] | None = ...,
after: collections.abc.Callable[[], object] | None = ...,
) collections.abc.AsyncGenerator[T][source]
asyncutils.iters.aside_effect(
f: collections.abc.Callable[[T], object],
it: asyncutils._internal.types.SupportsIteration[T],
/,
*,
size: None = ...,
before: collections.abc.Callable[[], object] | None = ...,
after: collections.abc.Callable[[], object] | None = ...,
) collections.abc.AsyncGenerator[T]
Apply a side effect function f to each item in an (async) iterable it and yield the items unchanged in an async generator.
If size is specified, the side effect function is applied to batches of that size instead of individual items, but the items are
still yielded separately.
The before and after functions are called before and after the iteration, respectively, but after is not called if
before fails.
asyncutils.iters.asieve(n: int) collections.abc.AsyncGenerator[int][source]

Implementation of the Sieve of Eratosthenes, yielding prime numbers strictly smaller than n in order in an async generator.

asyncutils.iters.asliced[T: asyncutils._internal.types.SupportsSlicing[Any]](seq: T, n: int, strict: bool = ...) collections.abc.AsyncGenerator[T][source]
Slice a slicable object seq (so named because these are usually sequences) and yield slices of the size n, which should be of the same type as seq, from the start to the end.
If strict is True, raise ValueError if the length of any slice is less than n (should only happen for the last slice unless the __getitem__() method is misimplemented).
asyncutils.iters.asorted[C: asyncutils._internal.types.SupportsRichComparison](it: asyncutils._internal.types.SupportsIteration[C], *, reverse: bool = ...) list[C][source]
asyncutils.iters.asorted(
it: asyncutils._internal.types.SupportsIteration[T],
*,
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison],
reverse: bool = ...,
) list[T]

Async version of sorted(). O(n log n) time and O(n) space, but nowhere near as optimized as the builtin version.

asyncutils.iters.asplitat[T](
it: asyncutils._internal.types.SupportsIteration[T],
pred: collections.abc.Callable[[T], object],
maxsplit: int = ...,
keep_sep: bool = ...,
) collections.abc.AsyncGenerator[list[T]][source]

Split an async iterator at each item satisfying pred, with keep_sep dictating whether the separator is to be included as the last item of each list.

asyncutils.iters.aspy[T](
it: asyncutils._internal.types.SupportsIteration[T],
n: int = ...,
) tuple[collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T]][source]

Return an async generator containing the first n items, and another containing all the original items.

async asyncutils.iters.asquaresum[X: (int, float, complex)](it: asyncutils._internal.types.SupportsIteration[X]) X[source]

Return the sum of squares of items in an (async) iterable of numbers as a number of the same type.

asyncutils.iters.astarfilter[T](
pred: collections.abc.Callable[[*tuple[T, ...]], object],
it: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Filter an (async) iterable of tuples of items, yielding only those tuples for which the predicate returns a truthy value when called on the tuple unpacked.

asyncutils.iters.astarfilterfalse[T](
pred: collections.abc.Callable[[*tuple[T, ...]], object],
it: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Filter an (async) iterable of tuples of items, yielding only those tuples for which the predicate returns a falsy value when called on the tuple unpacked.

asyncutils.iters.astarmap[*Ts, R](
f: collections.abc.Callable[[*Ts], R],
it: asyncutils._internal.types.SupportsIteration[tuple[*Ts]],
/,
await_: Literal[False] = ...,
) collections.abc.AsyncGenerator[R][source]
asyncutils.iters.astarmap(
f: collections.abc.Callable[[*Ts], collections.abc.Awaitable[R]],
it: asyncutils._internal.types.SupportsIteration[tuple[*Ts]],
/,
await_: Literal[True],
) collections.abc.AsyncGenerator[R]

Async version of itertools.starmap that is not a class. await_ specifies whether to await the return value of the transformation function.

asyncutils.iters.astarmap_with_kwds[T](
f: collections.abc.Callable[Ellipsis, T],
it: asyncutils._internal.types.SupportsIteration[tuple[collections.abc.Iterable[Any], collections.abc.Mapping[str, Any]]],
/,
) collections.abc.AsyncGenerator[T][source]

Like amap(), but the iterable should yield tuples of the form (args, kwargs), where args is an iterable of positional arguments and kwargs is a mapping of keyword arguments.

asyncutils.iters.asubslices[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

asubstrings(), but yield all subslices containing the first item first in ascending order of length, then all subslices containing the second item but not the first, and so on.

asyncutils.iters.asubstr_indices[S: (str, bytes, bytearray)](seq: S, reverse: bool = ...) collections.abc.AsyncGenerator[tuple[S, int, int]][source]
asyncutils.iters.asubstr_indices(
seq: asyncutils._internal.types.SupportsSlicing[T],
reverse: bool = ...,
) collections.abc.AsyncGenerator[tuple[collections.abc.Iterable[T], int, int]]

Yield tuples of the form (substr, start, end), where substr is a contiguous subsequence of seq starting at index start and ending at index end-1 (such that its length is end-start).

asyncutils.iters.asubstrings[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Yield all the contiguous subsequences of the (async) iterable it as tuples, in increasing order of length.

async asyncutils.iters.asum[X: (int, float, complex)](it: asyncutils._internal.types.SupportsIteration[X], start: X = ...) X[source]

Return the sum of the items in the (async) iterable, preceded by start if passed.

async asyncutils.iters.asumprod[X: (int, float, complex)](p: asyncutils._internal.types.SupportsIteration[X], q: asyncutils._internal.types.SupportsIteration[X], /) X[source]

Return the sum of products of items in two iterables of numbers as a number of the same type. Not as precise as math.fsumprod() for floating-point numbers, but supports async iterables.

asyncutils.iters.atabulate[T](
f: collections.abc.Callable[[int], T],
start: int = ...,
step: int = ...,
/,
*,
await_: Literal[False] = ...,
) collections.abc.AsyncGenerator[T][source]
asyncutils.iters.atabulate(
f: collections.abc.Callable[[int], collections.abc.Awaitable[T]],
start: int = ...,
step: int = ...,
/,
*,
await_: Literal[True],
) collections.abc.AsyncGenerator[T]

Composition of amap() and acount().

asyncutils.iters.atail[T](n: int, it: asyncutils._internal.types.SupportsIteration[T], /) collections.abc.AsyncGenerator[T][source]

Yield the last n items from the (async) iterable it.

asyncutils.iters.atakewhile[T](
pred: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
) collections.abc.AsyncGenerator[T][source]

Async version of itertools.takewhile that is not a class.

asyncutils.iters.atakewhile_inclusive[T](
pred: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
) collections.abc.AsyncGenerator[T][source]

atakewhile(), but yielding the first falsy item last.

asyncutils.iters.atakewhilenot[T](
pred: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
) collections.abc.AsyncGenerator[T][source]

Take items from the iterable while the predicate called on the item does not hold.

asyncutils.iters.atakewhilenot_inclusive[T](
pred: collections.abc.Callable[[T], object] | None,
it: asyncutils._internal.types.SupportsIteration[T],
) collections.abc.AsyncGenerator[T][source]

atakewhilenot(), but yielding the first truthy item last.

asyncutils.iters.atranspose[T](
mat: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[T]],
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]][source]

Compute the transpose of a matrix.

asyncutils.iters.atriplewise[T](it: asyncutils._internal.types.SupportsIteration[T]) collections.abc.AsyncGenerator[tuple[T, T, T]][source]

Yield overlapping triples of items from an (async) iterable.

asyncutils.iters.aunique[T](
it: asyncutils._internal.types.SupportsIteration[T],
key: collections.abc.Callable[[T], asyncutils._internal.types.SupportsRichComparison] | None = ...,
reverse: bool = ...,
) collections.abc.AsyncGenerator[T][source]

Yield unique elements from it in sorted order, according to key, which should not be too expensive. If reverse is True, yield in descending order.

asyncutils.iters.aunique_everseen[T](
it: asyncutils._internal.types.SupportsIteration[T],
key: collections.abc.Callable[[T], object] = ...,
) collections.abc.AsyncGenerator[T][source]

Yield items from the (async) iterable it, without yielding items already previously yielded.

asyncutils.iters.aunique_justseen[T](
it: asyncutils._internal.types.SupportsIteration[T],
key: collections.abc.Callable[[T], object] = ...,
) collections.abc.AsyncGenerator[T][source]

Yield items from the (async) iterable it, without yielding consecutive duplicate items.

asyncutils.iters.aunique_to_each[H: collections.abc.Hashable](*its: asyncutils._internal.types.SupportsIteration[H]) collections.abc.AsyncGenerator[H][source]

Given multiple (async) iterables, yield every item that is only seen in exactly one of the iterables.

async asyncutils.iters.aunzip[T](
ait: asyncutils._internal.types.SupportsIteration[tuple[T]],
*,
put_batch: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T]][source]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T | R]],
*,
put_batch: int = ...,
fillvalue: R,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T]]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T, S]],
*,
put_batch: int = ...,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T], asyncutils._internal.types.AUnzipConsumer[S]]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T | R, S | R]],
*,
put_batch: int = ...,
fillvalue: R,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T], asyncutils._internal.types.AUnzipConsumer[S]]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T, S, V]],
*,
put_batch: int = ...,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T], asyncutils._internal.types.AUnzipConsumer[S], asyncutils._internal.types.AUnzipConsumer[V]]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T | R, S | R, V | R]],
*,
put_batch: int = ...,
fillvalue: R,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T], asyncutils._internal.types.AUnzipConsumer[S], asyncutils._internal.types.AUnzipConsumer[V]]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T, S, V, U]],
*,
put_batch: int = ...,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T], asyncutils._internal.types.AUnzipConsumer[S], asyncutils._internal.types.AUnzipConsumer[V], asyncutils._internal.types.AUnzipConsumer[U]]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T | R, S | R, V | R, U | R]],
*,
put_batch: int = ...,
fillvalue: R,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T], asyncutils._internal.types.AUnzipConsumer[S], asyncutils._internal.types.AUnzipConsumer[V], asyncutils._internal.types.AUnzipConsumer[U]]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T, Ellipsis]],
*,
put_batch: int = ...,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T], Ellipsis]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[T | R, Ellipsis]],
*,
put_batch: int = ...,
fillvalue: R,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[T], Ellipsis]
async asyncutils.iters.aunzip(
ait: asyncutils._internal.types.SupportsIteration[tuple[Any, Ellipsis]],
*,
put_batch: int = ...,
fillvalue: object = ...,
maxqsize: int = ...,
) tuple[asyncutils._internal.types.AUnzipConsumer[Any], Ellipsis]
Undo the effect of zip, itertools.zip_longest, aziplongest() or azip().
This function operates lazily, consuming items from the async iterable only when needed, in batches of size put_batch (default
context.AUNZIP_DEFAULT_PUT_BATCH) and caching other items in queues of capacity maxqsize (default
context.AUNZIP_DEFAULT_MAX_QSIZE).

Warning

This function may require significant auxiliary space.

asyncutils.iters.azip[T](i1: asyncutils._internal.types.SupportsIteration[T], /) collections.abc.AsyncGenerator[tuple[T]][source]
asyncutils.iters.azip(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
) collections.abc.AsyncGenerator[tuple[T, R]]
asyncutils.iters.azip(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
*,
strict: Literal[True],
) collections.abc.AsyncGenerator[tuple[T, R]]
asyncutils.iters.azip(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
) collections.abc.AsyncGenerator[tuple[T, R, V]]
asyncutils.iters.azip(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
strict: Literal[True],
) collections.abc.AsyncGenerator[tuple[T, R, V]]
asyncutils.iters.azip(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
) collections.abc.AsyncGenerator[tuple[T, R, V, U]]
asyncutils.iters.azip(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
strict: Literal[True],
) collections.abc.AsyncGenerator[tuple[T, R, V, U]]
asyncutils.iters.azip(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
) collections.abc.AsyncGenerator[tuple[T, R, V, U, S]]
asyncutils.iters.azip(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
*,
strict: Literal[True],
) collections.abc.AsyncGenerator[tuple[T, R, V, U, S]]
asyncutils.iters.azip(
*its: asyncutils._internal.types.SupportsIteration[T],
strict: bool = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]]

Async version of zip that is not a class.

asyncutils.iters.aziplongest[T](i1: asyncutils._internal.types.SupportsIteration[T], /) collections.abc.AsyncGenerator[tuple[T]][source]
asyncutils.iters.aziplongest(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
/,
*,
fillvalue: object = ...,
) collections.abc.AsyncGenerator[tuple[T, R]]
asyncutils.iters.aziplongest(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
/,
*,
fillvalue: object = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V]]
asyncutils.iters.aziplongest(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
/,
*,
fillvalue: object = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U]]
asyncutils.iters.aziplongest(
i1: asyncutils._internal.types.SupportsIteration[T],
i2: asyncutils._internal.types.SupportsIteration[R],
i3: asyncutils._internal.types.SupportsIteration[V],
i4: asyncutils._internal.types.SupportsIteration[U],
i5: asyncutils._internal.types.SupportsIteration[S],
/,
*,
fillvalue: object = ...,
) collections.abc.AsyncGenerator[tuple[T, R, V, U, S]]
asyncutils.iters.aziplongest(
*its: asyncutils._internal.types.SupportsIteration[T],
fillvalue: T = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis]]

Async version of itertools.zip_longest that is not a class. The first overload does not accept fillvalue, because passing it with only one iterable does not make sense.

async asyncutils.iters.basic_collect[T](it: asyncutils._internal.types.SupportsIteration[T], n: int) list[T][source]

Return a list of the first n items in the (async) iterable it, signalling no error if there are not enough items.

asyncutils.iters.batch[T](
it: asyncutils._internal.types.SupportsIteration[T],
n: int,
*,
item_timeout: float | None = ...,
strict: bool = ...,
) collections.abc.AsyncGenerator[list[T]][source]

More flexible but slightly slower implementation of batch2(), supporting timeouts waiting for each item, that raises ValueError instead of ItemsExhausted in the case of the length of the iterable being indivisible by the batch size.

asyncutils.iters.batch2[T](
it: asyncutils._internal.types.SupportsIteration[T],
n: int,
strict: Literal[True],
) collections.abc.AsyncGenerator[list[T]][source]
asyncutils.iters.batch2(
it: asyncutils._internal.types.SupportsIteration[T],
n: int | None,
strict: Literal[False] = ...,
) collections.abc.AsyncGenerator[list[T]]

Batch an (async) iterable into an async generator of lists. If strict=True is specified, raise ItemsExhausted on the last batch if it is discovered then that the iterable does not have enough items for a complete batch.

asyncutils.iters.batch_process[T, R](
items: asyncutils._internal.types.SupportsIteration[T],
size: int,
processor: collections.abc.Callable[[list[T]], collections.abc.Awaitable[R]],
) collections.abc.AsyncGenerator[R][source]

Apply processor to each batch of size size in items and yield the results awaited.

asyncutils.iters.buffer[T](
it: asyncutils._internal.types.SupportsIteration[T],
maxsize: int = ...,
*,
timeout_get: float | None = ...,
timeout_put: float | None = ...,
cooldown: float = ...,
loop: asyncio.AbstractEventLoop | None = ...,
) collections.abc.AsyncGenerator[T][source]
Buffer the given (async) iterable in an async generator, with an async queue as buffer of capacity maxsize (default unbounded) and optional timeouts for getting and putting items into the buffer.
cooldown specifies how long to wait after hitting a get timeout before trying again; whereas when a put timeout is reached, the async generator finishes.
asyncutils.iters.empty_agen() collections.abc.AsyncGenerator[Never][source]

Return an async generator that yields nothing. Due to async generator finalization issues, this is not a constant like yield_to_event_loop.

async asyncutils.iters.fmap[T, **P](
fs: asyncutils._internal.types.SupportsIteration[collections.abc.Callable[P, collections.abc.Awaitable[T]]],
/,
*a: P,
**k: P,
) list[T][source]

Return a list of the results of calling each async function in the first argument (an (async) iterable of functions), with the provided arguments.

asyncutils.iters.fmap_parallel[T, **P](
fs: asyncutils._internal.types.SupportsIteration[collections.abc.Callable[P, collections.abc.Awaitable[T]]],
/,
*a: P,
**k: P,
) collections.abc.AsyncGenerator[T][source]

Like fmap_sequential(), but starts background tasks for each call.

asyncutils.iters.fmap_sequential[T, **P](
fs: asyncutils._internal.types.SupportsIteration[collections.abc.Callable[P, collections.abc.Awaitable[T]]],
/,
*a: P,
**k: P,
) collections.abc.AsyncGenerator[T][source]

Like fmap(), but only call a function after the last completes and the result is gotten.

asyncutils.iters.iter_task[I: asyncutils._internal.types.SupportsIteration[object]](it: I, summaryf: collections.abc.Callable[[I], collections.abc.Awaitable[Any]] = ...) asyncio.Task[float][source]

Return a task that calls summaryf on the passed (async) iterable and returns the time taken to run it. By default, summaryf consumes it fully.

asyncutils.iters.map_on_map[T, R, V](
outer: collections.abc.Callable[[R], V],
inner: collections.abc.Callable[[T], asyncutils._internal.types.SupportsIteration[R]],
it: asyncutils._internal.types.SupportsIteration[T],
*,
inner_await: Literal[False] = ...,
outer_await: Literal[False] = ...,
) collections.abc.AsyncGenerator[tuple[V, Ellipsis]][source]
asyncutils.iters.map_on_map(
outer: collections.abc.Callable[[R], collections.abc.Awaitable[V]],
inner: collections.abc.Callable[[T], asyncutils._internal.types.SupportsIteration[R]],
it: asyncutils._internal.types.SupportsIteration[T],
*,
inner_await: Literal[False] = ...,
outer_await: Literal[True],
) collections.abc.AsyncGenerator[tuple[V, Ellipsis]]
asyncutils.iters.map_on_map(
outer: collections.abc.Callable[[R], V],
inner: collections.abc.Callable[[T], collections.abc.Awaitable[asyncutils._internal.types.SupportsIteration[R]]],
it: asyncutils._internal.types.SupportsIteration[T],
*,
inner_await: Literal[True],
outer_await: Literal[False] = ...,
) collections.abc.AsyncGenerator[tuple[V, Ellipsis]]
asyncutils.iters.map_on_map(
outer: collections.abc.Callable[[R], collections.abc.Awaitable[V]],
inner: collections.abc.Callable[[T], collections.abc.Awaitable[asyncutils._internal.types.SupportsIteration[R]]],
it: asyncutils._internal.types.SupportsIteration[T],
*,
inner_await: Literal[True],
outer_await: Literal[True],
) collections.abc.AsyncGenerator[tuple[V, Ellipsis]]

Apply a transformation on an (async) iterable on top of another.

asyncutils.iters.mat_vec_mul(
M: asyncutils._internal.types.SupportsIteration[asyncutils._internal.types.SupportsIteration[int]],
V: asyncutils._internal.types.SupportsIteration[int],
) collections.abc.AsyncGenerator[int][source]

Multiplication of a matrix M and a vector V. O(n^2).

asyncutils.iters.merge[T](
*I: asyncutils._internal.types.SupportsIteration[T],
reverse: bool = ...,
maxqsize: int = ...,
) collections.abc.AsyncGenerator[T][source]
Merge items from the (async) iterables into a single async generator, according to the order in which they come.
If reverse is True, the order is reversed, but the returned generator only starts when all items are available.
maxqsize (default context.MERGE_DEFAULT_MAX_QSIZE) controls the maximum number of items the consumer can fall behind
the producers before the producers cease to be advanced.

Caution

If maxqsize is smaller than the total number of items in the sources in reverse mode, a deadlock will occur.

asyncutils.iters.tee[T](it: asyncutils._internal.types.SupportsIteration[T], n: Literal[1]) tuple[collections.abc.AsyncGenerator[T]][source]
asyncutils.iters.tee(
it: asyncutils._internal.types.SupportsIteration[T],
n: Literal[2] = ...,
*,
maxqsize: int = ...,
put_exc: bool = ...,
loop: asyncio.AbstractEventLoop | None = ...,
) tuple[collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T]]
asyncutils.iters.tee(
it: asyncutils._internal.types.SupportsIteration[T],
n: Literal[3],
*,
maxqsize: int = ...,
put_exc: bool = ...,
loop: asyncio.AbstractEventLoop | None = ...,
) tuple[collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T]]
asyncutils.iters.tee(
it: asyncutils._internal.types.SupportsIteration[T],
n: Literal[4],
*,
maxqsize: int = ...,
put_exc: bool = ...,
loop: asyncio.AbstractEventLoop | None = ...,
) tuple[collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T]]
asyncutils.iters.tee(
it: asyncutils._internal.types.SupportsIteration[T],
n: Literal[5],
*,
maxqsize: int = ...,
put_exc: bool = ...,
loop: asyncio.AbstractEventLoop | None = ...,
) tuple[collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T]]
asyncutils.iters.tee(
it: asyncutils._internal.types.SupportsIteration[T],
n: Literal[6],
*,
maxqsize: int = ...,
put_exc: bool = ...,
loop: asyncio.AbstractEventLoop | None = ...,
) tuple[collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T], collections.abc.AsyncGenerator[T]]
asyncutils.iters.tee(
it: asyncutils._internal.types.SupportsIteration[T],
n: int,
*,
maxqsize: int = ...,
put_exc: bool = ...,
loop: asyncio.AbstractEventLoop | None = ...,
) tuple[collections.abc.AsyncGenerator[T], Ellipsis]
Create n independent async generators from a single (async) iterable it that yield the same items, caching items in a queue when needed.
A background task will be spawned to consume the iterable.
Unlike itertools.tee(), the returned iterators are plain async generators, and the flattening step with a linked list as specified in the
itertools docs is not done.
maxqsize (default context.TEE_DEFAULT_MAX_QSIZE) specifies how many unproduced items can be consumed from the source ahead of the
slowest consumer(s) before the background task and the faster consumers start blocking to wait for them. 0 or below indicates an unbounded queue.
If put_exc is True (default context.TEE_DEFAULT_PUT_EXC), an exception raised by the source iterable will be propagated as late
as possible; that is, only when the caller gets to that point. Slower consumers are not immediately affected.
Otherwise, the exception will be raised in the background task used to consume the iterable, and QueueShutDown will be propagated
to callers waiting on consumers.
async asyncutils.iters.to_list[T](it: asyncutils._internal.types.SupportsIteration[T], /) list[T][source]

Collect all items of an async iterable into a list. Faster than base.collect().

async asyncutils.iters.to_set[H: collections.abc.Hashable](it: asyncutils._internal.types.SupportsIteration[H], /, frozen: Literal[False] = ...) set[H][source]
async asyncutils.iters.to_set(it: asyncutils._internal.types.SupportsIteration[H], /, frozen: Literal[True]) frozenset[H]

Convert the output of to_list() into a set or frozenset depending on the frozen parameter (False by default).

async asyncutils.iters.to_tuple[T](it: asyncutils._internal.types.SupportsIteration[T], /) tuple[T, Ellipsis][source]

Convert the output of to_list() into a tuple.

async asyncutils.iters.vecs_eq[T](
u: asyncutils._internal.types.SupportsIteration[T],
v: asyncutils._internal.types.SupportsIteration[T],
cmpeq: collections.abc.Callable[[T, T], object] = ...,
*,
strict: bool = ...,
) bool[source]

Whether the vectors u and v are equal according to cmpeq called on each pair of items from iterating through them in parallel. If strict is False (default True), may return True even for differently-sized vectors.

asyncutils.iters.window[T](
it: asyncutils._internal.types.SupportsIteration[T],
size: int,
step: int = ...,
) collections.abc.AsyncGenerator[tuple[T, Ellipsis], tuple[int, int] | None][source]

Window an async iterable into an async generator of tuples of the specified size and step. You can send in a tuple (size, step) to change the behaviour of the iterator.