{"id":13737541,"url":"https://github.com/ryananguiano/async_property","last_synced_at":"2025-05-08T14:31:59.318Z","repository":{"id":37432458,"uuid":"180741389","full_name":"ryananguiano/async_property","owner":"ryananguiano","description":"Python decorator for async properties.","archived":false,"fork":false,"pushed_at":"2023-09-05T05:31:37.000Z","size":114,"stargazers_count":91,"open_issues_count":9,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T22:41:41.166Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryananguiano.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-04-11T07:47:00.000Z","updated_at":"2025-04-04T22:33:10.000Z","dependencies_parsed_at":"2024-01-05T21:20:14.436Z","dependency_job_id":"7d4e6b5a-bdb4-415a-8762-c8b467af347d","html_url":"https://github.com/ryananguiano/async_property","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.032258064516129004","last_synced_commit":"6326fe18ac4bf775e5424cf241a06014e38525f1"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryananguiano%2Fasync_property","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryananguiano%2Fasync_property/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryananguiano%2Fasync_property/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryananguiano%2Fasync_property/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryananguiano","download_url":"https://codeload.github.com/ryananguiano/async_property/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253085563,"owners_count":21851653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:01:52.693Z","updated_at":"2025-05-08T14:31:59.289Z","avatar_url":"https://github.com/ryananguiano.png","language":"Python","funding_links":[],"categories":["Python","Misc"],"sub_categories":[],"readme":"==============\nasync_property\n==============\n\n\n.. image:: https://img.shields.io/pypi/v/async_property.svg\n    :target: https://pypi.org/project/async-property/\n\n.. image:: https://anaconda.org/ryananguiano/async-property/badges/version.svg\n    :target: https://anaconda.org/ryananguiano/async-property\n\n.. image:: https://app.travis-ci.com/ryananguiano/async_property.svg?branch=master\n    :target: https://app.travis-ci.com/github/ryananguiano/async_property\n\n.. image:: https://readthedocs.org/projects/async-property/badge/?version=latest\n    :target: https://async-property.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\n.. image:: https://pyup.io/repos/github/ryananguiano/async_property/shield.svg\n    :target: https://pyup.io/repos/github/ryananguiano/async_property/\n    :alt: Updates\n\n\nPython decorator for async properties.\n\n* Python: 3.7+\n* Free software: MIT license\n* Documentation: https://async-property.readthedocs.io\n* Package: https://pypi.org/project/async-property\n* Source code: https://github.com/ryananguiano/async_property\n\nInstall\n-------\n\nTo install async_property, run this command in your terminal:\n\n.. code-block:: console\n\n    $ pip install async-property\n\n\nOr if you have pipenv:\n\n.. code-block:: console\n\n    $ pipenv install async-property\n\n\nOr alternatively with conda:\n\n.. code-block:: console\n\n    $ conda install -c ryananguiano async-property\n\n\nUsage\n-----\n\nYou can use ``@async_property`` just as you would with ``@property``, but on an async function.\n\n.. code-block:: python\n\n    class Foo:\n        @async_property\n        async def remote_value(self):\n            return await get_remote_value()\n\nThe property ``remote_value`` now returns an awaitable coroutine.\n\n.. code-block:: python\n\n    instance = Foo()\n    await instance.remote_value\n\n\nCached Properties\n~~~~~~~~~~~~~~~~~\n\n``@async_cached_property`` will call the function only once. Subsequent awaits to the property will return a cached value.\n\n.. code-block:: python\n\n    class Foo:\n        @async_cached_property\n        async def value(self):\n            print('loading value')\n            return 123\n\n    \u003e\u003e\u003e instance = Foo()\n    \u003e\u003e\u003e instance.value\n    \u003cAwaitableOnly \"Foo.value\"\u003e\n\n    \u003e\u003e\u003e await instance.value\n    loading value\n    123\n    \u003e\u003e\u003e await instance.value\n    123\n    \u003e\u003e\u003e instance.value\n    123\n\n    \u003e\u003e\u003e instance.value = 'abc'\n    \u003e\u003e\u003e instance.value\n    'abc'\n    \u003e\u003e\u003e await instance.value\n    'abc'\n\n    \u003e\u003e\u003e del instance.value\n    \u003e\u003e\u003e await instance.value\n    loading value\n    123\n\n\nAwaitLoader\n~~~~~~~~~~~\n\nIf 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.\n\n.. code-block:: python\n\n\n    class Foo(AwaitLoader):\n        async def load(self):\n            print('load called')\n\n        @async_cached_property\n        async def db_lookup(self):\n            return 'success'\n\n        @async_cached_property\n        async def api_call(self):\n            print('calling api')\n            return 'works every time'\n\n    \u003e\u003e\u003e instance = await Foo()\n    load called\n    calling api\n    \u003e\u003e\u003e instance.db_lookup\n    'success'\n    \u003e\u003e\u003e instance.api_call\n    'works every time'\n\nFeatures\n--------\n\n* Both regular and cached property.\n* Cached properties can be accessed multiple times without repeating function call.\n* Uses asyncio.Lock to ensure cached functions are called only once.\n* Full test coverage with py.test\n\n\nCredits\n-------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n\n\nThe ObjectProxy_ class was taken from wrapt_ library by Graham Dumpleton.\n\n.. _ObjectProxy: https://github.com/GrahamDumpleton/wrapt/blob/master/src/wrapt/wrappers.py\n.. _wrapt: https://github.com/GrahamDumpleton/wrapt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryananguiano%2Fasync_property","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryananguiano%2Fasync_property","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryananguiano%2Fasync_property/lists"}