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)
Chains works like a reducer. It applies each function to a new value iteratively. It can return value or return nothing.
If nothing is return, the value will be kept asis. Any chained function is inserted by default in the end of chain, but
you can control it with a priority parameter, or with is_first parameter. If is_first is True, it will be inserted in the
beginning of the chain.
You can also use inheritance and modify inhereted properties with our special decorator inject:
class Parent:
@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, priority=100)
async def injected_method(self, value):
print('hello from injection')
#another form of injection using name of a property
@inject('hello')
async def injected_method_2(self, value):
print('hello from injection 2')
Read more in our docs
Metadata
Release files for aioproperty 0.3.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 | |
|---|---|---|---|---|
| aioproperty-0.3.2.tar.gz | 12.0 kB | Without provenance | Details |
Release files / aioproperty-0.3.2.tar.gz
| Download URL | aioproperty-0.3.2.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14700e5dfa3e92cc6985742e9fac71b77122b2b885689c9ca7eee4ff30d8c5ea
|
|
BLAKE2b-256 checksum How to use checksums |
3725b1d32701f8368f2c02502048bc0e55d231cc6f97ff4f6b9260715faee9b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.5.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1
|
Security for aioproperty 0.3.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.