Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

computed_properties-0.1.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

computed_properties-0.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

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

Hashes for computed_properties-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d552a9ed1a2eeed87da7ed0bab87ecb08abde911f24e0fca5f704fec25637664
MD5 ecd7d1f801ef71d630e5cf97979b0d27
BLAKE2b-256 d4a247120c8f3b8bf2098fa1380c0bcf811d720d39d25eba627c8ab7123b2532

See more details on using hashes here.

Provenance

The following attestation bundles were made for computed_properties-0.1.2.tar.gz:

Publisher: publish.yml on adriaciurana/computed-properties

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file computed_properties-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for computed_properties-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 810ee1274a13a2cddacb4a87b06dc15e5f36765daeebdcd49d3300076b6db5cd
MD5 fc769b436c156653e6730eb7dd15a214
BLAKE2b-256 ef7134083569ead4ed64695d36d58f150ef27b900fdf042765e9b25b2ae30bda

See more details on using hashes here.

Provenance

The following attestation bundles were made for computed_properties-0.1.2-py3-none-any.whl:

Publisher: publish.yml on adriaciurana/computed-properties

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page