Registry / property-manager

property-manager

JSON →
library3.0pypypi✓ verified 89d ago

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-manager
INSTALL
IMPORT
SIG · PROPERTY-MANAGER
P
property-manager
pythonv3.0
Install
1.7s avg
Import
96ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.098s · 18.6MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.7s · import 0.095s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PropertyManager
✓ from property_manager import PropertyManager
writable_property
✓ from property_manager import writable_property
required_property
✓ from property_manager import required_property
cached_property
✓ from property_manager import cached_property

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.

from property_manager import PropertyManager, required_property, writable_property, cached_property import random class MyManagedObject(PropertyManager): @required_property def name(self): """A name that must be provided during initialization.""" pass @writable_property def value(self): """A writable property with a computed default.""" return random.randint(1, 100) @cached_property def expensive_calculation(self): """A property whose value is computed once and cached.""" print("Calculating expensive_calculation...") return sum(range(self.value * 1000)) # Instantiate with a required property obj = MyManagedObject(name="Example Item") # Access writable property (gets default initially) print(f"Initial value: {obj.value}") # Set writable property obj.value = 200 print(f"New value: {obj.value}") # Access cached property (computes once) print(f"Expensive calculation (first access): {obj.expensive_calculation}") print(f"Expensive calculation (second access): {obj.expensive_calculation}") # Attempt to create an object without a required property try: MyManagedObject() except TypeError as e: print(f"Caught expected error: {e}")
Debug
Known issues
gotchaClasses inheriting from `PropertyManager` will raise a `TypeError` during instantiation if a `required_property` is not provided as a keyword argument to the constructor.
fix
Always provide values for `required_property` via keyword arguments in the `PropertyManager` subclass constructor.
affects: 3.0 and earlier
gotchaThe `cached_property` in `property-manager` does not support threading or time-based cache invalidation, unlike some other cached property implementations (e.g., `cached-property` library). If you need these features, consider alternatives or implement custom cache invalidation logic.
fix
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.
affects: 3.0 and earlier
gotchaValues for `writable_property` instances on `PropertyManager` subclasses can be set directly via keyword arguments during object instantiation. This can lead to unexpected behavior if not accounted for when designing constructors or expecting properties to always start with their computed defaults.
fix
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.
affects: 3.0 and earlier
Errors
Common errors & fixes
TypeError: Required property 'attribute_name' not set
You tried to instantiate a `PropertyManager` subclass but did not provide a value for a property decorated with `@required_property`.
fix
Provide a value for the required property as a keyword argument during object instantiation. For example: `my_instance = MyClass(attribute_name='some_value')`
TypeError: keyword argument 'unknown_arg' doesn't match a property
You passed a keyword argument to the constructor of a `PropertyManager` subclass that does not correspond to any defined property on the class.
fix
Ensure that all keyword arguments passed to the `PropertyManager` constructor match the names of existing properties defined in the class.
AttributeError: property 'my_property' cannot be set
You attempted to assign a value to a property that was not defined as `writable` (i.e., `writable=False` or it's a `required_property` which is implicitly non-writable after initial setting, or a `cached_property` without `writable=True`).
fix
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.
ModuleNotFoundError: No module named 'property_manager'
The `property-manager` library is either not installed in your Python environment or there's a typo in the import statement.
fix
Install the package using pip: `pip install property-manager` (note the hyphen). Ensure your import statement uses an underscore: `from property_manager import PropertyManager`.
AttributeError: property 'my_property' cannot be deleted
You attempted to delete a property that was not defined as `resettable` (i.e., `resettable=False`).
fix
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)`.
Upgrade
Version history
3.0latest on PyPI · released Mar 2, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
property-manager — pip install property-manager · libregistry