py-memoize
Caching library for asynchronous Python applications (both based on asyncio and Tornado) that handles dogpiling properly and provides a configurable & extensible API.
What it is and what it does
py-memoize is a caching library designed specifically for asynchronous Python code—both asyncio and Tornado—that solves the cache stampede (dog-piling) problem where multiple concurrent tasks simultaneously miss the cache and flood the underlying resource. It wraps expensive async functions with a decorator to cache and reuse their results, and includes built-in protections against concurrent cache misses.
The library is highly configurable: you can tune cache timeouts, key generation strategies, storage backends, eviction policies (least-recently-updated by default), and value post-processing (including optional deep-copy). It supports background cache refreshing with separate update and expiration delays, allowing stale values to be refreshed asynchronously without observable latency. All components are extensible, so you can plug in custom storage, key extraction, or eviction logic.
Use it for:
- Memoize expensive async API calls or database queries in asyncio services to reduce latency and backend load
- Prevent cache stampede in high-concurrency async applications where multiple tasks would otherwise recompute the same result simultaneously
- Cache results with tunable background refresh to serve stale data while updating in the background, avoiding request latency spikes
- Implement custom cache storage (e.g., Redis, Memcached) by extending the provided storage and serialization interfaces
- Decorate Tornado async handlers to cache computed responses across concurrent requests
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Caching library for async Python applications that prevents cache stampede (dog-piling) and provides a configurable, extensible API for memoizing expensive async function calls.
Yes, if you are building async Python services and need protection against cache stampede. The library is stable and has no known vulnerabilities, but note that maintenance is dormant (676 days since last release)—verify compatibility with your target Python version and async framework before adopting. For simple in-memory caching in active projects, consider whether the dormancy risk is acceptable.
Install
py-memoize on PyPI
pip
pip install py-memoizeuv
uv add py-memoizepoetry
poetry add py-memoizeInstalling py-memoize
Before you install
Installs with no runtime dependencies. Maintenance is dormant—last release was 676 days ago (2024-10-07), though the repository remains active with 74 stars and no archived status.
License in practice
Licensed under Apache License 2.0 (permissive), allowing commercial and private use with minimal restrictions.
Quickstart
pip install py-memoize
import asyncio
from memoize.wrapper import memoize
@memoize()
async def expensive_computation():
return 'result'
asyncio.run(expensive_computation())
Verify before relying
- Whether the dormant maintenance status (676 days since last release) affects compatibility with current Python async ecosystems
- Real-world performance impact of deep-copy post-processing on large cached objects
- Whether ujson extra dependency improves JSON serialization performance meaningfully
Package facts
| License | Apache License 2.0 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 676 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 182,579/month — #10,093 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: py_memoize-3.1.1-py3-none-any.whl
Keywords: python, cache, tornado, asyncio
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
cachetools-asyncProvides async-aware memoization decorators for…
permissive · top 15,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
cacheoutCacheout provides in-memory caching with…
permissive · top 5,000 on PyPI
django-memoizeCaches function and method results in Django…
permissive · top 15,000 on PyPI
django-cache-memoizeA decorator that caches function results using…
copyleft · top 15,000 on PyPI
vercel-cacheProvides runtime cache helpers for Vercel…
permissive · top 5,000 on PyPI
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
requests-cacheAdds persistent HTTP caching to the requests…
permissive · top 5,000 on PyPI
aiodataloaderBatches and caches concurrent data requests in…
permissive · top 5,000 on PyPI