propcache
Fast, C-accelerated property caching for Python, providing `cached_property` and `under_cached_property` decorators
Repository Health
Technical Analysis
propcache provides a cached_property-style decorator that memoizes an expensive computed attribute on first access and reuses the result on subsequent lookups, with an optional Cython-compiled fast path for CPython and a pure-Python fallback for other interpreters like PyPy. It also offers under_cached_property, a variant that stores its cache under a name-mangled attribute to avoid clashing with __slots__ or public attribute names.
Extracted from the aio-libs ecosystem (the organization behind aiohttp, yarl, and multidict), propcache was split out as its own dependency so that performance-sensitive caching logic could be shared and independently versioned across those libraries and any other project needing the same pattern.
What You Get
cached_propertydecorator that memoizes a method’s result as an instance attribute on first accessunder_cached_propertyvariant storing the cache under a mangled name to coexist with__slots__- A Cython-compiled
_helpers_cfast path used automatically on supported CPython builds - A pure-Python
_helpers_pyfallback so the library works unmodified on PyPy and other interpreters - Full type-hint support via a bundled
py.typedmarker for static type checkers
Common Use Cases
- Caching expensive derived attributes (e.g. parsed URL components, computed hashes) on frequently instantiated objects
- Reducing per-request overhead in high-throughput async libraries like aiohttp and yarl that call the same computed property repeatedly
- Any Python class needing memoized properties without introducing a heavier caching framework as a dependency
- Libraries needing memoization compatible with
__slots__-based classes viaunder_cached_property
Under The Hood
Architecture
The library exposes a stable public surface (api.py, __init__.py) that re-exports whichever implementation is available: a Cython-compiled extension built from _helpers_c.pyx when present, or the pure-Python _helpers_py.py implementation as an automatic fallback, with _helpers.py acting as the selection/compatibility shim between the two.
Tech Stack
A hybrid Python/Cython project using a custom in-tree PEP 517 build backend (packaging/pep517_backend) to conditionally cythonize and compile the C extension at build time; ships prebuilt wheels for common platforms so most users never need a C compiler, and is packaged with a src/ layout.
Code Quality
Despite its small size (roughly 250 lines across implementation files), the project has a proportionally thorough test suite (test_cached_property.py, test_under_cached_property.py, test_api.py, plus dedicated benchmark tests) and enforces mypy static typing via .mypy.ini, along with pre-commit hooks and towncrier-managed changelogs.
API Design
The API is minimal by design — import cached_property and apply it exactly like Python’s standard-library functools.cached_property, making adoption immediate for anyone already familiar with that pattern, with under_cached_property as the only additional concept needed for __slots__ compatibility.
Used by 5 apps in this directory
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
GPT Researcher
Productivity · AI Assistants
The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.
Helicone
Monitoring · AI Development · Analytics
An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.
knowhere
AI Development · Developer Tools
Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.
SWIRL
Search · Databases · Data Engineering
Federated AI search and RAG across 100+ enterprise sources—no data extraction, no vector database required.