Skip to main content

aiomemoize CircleCI Test Coverage

Memoize asyncio Python calls. Invalidation is manual/explicit for each set of arguments, although exceptions raised are not cached. This can be used for coroutines, and functions that return a promise.

Installation

pip install aiomemoize

Usage

For a coroutine whose arguments are hashable, you can create a memoized version by passing it to memoize. This returns a tuple of the memoized function, and a function to invalidate the cache on a per-item basis.

For example, the below

import asyncio
from aiomemoize import memoize

async def main():
    memoized, invalidate = memoize(coro)
    results = await asyncio.gather(*[
        memoized('a'),
        memoized('a'),
        memoized('b'),
    ])
    print(results)

    invalidate('a')
    results = await asyncio.gather(*[
        memoized('a'),
        memoized('a'),
        memoized('b'),
    ])
    print(results)

    await memoized('a')

async def coro(value):
    print('Inside coro', value)
    await asyncio.sleep(1)
    return value

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()

will output

Inside coro a
Inside coro b
['a', 'a', 'b']
Inside coro a
['a', 'a', 'b']

Metadata

Release files for aiomemoize 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiomemoize 0.0.3
File Size Uploaded
aiomemoize-0.0.3.tar.gz 2.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aiomemoize 0.0.3
File Interpreter ABI Platform
aiomemoize-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 5.0 kB

Release files / aiomemoize-0.0.3.tar.gz

Download URL aiomemoize-0.0.3.tar.gz
Size 2.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d938faaeb7569bdb23d22636d5a3b9c0f23e70eee31c0636f94ba892a5adab7f
BLAKE2b-256 checksum
How to use checksums
bac063535cf9caa105841274e5aa93f1ad630786343e63adcde05d47a258c502
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

Release files / aiomemoize-0.0.3-py3-none-any.whl

Download URL aiomemoize-0.0.3-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f43482f396765038af49b33d4a4915b24e403049fc777883ad25cb3e5ac38b5c
BLAKE2b-256 checksum
How to use checksums
a9f24de59365566e454aa880db8d2a6369349f8fa726d1d2c472a1309eb6ba70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page