--- id: cached-property version: "2.0.1" license: BSD license_treatment: permissive maintenance: dormant --- # cached-property — A decorator for caching properties in classes. License: permissive · Maintenance: dormant · Popularity: top 1,000 on PyPI ## Install pip install cached-property uv add cached-property poetry add cached-property ## Description # cached-property [![Github Actions status](https://github.com/pydanny/cached-property/workflows/Python%20package/badge.svg)](https://github.com/pydanny/cached-property/actions) [![PyPI](https://img.shields.io/pypi/v/cached-property.svg)](https://pypi.python.org/pypi/cached-property) [![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff) A decorator for caching properties in classes. ## Why? * Makes caching of time or computational expensive properties quick and easy. * Because I got tired of copy/pasting this code from non-web project to non-web project. * I needed something really simple that worked in Python 2 and 3. (Python 3.8 added a version of this decorator as [`@functools.cached_property`](https://docs.python.org/3.12/library/functools.html#functools.cached_property).) ## How to use it Let's define a class with an expensive property. Every time you stay there the price goes up by $50! ```python class Monopoly: def __init__(self): self.boardwalk_price = 500 @property def boardwalk(self): # In reality, this might represent a database call or time # intensive task... [View on SkillFed](https://skillfed.io/packages/cached-property) · [View on PyPI](https://pypi.org/project/cached-property/)