Skip to content
Lazy attributes for Python objects
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Remove old docs redirect. Jan 28, 2019
CHANGES.rst Post-release version bump. Jan 28, 2019
LICENSE Add Aug 6, 2017
README.rst Link to documentation in README. May 3, 2018
setup.cfg Update metadata. Feb 2, 2017 Post-release version bump. Jan 28, 2019
tox.ini Add Python 3.7 to classifiers. Jan 26, 2019



Lazy attributes for Python objects

Package Contents

A decorator to create lazy attributes.


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.


The class below creates its store resource lazily:

from lazy import lazy

class FileUploadTmpStore(object):

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

    def put(self, uid, fp):, fp)

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

Another application area is caching:

class PersonView(View):

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

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


For further details please refer to the API Documentation.


I first encountered this type of descriptor in the zope.cachedescriptors package, which is part of the Zope Toolkit.

You can’t perform that action at this time.