skip to navigation
skip to content

Not Logged In

memoized-property 1.0.1

A simple python decorator for defining properties that only run their fget function once

https://badge.fury.io/py/memoized-property.png https://travis-ci.org/estebistec/python-memoized-property.png?branch=master https://pypip.in/d/memoized-property/badge.png

A simple python decorator for defining properties that only run their fget function once.

  • Free software: BSD license

What?

A Python property that only calls its fget function one time. How many times have you written this code (or similar)?

def class C(object):

    @property
    def name(self):
        if not hasattr(self, '_name'):
            self._name = some_expensive_load()
        return self._name

I've written it just enough times to be annoyed enough to capture this module. The result is this:

from memoized_property import memoized_property

def class C(object):

    @memoized_property
    def name(self):
        # Boilerplate guard conditional avoided, but this is still only called once
        return some_expensive_load()

Why?

I couldn't find a pre-existing version of this on PyPI. I found one other on GitHub, https://github.com/ytyng/python-memoized-property, but it was not published to PyPI.

History

1.0.1 (2014-01-01)

  • Added python 3.2 compatability

1.0.0 (2013-12-26)

  • First release on PyPI.
 
File Type Py Version Uploaded on Size
memoized-property-1.0.1.tar.gz (md5) Source 2014-01-01 4KB
  • Downloads (All Versions):
  • 2 downloads in the last day
  • 31 downloads in the last week
  • 228 downloads in the last month