Small Python package that allows you to automatically precompute properties and recalculate them only when their dependencies change their value.
Project description
computed-properties
computed-properties is a small Python package that allows you to precompute properties and only recalculate them when the values of their dependencies have changed. This is useful for optimizing performance in classes where certain properties are expensive to compute and depend on other attributes.
Installation
You can install the package using pip:
pip install computed-properties
Usage
To use computed-properties, decorate your class properties with the provided decorator. The property will be automatically recalculated only when any of its dependencies change.
from computed_properties import ComputedPropertyCache
cache = ComputedPropertyCache()
class Rectangle(metaclass=cache):
def __init__(self, width, height):
super().__init__()
self.width = width
self.height = height
@cache.computed_property
def area(self):
print("Calculating area...")
return self.width * self.height
rect = Rectangle(3, 4)
print(rect.area) # Calculates and prints 12
print(rect.area) # Uses cached value, prints 12
rect.width = 5
print(rect.area) # Recalculates and prints 20
Features
- Declarative dependency tracking for properties.
- Automatic invalidation and recalculation when dependencies change.
- Simple API using decorators.
- Lightweight and easy to integrate into existing projects.
Additional Information
- Compatible with Python 3.7 and above.
- Well-suited for data models, scientific computing, and any scenario where computed properties depend on mutable state.
- Inspired by similar concepts in other frameworks and languages (e.g., Vue.js computed properties, Django cached_property).
- Contributions and issues are welcome via the project's GitHub repository.
For more details, examples, and API documentation, please refer to the official documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file computed_properties-0.1.2.tar.gz.
File metadata
- Download URL: computed_properties-0.1.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d552a9ed1a2eeed87da7ed0bab87ecb08abde911f24e0fca5f704fec25637664
|
|
| MD5 |
ecd7d1f801ef71d630e5cf97979b0d27
|
|
| BLAKE2b-256 |
d4a247120c8f3b8bf2098fa1380c0bcf811d720d39d25eba627c8ab7123b2532
|
Provenance
The following attestation bundles were made for computed_properties-0.1.2.tar.gz:
Publisher:
publish.yml on adriaciurana/computed-properties
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
computed_properties-0.1.2.tar.gz -
Subject digest:
d552a9ed1a2eeed87da7ed0bab87ecb08abde911f24e0fca5f704fec25637664 - Sigstore transparency entry: 219867106
- Sigstore integration time:
-
Permalink:
adriaciurana/computed-properties@4d7bb98e38f57a5108acc09b8475cc17de0171f5 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/adriaciurana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4d7bb98e38f57a5108acc09b8475cc17de0171f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file computed_properties-0.1.2-py3-none-any.whl.
File metadata
- Download URL: computed_properties-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
810ee1274a13a2cddacb4a87b06dc15e5f36765daeebdcd49d3300076b6db5cd
|
|
| MD5 |
fc769b436c156653e6730eb7dd15a214
|
|
| BLAKE2b-256 |
ef7134083569ead4ed64695d36d58f150ef27b900fdf042765e9b25b2ae30bda
|
Provenance
The following attestation bundles were made for computed_properties-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on adriaciurana/computed-properties
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
computed_properties-0.1.2-py3-none-any.whl -
Subject digest:
810ee1274a13a2cddacb4a87b06dc15e5f36765daeebdcd49d3300076b6db5cd - Sigstore transparency entry: 219867108
- Sigstore integration time:
-
Permalink:
adriaciurana/computed-properties@4d7bb98e38f57a5108acc09b8475cc17de0171f5 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/adriaciurana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4d7bb98e38f57a5108acc09b8475cc17de0171f5 -
Trigger Event:
push
-
Statement type: