landuo


Namelanduo JSON
Version 1.0.0 PyPI version JSON
download
home_page
Summarycachedproperty = property + cached_property
upload_time2023-01-16 09:00:02
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License Copyright (c) 2018 Niels Bantilan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords cachedproperty lazy property cached cached-property cached_property
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # landuo (cachedproperty)
_just a property but lazier_...

Simply put, `cachedproperty` = `property` + `cached_property`.

Version: 1.0.0

# Reasons for Creating This
1. In-built [`property`](https://docs.python.org/3/library/functions.html#property) decorator allows you to manage your instances' attributes but at a cost of repeated computation for each read of the attribute.
2. `cached_property` built by many [1], allows you to cache your instances' attributes but at a cost of losing the ability to implement `setter` methods of them.

`cachedproperty` (used interchangably with `cached property` or its variants) solves this problem by caching of the values of your instances' attributes AND implementing `setter` methods for each of them.

# Objectives
|Objective|Description|Status|
|:--|:--|:--|
|Backward compatibility|It should be 'easy' (ideally, by adding a one-liner) to existing project to incorporate caching in property.|![](https://badgen.net/badge/status/completed/green)|
|Caching|Property must be cached. It should allow the use of another 'cache' beyond the instance's `__dict__` attribute for instances whose `__dict__` attribute is a non-mutable mapping. Read [more](https://docs.python.org/3/library/functools.html#cached_property).|Kinda?|
|Setter method is available|Cached property should allow for the implementation of `.setter(self, value)` method.|![](https://badgen.net/badge/status/completed/green)|
|Deleter method is available|Cached property should allow for the implementation of `.deleter(self)` method.|![](https://badgen.net/badge/status/completed/green)|
|Async compatibility|Cached property should be thread-safe. pydanny's [`cached_property`](https://github.com/pydanny/cached-property/blob/master/cached_property.py) allows for this.|No plans to do that in near future.
|Properties should be inherited as it is.|An example would be best here, if `self.name` returns `self._name` for a superclass, then for the subclass `self.name` should still return `self._name`, UNLESS wilfully overridden, e.g. `self.name` returns `f'Hi, I'm {super().name}`, the subclass' managed attribute `name` prepends `'Hi, I'm '`.|![](https://badgen.net/badge/status/completed/green)|

# Installation
[More on Installation](installation.md)

# Using `pip`

With `pip` installed, you can use the following command to install `landuo`.

```cmd
python -m pip install landuo
```

Check that `landuo` is installed by importing it in a python console.

Example:

```python
from landuo import property
```
```
>>> property
<class 'landuo._lpusedict.BaseMutableCachedProperty'> # Output
```

# How to Use
[More on Usage](quickstart.md)

## For Existing Project

If you have an existing project which already uses the python's inbuilt `property`,

* add `landuo` to your dependencies,
* add the following declaration into the import declarations in your modules that use the python's inbuilt `property`.
```python
from landuo import property
#... other import statements
```

That's it! All your original `property` should now have caching. By default, the cache used is the instance's attribute `__dict__`, read more at [APIs: cachedproperty](APIs/cachedproperty.md).

# Glossary

Managed Attribute(s) - The set of attribute(s) of a class which is managed by the `cachedproperty` / `property` object. To 'manage' means that the 'read' and/or 'write' capabilities of the attribute is decided by another python object.

Private Variable(s) - Python has no strictly 'private' variable. In this case, the 'private' variable refers to the attribute of a class that is managed by another python object.

Example:
```python
class Person:
    def __init__(self, name):
        self._name = name
        # self._name is referred as the 'private' variable

    @property # `property` manages `self.name` and its underlying private variable is `self._name`
    def name(self):
        return self._name
```

# References
[1] Here is a list of implementations for '`cached_property`'.

*    functools' [`cached_property`](https://docs.python.org/3/library/functools.html#cached_property)<br>
*    pydanny's [`cached_property`](https://github.com/pydanny/cached-property/blob/master/cached_property.py)<br>
*    penguinolog's [`cached_property`](https://github.com/penguinolog/backports.cached_property/blob/master/backports/cached_property/__init__.py) <br>
*    werkzeug's [`cached_property`](https://tedboy.github.io/flask/_modules/werkzeug/utils.html#cached_property) <br>
*    bottles' [`cached_property`](https://github.com/bottlepy/bottle/blob/df67999584a0e51ec5b691146c7fa4f3c87f5aac/bottle.py#L215)<br>
*    bottles' [`lazy_attribute`](https://github.com/bottlepy/bottle/blob/df67999584a0e51ec5b691146c7fa4f3c87f5aac/bottle.py#L230)<br>
*    sad2project's [`LazyProperty`](https://github.com/sad2project/descriptor-tools/blob/master/src/descriptor_tools/properties.py#L10)<br>

# Why the Name `landuo`?

懒惰 (Hàn yǔ Pīn yīn: lănduò) means lazy in Chinese, which describes the `cachedproperty` class of this package.






            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "landuo",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "cachedproperty,lazy,property,cached,cached-property,cached_property",
    "author": "",
    "author_email": "Jim Chng <jimchng@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/4c/ec/e0a6004524da36e2707e51e78c958333c150c2c038e3815fb07d4c2f1883/landuo-1.0.0.tar.gz",
    "platform": null,
    "description": "# landuo (cachedproperty)\r\n_just a property but lazier_...\r\n\r\nSimply put, `cachedproperty` = `property` + `cached_property`.\r\n\r\nVersion: 1.0.0\r\n\r\n# Reasons for Creating This\r\n1. In-built [`property`](https://docs.python.org/3/library/functions.html#property) decorator allows you to manage your instances' attributes but at a cost of repeated computation for each read of the attribute.\r\n2. `cached_property` built by many [1], allows you to cache your instances' attributes but at a cost of losing the ability to implement `setter` methods of them.\r\n\r\n`cachedproperty` (used interchangably with `cached property` or its variants) solves this problem by caching of the values of your instances' attributes AND implementing `setter` methods for each of them.\r\n\r\n# Objectives\r\n|Objective|Description|Status|\r\n|:--|:--|:--|\r\n|Backward compatibility|It should be 'easy' (ideally, by adding a one-liner) to existing project to incorporate caching in property.|![](https://badgen.net/badge/status/completed/green)|\r\n|Caching|Property must be cached. It should allow the use of another 'cache' beyond the instance's `__dict__` attribute for instances whose `__dict__` attribute is a non-mutable mapping. Read [more](https://docs.python.org/3/library/functools.html#cached_property).|Kinda?|\r\n|Setter method is available|Cached property should allow for the implementation of `.setter(self, value)` method.|![](https://badgen.net/badge/status/completed/green)|\r\n|Deleter method is available|Cached property should allow for the implementation of `.deleter(self)` method.|![](https://badgen.net/badge/status/completed/green)|\r\n|Async compatibility|Cached property should be thread-safe. pydanny's [`cached_property`](https://github.com/pydanny/cached-property/blob/master/cached_property.py) allows for this.|No plans to do that in near future.\r\n|Properties should be inherited as it is.|An example would be best here, if `self.name` returns `self._name` for a superclass, then for the subclass `self.name` should still return `self._name`, UNLESS wilfully overridden, e.g. `self.name` returns `f'Hi, I'm {super().name}`, the subclass' managed attribute `name` prepends `'Hi, I'm '`.|![](https://badgen.net/badge/status/completed/green)|\r\n\r\n# Installation\r\n[More on Installation](installation.md)\r\n\r\n# Using `pip`\r\n\r\nWith `pip` installed, you can use the following command to install `landuo`.\r\n\r\n```cmd\r\npython -m pip install landuo\r\n```\r\n\r\nCheck that `landuo` is installed by importing it in a python console.\r\n\r\nExample:\r\n\r\n```python\r\nfrom landuo import property\r\n```\r\n```\r\n>>> property\r\n<class 'landuo._lpusedict.BaseMutableCachedProperty'> # Output\r\n```\r\n\r\n# How to Use\r\n[More on Usage](quickstart.md)\r\n\r\n## For Existing Project\r\n\r\nIf you have an existing project which already uses the python's inbuilt `property`,\r\n\r\n* add `landuo` to your dependencies,\r\n* add the following declaration into the import declarations in your modules that use the python's inbuilt `property`.\r\n```python\r\nfrom landuo import property\r\n#... other import statements\r\n```\r\n\r\nThat's it! All your original `property` should now have caching. By default, the cache used is the instance's attribute `__dict__`, read more at [APIs: cachedproperty](APIs/cachedproperty.md).\r\n\r\n# Glossary\r\n\r\nManaged Attribute(s) - The set of attribute(s) of a class which is managed by the `cachedproperty` / `property` object. To 'manage' means that the 'read' and/or 'write' capabilities of the attribute is decided by another python object.\r\n\r\nPrivate Variable(s) - Python has no strictly 'private' variable. In this case, the 'private' variable refers to the attribute of a class that is managed by another python object.\r\n\r\nExample:\r\n```python\r\nclass Person:\r\n    def __init__(self, name):\r\n        self._name = name\r\n        # self._name is referred as the 'private' variable\r\n\r\n    @property # `property` manages `self.name` and its underlying private variable is `self._name`\r\n    def name(self):\r\n        return self._name\r\n```\r\n\r\n# References\r\n[1] Here is a list of implementations for '`cached_property`'.\r\n\r\n*    functools' [`cached_property`](https://docs.python.org/3/library/functools.html#cached_property)<br>\r\n*    pydanny's [`cached_property`](https://github.com/pydanny/cached-property/blob/master/cached_property.py)<br>\r\n*    penguinolog's [`cached_property`](https://github.com/penguinolog/backports.cached_property/blob/master/backports/cached_property/__init__.py) <br>\r\n*    werkzeug's [`cached_property`](https://tedboy.github.io/flask/_modules/werkzeug/utils.html#cached_property) <br>\r\n*    bottles' [`cached_property`](https://github.com/bottlepy/bottle/blob/df67999584a0e51ec5b691146c7fa4f3c87f5aac/bottle.py#L215)<br>\r\n*    bottles' [`lazy_attribute`](https://github.com/bottlepy/bottle/blob/df67999584a0e51ec5b691146c7fa4f3c87f5aac/bottle.py#L230)<br>\r\n*    sad2project's [`LazyProperty`](https://github.com/sad2project/descriptor-tools/blob/master/src/descriptor_tools/properties.py#L10)<br>\r\n\r\n# Why the Name `landuo`?\r\n\r\n\u61d2\u60f0 (H\u00e0n y\u01d4 P\u012bn y\u012bn: l\u0103ndu\u00f2) means lazy in Chinese, which describes the `cachedproperty` class of this package.\r\n\r\n\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2018 Niels Bantilan  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "cachedproperty = property + cached_property",
    "version": "1.0.0",
    "split_keywords": [
        "cachedproperty",
        "lazy",
        "property",
        "cached",
        "cached-property",
        "cached_property"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8062d083f05e82dea5d1463c5a3bc515d016110e227094d40342db806c5200fd",
                "md5": "05a9edc3851023750798fda6bd9eec7f",
                "sha256": "b628501e4e18633459a2644775101555354cbb9dfd49c93ce6b974712cac7e4c"
            },
            "downloads": -1,
            "filename": "landuo-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "05a9edc3851023750798fda6bd9eec7f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8775,
            "upload_time": "2023-01-16T09:00:00",
            "upload_time_iso_8601": "2023-01-16T09:00:00.117025Z",
            "url": "https://files.pythonhosted.org/packages/80/62/d083f05e82dea5d1463c5a3bc515d016110e227094d40342db806c5200fd/landuo-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cece0a6004524da36e2707e51e78c958333c150c2c038e3815fb07d4c2f1883",
                "md5": "b74f4ea84ac489dbe7d0b19359717968",
                "sha256": "12f1c4c79794dc07c6eaad486a3ed061681dceae4a8a2a65a057738dbcdacdf9"
            },
            "downloads": -1,
            "filename": "landuo-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b74f4ea84ac489dbe7d0b19359717968",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9655,
            "upload_time": "2023-01-16T09:00:02",
            "upload_time_iso_8601": "2023-01-16T09:00:02.252703Z",
            "url": "https://files.pythonhosted.org/packages/4c/ec/e0a6004524da36e2707e51e78c958333c150c2c038e3815fb07d4c2f1883/landuo-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-16 09:00:02",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "landuo"
}
        
Elapsed time: 0.02866s