Skip to main content

Tools to bridge coroutines and non-coroutine awaitables in Python

Project description

Awaitable Tools

This package provides utilities for working with awaitable objects in Python.

Coroutines vs Awaitables

Coroutines

Objects returned from the function declared with the async def syntax. It is the standard way to create asynchronous programs.

async def coroutine():
    pass

Awaitable

Any object that implements __await__() for use in an await expression.

class Awaitable:
    def __await__(self):
        yield

Installation

pip install awaitable-tools

While most users work with coroutines, some advanced scenarios (like protocol implementations or framework development) require working directly with awaitables. This package fills that gap.

Technical Background

The Awaitable Protocol

An object is awaitable if its __await__() method returns an generator that:

  1. Only yields None (any other value raises RuntimeError)
  2. Final value uses return (not yield)
  3. May use yield from with other compliant generators
class ValidAwaitable:
    def __await__(self):
        yield None  # Valid suspension
        # coroutine also implements __await__()
        yield from asyncio.sleep(1).__await__()
        return True

class InvalidAwaitable:
    def __await__(self):
        # Only valid if marked as @types.coroutine
        yield from asyncio.sleep(1)  # TypeError!
        yield "foo"  # RuntimeError!

About async/await

April 18, 2020, From yield to async/await

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

awaitable_tools-0.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

awaitable_tools-0.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file awaitable_tools-0.0.1.tar.gz.

File metadata

  • Download URL: awaitable_tools-0.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for awaitable_tools-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8a2f5d4031b11741bd9acaba8f6bdc2b4b420abe70ecab6c22901faa70d19c44
MD5 7afa9c76a12f51bc5c515be65ef7e197
BLAKE2b-256 337e7f72f4498636ff672022850d4ae9ef9b3ecf319c96f174e7c7751a76ea2a

See more details on using hashes here.

Provenance

The following attestation bundles were made for awaitable_tools-0.0.1.tar.gz:

Publisher: python-publish.yml on AlanBogarin/awaitable-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file awaitable_tools-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for awaitable_tools-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9382020fdbc680b74cde8aafb1edfc2b172b46c874d9dd7afc1450582028802c
MD5 84fdf9b67c370e25ef2d963711128184
BLAKE2b-256 5e441922ba8045a17ab05a9bde4e02d78c4e8ea8eb09be28cceef05b6a091b21

See more details on using hashes here.

Provenance

The following attestation bundles were made for awaitable_tools-0.0.1-py3-none-any.whl:

Publisher: python-publish.yml on AlanBogarin/awaitable-tools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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