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.
Metadata
Release files for fluent-async 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fluent_async-0.1.2.tar.gz | 3.6 kB | Without provenance | Details for fluent_async-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fluent_async-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for fluent_async-0.1.2-py3-none-any.whl |
Total release size: 7.9 kB
Release files / fluent_async-0.1.2.tar.gz
| Download URL | fluent_async-0.1.2.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
efb3b85a79342152de739ced3676253a8cc64df24a7c17ad8654c9ff73756cbb
|
|
BLAKE2b-256 checksum How to use checksums |
30cfe1019069d2f2b03fcea5d70d0366963944a5aa80b01a9d0062493a0da41a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.1 Linux/6.8.0-1020-azure
|
Release files / fluent_async-0.1.2-py3-none-any.whl
| Download URL | fluent_async-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dea22a1d5fe7814d349105339e9673548b54c31cf9b4907d8d6e5b9559d7d607
|
|
BLAKE2b-256 checksum How to use checksums |
49568539e8baa081c13f5e60a4820bb330f3e631952e2594d0bebcd003a8ec62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.1 Linux/6.8.0-1020-azure
|
Security for fluent-async 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.