No project description provided
Project description
fluent-async
Overview
fluent-async is a Python library that enables fluent-style chaining of asynchronous methods and supports @async_property and @async_cached_property without requiring explicit await statements at each step. It simplifies working with asynchronous classes and methods by eliminating deep nesting of await expressions.
In other words:
async def example():
await (await (await (await StyleBuilder().gray()).bold()).underline()).as_posix_style
Becomes:
async def example():
await StyleBuilder().gray().bold().underline().as_posix_style
Features
- Fluent API for Async Methods: Chain async methods seamlessly without manually awaiting each step.
- Automatic Handling of Async Properties: Access
@async_propertyattributes without explicitawait. - Enhanced Debugging: Provides clear execution traces in
__repr__for better debugging.
Installation
pip install fluent-async
poetry add fluent-async
Usage
Basic Example
import asyncio
from async_property import async_property
from fluent_async import fluent
from typing import cast, Callable, Self
class Arithmetic:
def __init__(self, value: int):
self.value = value
@fluent
async def increment(self) -> Self:
self.value += 1
return self
increment = cast(Callable[..., Self], increment)
@fluent
async def double(self) -> Self:
self.value *= 2
return self
double = cast(Callable[..., Self], double)
@async_property
async def async_value(self) -> int:
return self.value
async def main():
result = await Arithmetic(1).increment().double().async_value
print(result) # Expected output: (1+1) * 2 = 4
asyncio.run(main())
How It Works
@fluent Decorator
- Wraps an async method to allow fluent chaining.
- Ensures returned values are wrapped in a
Fluentinstance.
Fluent Class
- Implements
__getattr__to support accessing async properties. - Implements
__call__to handle method calls. - Overrides
__await__to return awaited values correctly.
License
MIT License -- LICENSE
Contributing
Contributions are welcome! Please submit issues or pull requests to improve the project.
Project details
Release history Release notifications | RSS feed
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 fluent_async-0.1.0.tar.gz.
File metadata
- Download URL: fluent_async-0.1.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.13.1 Linux/6.8.0-1020-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ab3ad536530933335c31ab0ab30a41ec7c8063b0addefbea607082c25314fa0
|
|
| MD5 |
07be2d86dabba8f8b78c2ab944077ed5
|
|
| BLAKE2b-256 |
ac2d9e5e49651b3718b86b0f602a6732af5280fa6c072beed79ace187b6aba6a
|
File details
Details for the file fluent_async-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fluent_async-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.13.1 Linux/6.8.0-1020-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d12c35ec984f74abca3baf80ac817a56d86d43469047afcf23fd6aef93c6ccb
|
|
| MD5 |
38a17f428b58761ce4f480ebac76726d
|
|
| BLAKE2b-256 |
6a7231858b352d2ff5bec23f3fc451b01a07dfafaaa08c505389518ffd22533c
|