---
title: "async-property | pypx"
description: "Python decorator for async properties."
canonical_url: "https://pypx.app/packages/async-property"
meta:
  "og:description": "Python decorator for async properties."
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_async-property%2Cversion_0.2.2%2Csummary_Python%2Bdecorator%2Bfor%2Basync%2Bproperties.%2Clicense_MIT%2BLicense%2Cp_Ii9wYWNrYWdlcy9hc3luYy1wcm9wZXJ0eSI%2Cs_XZFdl1mN2Vol7cWx.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "async-property 0.2.2"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_async-property%2Cversion_0.2.2%2Csummary_Python%2Bdecorator%2Bfor%2Basync%2Bproperties.%2Clicense_MIT%2BLicense%2Cp_Ii9wYWNrYWdlcy9hc3luYy1wcm9wZXJ0eSI%2Cs_XZFdl1mN2Vol7cWx.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **async-property**

v0.2.2

Python decorator for async properties.

9 KBpy2.py3-none-anyMIT License Likely Unmaintained

[** Diff **](https://pypx.app/packages/async-property/diff)

`$ uv add async-property`

==============

# async\_property

![Documentation Status](https://readthedocs.org/projects/async-property/badge/?version=latest) ![Updates](https://pyup.io/repos/github/ryananguiano/async_property/shield.svg)

Python decorator for async properties.

- Python: 3.7+
- Free software: MIT license
- Documentation: https://async-property.readthedocs.io
- Package: https://pypi.org/project/async-property
- Source code: https://github.com/ryananguiano/async\_property

## Install

To install async\_property, run this command in your terminal:

```console
$ pip install async-property
```

Or if you have pipenv:

```console
$ pipenv install async-property
```

## Usage

You can use @async\_property just as you would with @property, but on an async function.

```python
class Foo:
    @async_property
    async def remote_value(self):
        return await get_remote_value()
```

The property remote\_value now returns an awaitable coroutine.

```python
instance = Foo()
await instance.remote_value
```

### Cached Properties

@async\_cached\_property will call the function only once. Subsequent awaits to the property will return a cached value.

```python
class Foo:
    @async_cached_property
    async def value(self):
        print('loading value')
        return 123

>>> instance = Foo()
>>> instance.value
<AwaitableOnly "Foo.value">

>>> await instance.value
loading value
123
>>> await instance.value
123
>>> instance.value
123

>>> instance.value = 'abc'
>>> instance.value
'abc'
>>> await instance.value
'abc'

>>> del instance.value
>>> await instance.value
loading value
123
```

### AwaitLoader

If you have an object with multiple cached properties, you can subclass AwaitLoader. This will make your class instances awaitable and will load all @async\_cached\_property fields concurrently. AwaitLoader will call await instance.load(), if it exists, before loading properties.

```python
class Foo(AwaitLoader):
    async def load(self):
        print('load called')

    @async_cached_property
    async def db_lookup(self):
        return 'success'

    @async_cached_property
    async def api_call(self):
        print('calling api')
        return 'works every time'

>>> instance = await Foo()
load called
calling api
>>> instance.db_lookup
'success'
>>> instance.api_call
'works every time'
```

## Features

- Both regular and cached property.
- Cached properties can be accessed multiple times without repeating function call.
- Uses asyncio.Lock to ensure cached functions are called only once.
- Full test coverage with py.test

## Credits

This package was created with Cookiecutter\_ and the `audreyr/cookiecutter-pypackage`\_ project template.

The ObjectProxy\_ class was taken from wrapt\_ library by Graham Dumpleton.

=======

# History

## 0.2.2 (2023-07-03)

- Add Python 3.11 support and drop Python 3.6.

## 0.2.1 (2019-04-13)

- Update docs and readme

## 0.2.0 (2019-04-12)

- Use instance state to hold cache and locks

## 0.1.4 (2019-04-12)

- Fix inheritance issues on AwaitLoader

## 0.1.3 (2019-04-12)

- Cleanup code

## 0.1.2 (2019-04-12)

- Fix asyncio.Lock issues

## 0.1.1 (2019-04-11)

- Complete test coverage and update readme

## 0.1.0 (2019-04-11)

- First release on PyPI.

## **Details **

<dl>

<dt>Version</dt>
<dd>0.2.2</dd>

<dt>License</dt>
<dd>MIT License</dd>

<dt>Maintainer</dt>
<dd>Ryan Anguiano</dd></dl>

## **Links**

- [Homepage](https://github.com/ryananguiano/async_property)
- [View on PyPI](https://pypi.org/project/async-property/)

## **Maintainers **

- Ryan Anguiano · [ryan.anguiano@gmail.com](mailto:ryan.anguiano@gmail.com)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/async-property#webpage","@type":"WebPage","description":"Python decorator for async properties.","name":"async-property","url":"https://pypx.app/packages/async-property","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/async-property"]}]},{"@id":"https://pypx.app/packages/async-property#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"Python decorator for async properties.","license":"MIT License","name":"async-property","softwareVersion":"0.2.2"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
