Metadata-Version: 2.4
Name: awaitable-tools
Version: 0.0.1
Summary: Tools to bridge coroutines and non-coroutine awaitables in Python
Author-email: AlanBogarin <bogarin01alan@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Alan Bogarin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/AlanBogarin/awaitable-tools
Project-URL: Bug Tracker, https://github.com/AlanBogarin/awaitable-tools/issues
Keywords: async,python,awaitable,tools,AlanBogarin
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typing-extensions>=4.12.2
Dynamic: license-file

# 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.

```python
async def coroutine():
    pass
```

## Awaitable

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

```python
class Awaitable:
    def __await__(self):
        yield
```

## Installation

```bash
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

```python
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](https://mleue.com/posts/yield-to-async-await/)
