Skip to main content

Collection of utilities to write safe asyncio code.

Project description

asynchrony

Python asyncio framework for writing safe and fast concurrent code.

Features:

  • Type annotated and type safe
  • Makes it easy to work with cancellation, errors, and scheduling.
  • Well tested and well documented.
  • Zero dependency.
  • Based on real world experience and pain.

Installation and usage

python3 -m pip install asynchrony

A simple example of starting concurrent tasks for all URLs (maximum 100 tasks at the same time) and waiting for all of them to finish:

from asynchrony import Tasks

async def download_page(url: str) -> bytes:
    ...

urls = [...]
tasks = Tasks[bytes](timeout=10, max_concurrency=100)
tasks.map(urls, download_page)

try:
    pages = await tasks
except Exception:
    failed = sum(t.failed for t in tasks)
    print(f'{failed} tasks failed')
    cancelled = sum(t.cancelled for t in tasks)
    print(f'{cancelled} tasks cancelled')
else:
    print(f'finished {len(tasks)} tasks')

See tutorial for runnable usage examples.

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

asynchrony-0.2.0.tar.gz (11.9 kB view hashes)

Uploaded Source

Built Distribution

asynchrony-0.2.0-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page