truely async properties
Project description
Install
pip3 install aioproperty
Documentation
You can find documentation here
Description
aioproperty presents async properties with both async getter and setter in one place.
Example:
from aioproperty import aioproperty
import asyncio
class SomeClass:
@aioproperty
async def hello(self, value):
await asyncio.sleep(1)
return value
some_obj = SomeClass()
some_obj.hello = 'hello'
async def run():
print(await some_obj.hello)
asyncio.run(run())
aioproperty is not a property in a classic meaning, it keeps values inside asincio tasks. Once you set a new value, it is scheduled in a task. If any task is running now, it will wait untill it is finished. When you get value, you actually get a current task, and you can await it to get a value. More of that: you can use math without awaiting like that:
other = some_obj.hello + ' byby'
print(await other)
We also introduce chaining:
class SomeClass:
@aioproperty
async def hello(self, value):
await asyncio.sleep(1)
return value
@hello.chain
async def some_more(self, value):
push_value(value)
And with our special MetaClass you can effectively inject some new chains in inherited classes:
class Parent(metaclass=AiopropMeta):
@aioproperty
async def hello(self, value):
await asyncio.sleep(1)
return value
@hello.chain
async def some_more(self, value):
push_value(value)
class Child(Parent):
@inject(Parent.hello, priotity=100)
async def injected_method(self, value):
print('hello from injection')
Read more in our docs
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
File details
Details for the file aioproperty-0.2.2.tar.gz.
File metadata
- Download URL: aioproperty-0.2.2.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84a48e0051229a44d16d9af270a3d471211983799aca5c4547b6b6ee1716fc6c
|
|
| MD5 |
88c8d286d1977249275fa98ed802625a
|
|
| BLAKE2b-256 |
734071504942b577e844926b9643cc9ce26abb28748251e0e933a8ba40b01fe4
|