{"id":21722,"library":"py-memoize","title":"py-memoize","description":"A caching library for asynchronous Python applications (asyncio-based) that handles dogpiling properly and provides a configurable & extensible API. Current version 3.1.1. Release cadence is irregular.","status":"active","version":"3.1.1","language":"python","source_language":"en","source_url":"https://github.com/DreamLab/memoize","tags":["cache","async","asyncio","memoization","dogpiling"],"install":[{"cmd":"pip install py-memoize","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Correct import path for the main class.","wrong":"","symbol":"Memoizer","correct":"from memoize import Memoizer"},{"note":"Correct import for the expiring cache backend.","wrong":"","symbol":"ExpiringCache","correct":"from memoize.cache import ExpiringCache"},{"note":"Default in-memory cache backend.","wrong":"","symbol":"InMemoryCache","correct":"from memoize.cache import InMemoryCache"}],"quickstart":{"code":"import asyncio\nfrom memoize import Memoizer\nfrom memoize.cache import InMemoryCache, ExpiringCache\n\nmemoizer = Memoizer(cache=InMemoryCache())\n\n@memoizer.cache(ttl=5)\nasync def fetch_data(key: str) -> str:\n    await asyncio.sleep(1)\n    return f\"data-{key}\"\n\nasync def main():\n    result = await fetch_data(\"my_key\")\n    print(result)\n\nasyncio.run(main())","lang":"python","description":"Basic usage: create a Memoizer with an in-memory cache and decorate an async function with ttl in seconds."},"warnings":[{"fix":"Use asyncio-based applications or pin version to <3.0.0.","message":"Version 3.0.0 removed support for Tornado. If you rely on Tornado integration, stay on v2.x.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Update any exception handling logic that relied on checking exception.args for chained exceptions.","message":"Version 2.0.0 changed exception handling: exceptions are now chained (via __cause__) instead of being added to args. Timeout errors are now also chained.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Explicitly instantiate Memoizer with an ExpiringCache instance and configure ttl in the decorator.","message":"The default cache is InMemoryCache which has no expiration by default. Use ExpiringCache if you need TTL-based expiry.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure the decorated function is defined with async def.","message":"The decorator requires the wrapped function to be async. Applying it to a sync function will cause a runtime error.","severity":"gotcha","affected_versions":"all"},{"fix":"Migrate to asyncio-based usage.","message":"Tornado support was deprecated in v1.2.0 and removed in v3.0.0. Tornado-specific imports will raise ImportError.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use: from memoize import Memoizer","cause":"Incorrect import path; maybe using 'from memoize import memoize' or similar.","error":"AttributeError: module 'memoize' has no attribute 'Memoizer'"},{"fix":"Use @memoizer.cache(ttl=...) instead of @memoizer.cache.","cause":"Trying to use the decorator without calling it (missing parentheses).","error":"TypeError: 'Memoizer' object is not callable"},{"fix":"Make the function async: async def my_func(...) ...","cause":"Decorating a synchronous function with the cache decorator.","error":"RuntimeError: Cannot use sync function with async decorator"},{"fix":"Use asyncio backends like InMemoryCache or ExpiringCache.","cause":"Tornado support was removed in v3.0.0.","error":"ImportError: cannot import name 'TornadoBackend' from 'memoize'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}