AsyncZip
AsyncZip is a simple zip like function working with asynchronous iterables. It look, in many aspects, like asyncio.wait.
Usage
Given n asynchronous iterables, AsyncZip(*aiterables) gives a new asynchronous iterable iterating over all of them. Like asyncio.wait, it’s possible to wait for any iterable to yield something using the option FIRST_COMPLETED, or to wait for all of them using the option ALL_COMPLETED.
class AsyncZip
def __init__(self, *asynchronous_iterables, loop=None, yield_when=FIRST_COMPLETED):
asynchronous_iterables: A collection of asynchronous iterables
loop: Optional named parameter, to give an specific event loop
yield_when: Like return_when from asyncio.wait, FIRST_COMPLETED or ALL_COMPLETED.
FIRST_COMPLETED, ALL_COMPLETED
The two values yield_when can take, FIRST_COMPLETED and ALL_COMPLETED tell, like for asyncio.wait, when AsyncZip should yield. Defaults to FIRST_COMPLETED.
FIRST_COMPLETED
Like select, where AsyncZip yields each time any iterable yields, as soon as possible.
ALL_COMPLETED
It’s the classical zip mode, where AsyncZip waits for a value for each iterator before yielding them all in a single loop.
Example usage
import asyncio
from asynczip import AsyncZip
class DummyAsyncIterable:
def __init__(self, items):
self.items = items
async def __aiter__(self):
return self
async def __anext__(self):
try:
return self.items.pop(0)
except IndexError:
raise StopAsyncIteration
async def test():
async for items in AsyncZip(DummyAsyncIterable(list("foo")),
DummyAsyncIterable(list("bar"))):
print(items)
asyncio.get_event_loop().run_until_complete(test())
Gives:
[<Task finished coro=<DummyAsyncIterable.__anext__() done, defined at test.py:11> result='f'>,<Task finished coro=<DummyAsyncIterable.__anext__() done, defined at test.py:11> result='b'>]
[<Task finished coro=<DummyAsyncIterable.__anext__() done, defined at test.py:11> result='o'>, <Task finished coro=<DummyAsyncIterable.__anext__() done, defined at test.py:11> result='a'>]
[<Task finished coro=<DummyAsyncIterable.__anext__() done, defined at test.py:11> result='o'>, <Task finished coro=<DummyAsyncIterable.__anext__() done, defined at test.py:11> result='r'>]
Metadata
Release files for asynczip 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asynczip-1.0.7.tar.gz | 3.4 kB | Without provenance | Details for asynczip-1.0.7.tar.gz |
Release files / asynczip-1.0.7.tar.gz
| Download URL | asynczip-1.0.7.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eea2b2375256dce6da2457d79212deb1c7861146238853be6c5c15aa5be8ebfc
|
|
BLAKE2b-256 checksum How to use checksums |
867f47f404eae0286669a02bd929c220bca6fadf63d38672c935075885b2026a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for asynczip 1.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.