Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install lazy

How to install lazy

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install lazy
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.1 Available View build log
1.0 Available View build log
1.0
1.1Never BuiltWhy not?
1.0 Available View build log
Windows (64-bit)
1.1 Available View build log
1.0 Available View build log
1.0
1.1Never BuiltWhy not?
1.0 Available View build log
Mac OS X (10.5+)
1.1 Available View build log
1.0 Available View build log
1.1 Available View build log
1.0 Available View build log
Linux (32-bit)
1.1 Available View build log
1.0 Available View build log
1.1 Available View build log
1.0 Available View build log
Linux (64-bit)
1.1 Available View build log
1.0 Available View build log
1.1 Available View build log
1.0 Available View build log
1.1 Available View build log
 
License
BSD
Dependencies
Imports
Lastest release
version 1.1 on Nov 20th, 2012

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.

Examples

The class below creates its store resource lazily:

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)

Another application area is caching:

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)

Credits

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

Changelog

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.

Subscribe to package updates

Last updated Nov 20th, 2012

Download Stats

Last month:2

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.