Skip to main content
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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memoized-property-1.0.1.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file memoized-property-1.0.1.tar.gz.

File metadata

File hashes

Hashes for memoized-property-1.0.1.tar.gz
Algorithm Hash digest
SHA256 15b7b19d56dad8bbcaab3935c8880d5f3951a65714114384eeceb7262e91d23f
MD5 8b05cbd912d3d4c24c2d62c3ab0f5b7f
BLAKE2b-256 428d81892a7858ce247a2e305cf7ff35db13f260fe232d98dd7fe85971b263d1

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.3

1 file

1.0.2

1 file

This release

1.0.1 This release

1 file

1.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page