Install & Compatibility
Where this runs
tested against v0.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.222s · 17.9MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.192s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
async_property
✓ from async_property import async_property
async_cached_property
✓ from async_property import async_cached_property
AwaitLoader
✓ from async_property import AwaitLoader
✗ from async_property.await_loader import AwaitLoader
AwaitLoader is directly exposed from the top-level package for convenience in recent versions.
This quickstart demonstrates the basic usage of `@async_property` for a standard awaitable property, `@async_cached_property` for a property that computes its value only once, and `AwaitLoader` for classes with multiple concurrently loaded cached properties. Remember to `await` the property access.
import asyncio
from async_property import async_property, async_cached_property, AwaitLoader
async def fetch_data(delay: float, value: str):
await asyncio.sleep(delay)
return value
class MyClass:
def __init__(self, initial_value: str):
self._initial_value = initial_value
@async_property
async def regular_async_prop(self) -> str:
print("Fetching regular_async_prop...")
return await fetch_data(0.1, f"Regular: {self._initial_value}")
@async_cached_property
async def cached_async_prop(self) -> str:
print("Fetching cached_async_prop (only once)...")
return await fetch_data(0.2, f"Cached: {self._initial_value}")
class MyAwaitableClass(AwaitLoader):
def __init__(self, initial_value: str):
self._initial_value = initial_value
async def load(self):
print("AwaitLoader load method called.")
@async_cached_property
async def await_loader_prop1(self) -> str:
print("Fetching await_loader_prop1...")
return await fetch_data(0.05, f"AwaitLoader Prop1: {self._initial_value}")
@async_cached_property
async def await_loader_prop2(self) -> str:
print("Fetching await_loader_prop2...")
return await fetch_data(0.03, f"AwaitLoader Prop2: {self._initial_value}")
async def main():
instance = MyClass("test")
# Accessing regular async property
print(f"-> {await instance.regular_async_prop}")
print(f"-> {await instance.regular_async_prop}") # Fetches again
# Accessing cached async property
print(f"-> {await instance.cached_async_prop}")
print(f"-> {await instance.cached_async_prop}") # Returns cached value
# Using AwaitLoader
awaitable_instance = await MyAwaitableClass("loader_data")
print(f"-> {awaitable_instance.await_loader_prop1}")
print(f"-> {awaitable_instance.await_loader_prop2}")
if __name__ == "__main__":
asyncio.run(main())
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'async_property'
The 'async_property' module is not installed in the Python environment.
fixInstall the module using pip: 'pip install async-property'.
AttributeError: module 'async_property' has no attribute 'async_property'
Incorrect import statement; the correct attribute is 'async_property' from the 'async_property' module.
fixUse the correct import: 'from async_property import async_property'.
TypeError: 'async_property' object is not callable
Attempting to call an 'async_property' decorated method directly instead of awaiting it.
fixAccess the property with 'await' syntax: 'await instance.property_name'.
SyntaxError: can't assign to await expression
Attempting to assign a value to an 'async_property' decorated property, which does not support assignment.
fixUse a regular async method with explicit getter and setter methods instead of 'async_property'.
TypeError: object 'coroutine'/'_CachedAsyncProperty'/'_AsyncProperty' is not awaitable
You are trying to use the result of an `@async_property` or `@async_cached_property` directly without awaiting it, or you have applied the decorator to a non-async function.
fixEnsure the decorated method is `async def` and always `await` the property when accessing its value. Example: `await instance.my_async_prop`.
Upgrade
Version history
0.2.2latest on PyPI · released Jul 3, 2023
Audit
Dependencies
wraptrequiredUsed for ObjectProxy functionality, which is part of the decorator's implementation.