The `property-manager` package, currently at version 3.0, provides useful property variants for Python programming, extending Python's built-in `property` descriptor. It offers decorators for creating required properties, writable properties, and cached properties, as well as a `PropertyManager` base class with enhanced constructor behavior and `repr()` customization. The library has a stable release cadence, with version 3.0 released in 2020, and is designed to make managing class attributes more robust and flexible.
pip install property-managerVerified import paths — ran on the pinned version, not inferred.
This example demonstrates defining a class using `PropertyManager` with `required_property`, `writable_property`, and `cached_property`. It shows how required properties are enforced at instantiation, how writable properties can have computed defaults and be assigned new values, and how cached properties compute their value only once upon first access.
Always provide values for `required_property` via keyword arguments in the `PropertyManager` subclass constructor.
For thread-safe or time-sensitive caching, use a different library or implement custom locking/invalidation. For manual invalidation, use the `clear_cached_properties()` method on `PropertyManager` subclasses.
Be aware that constructor keyword arguments can override the initial computed default of `writable_property`. If you need to prevent this, implement custom constructor logic.
Provide a value for the required property as a keyword argument during object instantiation. For example: `my_instance = MyClass(attribute_name='some_value')`
Ensure that all keyword arguments passed to the `PropertyManager` constructor match the names of existing properties defined in the class.
If the property is intended to be writable, define it using `@writable_property` or `@cached_property(writable=True)`. If it's a `required_property`, its value can only be set during initialization and cannot be changed later.
Install the package using pip: `pip install property-manager` (note the hyphen). Ensure your import statement uses an underscore: `from property_manager import PropertyManager`.
If the property is intended to be deletable (to reset its value to its computed default), define it with `resettable=True` in its decorator, e.g., `@cached_property(resettable=True)`.
No dependency data recorded yet.