lazy


Namelazy JSON
Version 1.6 PyPI version JSON
download
home_pagehttps://github.com/stefanholek/lazy
SummaryLazy attributes for Python objects
upload_time2023-09-14 13:31:13
maintainer
docs_urlhttps://pythonhosted.org/lazy/
authorStefan H. Holek
requires_python!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7
licenseBSD-2-Clause
keywords decorator lazy lazy attribute descriptor property
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ====
lazy
====
----------------------------------
Lazy attributes for Python objects
----------------------------------

Package Contents
================

@lazy
    A decorator to create lazy attributes.

Overview
========

Lazy attributes are computed attributes that are evaluated only
once, the first time they are used.  Subsequent uses return the
results of the first call. They come handy when code should run

- *late*, i.e. just before it is needed, and
- *once*, i.e. not twice, in the lifetime of an object.

You can think of it as *deferred initialization*.
The possibilities are endless.

Typing
======

The decorator is fully typed. Type checkers can infer the type of
a lazy attribute from the return value of the decorated method.

Examples
========

The class below creates its ``store`` resource lazily:

.. code-block:: python

    from lazy import lazy

    class FileUploadTmpStore(object):

        @lazy
        def store(self):
            location = settings.get('fs.filestore')
            return FileSystemStore(location)

        def put(self, uid, fp):
            self.store.put(uid, fp)
            fp.seek(0)

        def get(self, uid, default=None):
            return self.store.get(uid, default)

        def close(self):
            if 'store' in self.__dict__:
                self.store.close()

Another application area is caching:

.. code-block:: python

    class PersonView(View):

        @lazy
        def person_id(self):
            return self.request.get('person_id', -1)

        @lazy
        def person_data(self):
            return self.session.query(Person).get(self.person_id)

Documentation
=============

For further details please refer to the `API Documentation`_.

.. _`API Documentation`: https://lazy.readthedocs.io/en/stable/


Changelog
=========

1.6 - 2023-09-14
----------------

- Implement ``lazy.__set_name__()`` which helps in cases like
  ``foo=lazy(_foo)``.
  [stefan]

- Update tox.ini for latest tox.
  [stefan]

- Add GitHub CI workflow.
  [stefan]

- Add .readthedocs.yaml file.
  [stefan]

- Pin sphinx and sphinx-rtd-theme versions in docs extra.
  [stefan]

- Add mypy extra which installs mypy.
  [stefan]

- Fix stray characters in keywords.
  [stefan]

1.5 - 2022-09-18
----------------

- Allow type checkers to infer the type of a lazy attribute.
  Thanks to Elias Keis and Palpatineli for their contributions.
  [elKei24] [Palpatineli]

- Add Python 3.8-3.11 to tox.ini. Remove old Python versions.
  [stefan]

- Replace deprecated ``python setup.py test`` in tox.ini.
  [stefan]

- Remove deprecated ``test_suite`` from setup.py.
  [stefan]

- Move metadata to setup.cfg and add a pyproject.toml file.
  [stefan]

- Include tests in sdist but not in wheel.
  [stefan]

1.4 - 2019-01-28
----------------

- Add MANIFEST.in.
  [stefan]

- Release as universal wheel.
  [stefan]

1.3 - 2017-02-05
----------------

- Support Python 2.6-3.6 without 2to3.
  [stefan]

- Add a LICENSE file.
  [stefan]

1.2 - 2014-04-19
----------------

- Remove setuptools from install_requires because it isn't.
  [stefan]

1.1 - 2012-10-12
----------------

- Use ``functools.wraps()`` properly; the list of attributes changes with
  every version of Python 3.
  [stefan]

1.0 - 2011-03-24
----------------

- Initial release.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/stefanholek/lazy",
    "name": "lazy",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/lazy/",
    "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
    "maintainer_email": "",
    "keywords": "decorator,lazy,lazy attribute,descriptor,property",
    "author": "Stefan H. Holek",
    "author_email": "stefan@epy.co.at",
    "download_url": "https://files.pythonhosted.org/packages/3c/e6/704c32da169b023a9ac86d116f5433b42d02b4afeda24c9400a69b3530e5/lazy-1.6.tar.gz",
    "platform": null,
    "description": "====\nlazy\n====\n----------------------------------\nLazy attributes for Python objects\n----------------------------------\n\nPackage Contents\n================\n\n@lazy\n    A decorator to create lazy attributes.\n\nOverview\n========\n\nLazy attributes are computed attributes that are evaluated only\nonce, the first time they are used.  Subsequent uses return the\nresults of the first call. They come handy when code should run\n\n- *late*, i.e. just before it is needed, and\n- *once*, i.e. not twice, in the lifetime of an object.\n\nYou can think of it as *deferred initialization*.\nThe possibilities are endless.\n\nTyping\n======\n\nThe decorator is fully typed. Type checkers can infer the type of\na lazy attribute from the return value of the decorated method.\n\nExamples\n========\n\nThe class below creates its ``store`` resource lazily:\n\n.. code-block:: python\n\n    from lazy import lazy\n\n    class FileUploadTmpStore(object):\n\n        @lazy\n        def store(self):\n            location = settings.get('fs.filestore')\n            return FileSystemStore(location)\n\n        def put(self, uid, fp):\n            self.store.put(uid, fp)\n            fp.seek(0)\n\n        def get(self, uid, default=None):\n            return self.store.get(uid, default)\n\n        def close(self):\n            if 'store' in self.__dict__:\n                self.store.close()\n\nAnother application area is caching:\n\n.. code-block:: python\n\n    class PersonView(View):\n\n        @lazy\n        def person_id(self):\n            return self.request.get('person_id', -1)\n\n        @lazy\n        def person_data(self):\n            return self.session.query(Person).get(self.person_id)\n\nDocumentation\n=============\n\nFor further details please refer to the `API Documentation`_.\n\n.. _`API Documentation`: https://lazy.readthedocs.io/en/stable/\n\n\nChangelog\n=========\n\n1.6 - 2023-09-14\n----------------\n\n- Implement ``lazy.__set_name__()`` which helps in cases like\n  ``foo=lazy(_foo)``.\n  [stefan]\n\n- Update tox.ini for latest tox.\n  [stefan]\n\n- Add GitHub CI workflow.\n  [stefan]\n\n- Add .readthedocs.yaml file.\n  [stefan]\n\n- Pin sphinx and sphinx-rtd-theme versions in docs extra.\n  [stefan]\n\n- Add mypy extra which installs mypy.\n  [stefan]\n\n- Fix stray characters in keywords.\n  [stefan]\n\n1.5 - 2022-09-18\n----------------\n\n- Allow type checkers to infer the type of a lazy attribute.\n  Thanks to Elias Keis and Palpatineli for their contributions.\n  [elKei24] [Palpatineli]\n\n- Add Python 3.8-3.11 to tox.ini. Remove old Python versions.\n  [stefan]\n\n- Replace deprecated ``python setup.py test`` in tox.ini.\n  [stefan]\n\n- Remove deprecated ``test_suite`` from setup.py.\n  [stefan]\n\n- Move metadata to setup.cfg and add a pyproject.toml file.\n  [stefan]\n\n- Include tests in sdist but not in wheel.\n  [stefan]\n\n1.4 - 2019-01-28\n----------------\n\n- Add MANIFEST.in.\n  [stefan]\n\n- Release as universal wheel.\n  [stefan]\n\n1.3 - 2017-02-05\n----------------\n\n- Support Python 2.6-3.6 without 2to3.\n  [stefan]\n\n- Add a LICENSE file.\n  [stefan]\n\n1.2 - 2014-04-19\n----------------\n\n- Remove setuptools from install_requires because it isn't.\n  [stefan]\n\n1.1 - 2012-10-12\n----------------\n\n- Use ``functools.wraps()`` properly; the list of attributes changes with\n  every version of Python 3.\n  [stefan]\n\n1.0 - 2011-03-24\n----------------\n\n- Initial release.\n",
    "bugtrack_url": null,
    "license": "BSD-2-Clause",
    "summary": "Lazy attributes for Python objects",
    "version": "1.6",
    "project_urls": {
        "Documentation": "https://lazy.readthedocs.io/en/stable/",
        "Homepage": "https://github.com/stefanholek/lazy"
    },
    "split_keywords": [
        "decorator",
        "lazy",
        "lazy attribute",
        "descriptor",
        "property"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11ae3ae578fc22dc9c5f60ddcb5c254fe808d45ee7b4cd03315245caf5db6a47",
                "md5": "d291aee5d64c5318620e12a231353bd3",
                "sha256": "449375c125c7acac6b7a93f71b8e7ccb06546c37b161613f92d2d3981f793244"
            },
            "downloads": -1,
            "filename": "lazy-1.6-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d291aee5d64c5318620e12a231353bd3",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
            "size": 5246,
            "upload_time": "2023-09-14T13:31:11",
            "upload_time_iso_8601": "2023-09-14T13:31:11.688118Z",
            "url": "https://files.pythonhosted.org/packages/11/ae/3ae578fc22dc9c5f60ddcb5c254fe808d45ee7b4cd03315245caf5db6a47/lazy-1.6-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ce6704c32da169b023a9ac86d116f5433b42d02b4afeda24c9400a69b3530e5",
                "md5": "01a1311b20cc6f119e5478ef036685c2",
                "sha256": "7127324ec709e8324f08cb4611c1abe01776bda53bb9ce68dc5dfa46ca0ed3e9"
            },
            "downloads": -1,
            "filename": "lazy-1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "01a1311b20cc6f119e5478ef036685c2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7",
            "size": 10562,
            "upload_time": "2023-09-14T13:31:13",
            "upload_time_iso_8601": "2023-09-14T13:31:13.666598Z",
            "url": "https://files.pythonhosted.org/packages/3c/e6/704c32da169b023a9ac86d116f5433b42d02b4afeda24c9400a69b3530e5/lazy-1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 13:31:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stefanholek",
    "github_project": "lazy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "lazy"
}
        
Elapsed time: 0.14424s