No project description provided
Project description
Agent: Async generators for humans
agent provides a simple decorator to create python 3.5 asynchronous iterators via yields
Examples
Make people wait for things for no reason!
import agent
import asyncio
@agent.gen # Shorthand decorator
def wait_for_me():
yield 'Like '
yield from asyncio.sleep(1)
yield 'the line '
yield from asyncio.sleep(10)
yield 'at '
yield from asyncio.sleep(100)
yield 'the DMV'
async for part in wait_for_me():
print(part)
Paginate websites in an easy asynchronous manner.
import agent
import aiohttp
@agent.async_generator
def gen():
page, url = 0, 'http://example.com/paginated/endpoint'
while True:
resp = yield from aiohttp.request('GET', url, params={'page': page})
resp_json = (yield from resp.json())['data']
if not resp_json:
break
for blob in resp_json['data']:
yield blob
page += 1
# Later on....
async for blob in gen():
# Do work
The possibilities are endless!
For additional, crazier, examples take a look in the tests directory.
Get it
$ pip install -U agent
Caveats
yield from syntax must be used as yield in an async def block is a syntax error.
async def generator():
yield 1 # Syntax Error :(
asyncio.Futures can not be yielded directly, they must be wrapped by agent.Result.
License
MIT licensed. See the bundled LICENSE file for more details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent-0.1.3.tar.gz.
File metadata
- Download URL: agent-0.1.3.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.16 Darwin/22.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a010882b158376b64d24f4574afbfab4a5bf3ec5c99ca9abc11bf5459ad186f4
|
|
| MD5 |
241a9941274614056196d4f599a12c58
|
|
| BLAKE2b-256 |
5b0a4b9b1de3e1c551d2cce73ff1fcd4c9d4b6c324b4d7b44f3918f0fcdf7a86
|
File details
Details for the file agent-0.1.3-py3-none-any.whl.
File metadata
- Download URL: agent-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.9.16 Darwin/22.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2ee6b770fd72e35ff0c1a9d9c2002b77ef30138f62a2a3f4291492ff85d807d
|
|
| MD5 |
94f1548cbb2d80896c3aed8756cb3ead
|
|
| BLAKE2b-256 |
1308d9a4ea4eb58605465f1c5c3e502added359a86fa424a7f66901dd87bd096
|