{"id":6779,"library":"property-manager","title":"Property Manager","description":"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.","status":"active","version":"3.0","language":"en","source_language":"en","source_url":"https://github.com/xolox/python-property-manager","tags":["python","properties","descriptors","caching","required-properties","writable-properties","object-oriented"],"install":[{"cmd":"pip install property-manager","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"PropertyManager","correct":"from property_manager import PropertyManager"},{"symbol":"writable_property","correct":"from property_manager import writable_property"},{"symbol":"required_property","correct":"from property_manager import required_property"},{"symbol":"cached_property","correct":"from property_manager import cached_property"}],"quickstart":{"code":"from property_manager import PropertyManager, required_property, writable_property, cached_property\nimport random\n\nclass MyManagedObject(PropertyManager):\n    @required_property\n    def name(self):\n        \"\"\"A name that must be provided during initialization.\"\"\"\n        pass\n\n    @writable_property\n    def value(self):\n        \"\"\"A writable property with a computed default.\"\"\"\n        return random.randint(1, 100)\n\n    @cached_property\n    def expensive_calculation(self):\n        \"\"\"A property whose value is computed once and cached.\"\"\"\n        print(\"Calculating expensive_calculation...\")\n        return sum(range(self.value * 1000))\n\n# Instantiate with a required property\nobj = MyManagedObject(name=\"Example Item\")\n\n# Access writable property (gets default initially)\nprint(f\"Initial value: {obj.value}\")\n\n# Set writable property\nobj.value = 200\nprint(f\"New value: {obj.value}\")\n\n# Access cached property (computes once)\nprint(f\"Expensive calculation (first access): {obj.expensive_calculation}\")\nprint(f\"Expensive calculation (second access): {obj.expensive_calculation}\")\n\n# Attempt to create an object without a required property\ntry:\n    MyManagedObject()\nexcept TypeError as e:\n    print(f\"Caught expected error: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Always provide values for `required_property` via keyword arguments in the `PropertyManager` subclass constructor.","message":"Classes inheriting from `PropertyManager` will raise a `TypeError` during instantiation if a `required_property` is not provided as a keyword argument to the constructor.","severity":"gotcha","affected_versions":"3.0 and earlier"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"3.0 and earlier"},{"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.","message":"Values 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.","severity":"gotcha","affected_versions":"3.0 and earlier"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}