https://github.com/zmievsa/cached_classproperty
cached_property for class properties instead of instance properties
https://github.com/zmievsa/cached_classproperty
Last synced: 3 months ago
JSON representation
cached_property for class properties instead of instance properties
- Host: GitHub
- URL: https://github.com/zmievsa/cached_classproperty
- Owner: zmievsa
- License: mit
- Created: 2023-03-04T14:25:15.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-15T21:38:02.000Z (about 2 years ago)
- Last Synced: 2025-02-27T05:55:54.737Z (over 1 year ago)
- Language: Python
- Size: 32.2 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cached_classproperty
cached_property for class properties instead of instance properties
---
## Installation
```bash
pip install cached_classproperty
```
## Usage
Similarly to `functools.cached_property`, these properties get executed exactly once on access.
```python
from cached_classproperty import cached_staticproperty, cached_classproperty
class Foo:
@cached_staticproperty
def my_staticproperty():
...
@cached_classproperty
def my_classproperty(cls):
...
```
`cached_classproperty` can be inherited and can re-execute for every inherited class just like `cached_property`. `cached_staticproperty`, on the other hand, executes exactly once even if inherited. It is also lighter and faster than `cached_classproperty`.