Skip to main content

A fast and thorough lazy object proxy.

Project description

A fast and thorough lazy object proxy.

  • Free software: BSD 2-Clause License

Note that this is based on wrapt’s ObjectProxy with one big change: it calls a function the first time the proxy object is used, while wrapt.ObjectProxy just forwards the method calls to the target object.

In other words, you use lazy-object-proxy when you only have the object way later and you use wrapt.ObjectProxy when you want to override few methods (by subclassing) and forward everything else to the target object.

Example:

import lazy_object_proxy

def expensive_func():
    from time import sleep
    print('starting calculation')
    # just as example for a very slow computation
    sleep(2)
    print('finished calculation')
    # return the result of the calculation
    return 10

obj = lazy_object_proxy.Proxy(expensive_func)
# function is called only when object is actually used
print(obj)  # now expensive_func is called

print(obj)  # the result without calling the expensive_func

Installation

pip install lazy-object-proxy

Documentation

https://python-lazy-object-proxy.readthedocs.io/

Development

To run all the tests run:

tox

Acknowledgements

This project is based on some code from wrapt as you can see in the git history.

Changelog

1.6.0 (2021-03-22)

  • Added support for async special methods (__aiter__, __anext__, __await__, __aenter__, __aexit__). These are used in the async for, await` and ``async with statements.

    Note that __await__ returns a wrapper that tries to emulate the crazy stuff going on in the ceval loop, so there will be a small performance overhead.

  • Added the __resolved__ property. You can use it to check if the factory has been called.

1.5.2 (2020-11-26)

  • Added Python 3.9 wheels.

  • Removed Python 2.7 Windows wheels (not supported on newest image with Python 3.9).

1.5.1 (2020-07-22)

  • Added ARM64 wheels (manylinux2014).

1.5.0 (2020-06-05)

  • Added support for __fspath__.

  • Dropped support for Python 3.4.

1.4.3 (2019-10-26)

  • Added binary wheels for Python 3.8.

  • Fixed license metadata.

1.4.2 (2019-08-22)

  • Included a pyproject.toml to allow users install the sdist with old python/setuptools, as the setuptools-scm dep will be fetched by pip instead of setuptools. Fixes #30.

1.4.1 (2019-05-10)

  • Fixed wheels being built with -coverage cflags. No more issues about bogus cext.gcda files.

  • Removed useless C file from wheels.

  • Changed setup.py to use setuptools-scm.

1.4.0 (2019-05-05)

  • Fixed __mod__ for the slots backend. Contributed by Ran Benita in #28.

  • Dropped support for Python 2.6 and 3.3. Contributed by “hugovk” in #24.

1.3.1 (2017-05-05)

  • Fix broken release (sdist had a broken MANIFEST.in).

1.3.0 (2017-05-02)

  • Speed up arithmetic operations involving cext.Proxy subclasses.

1.2.2 (2016-04-14)

  • Added manylinux wheels.

  • Minor cleanup in readme.

1.2.1 (2015-08-18)

  • Fix a memory leak (the wrapped object would get bogus references). Contributed by Astrum Kuo in #10.

1.2.0 (2015-07-06)

  • Don’t instantiate the object when __repr__ is called. This aids with debugging (allows one to see exactly in what state the proxy is).

1.1.0 (2015-07-05)

  • Added support for pickling. The pickled value is going to be the wrapped object without any Proxy container.

  • Fixed a memory management issue in the C extension (reference cycles weren’t garbage collected due to improper handling in the C extension). Contributed by Alvin Chow in #8.

1.0.2 (2015-04-11)

  • First release on PyPI.

Project details


Download files

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

Source Distribution

lazy-object-proxy-1.6.0.tar.gz (44.5 kB view hashes)

Uploaded Source

Built Distributions

lazy_object_proxy-1.6.0-cp39-cp39-win_amd64.whl (22.5 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

lazy_object_proxy-1.6.0-cp39-cp39-win32.whl (20.5 kB view hashes)

Uploaded CPython 3.9 Windows x86

lazy_object_proxy-1.6.0-cp39-cp39-macosx_10_14_x86_64.whl (21.6 kB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

lazy_object_proxy-1.6.0-cp38-cp38-win_amd64.whl (22.4 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

lazy_object_proxy-1.6.0-cp38-cp38-win32.whl (20.5 kB view hashes)

Uploaded CPython 3.8 Windows x86

lazy_object_proxy-1.6.0-cp37-cp37m-win_amd64.whl (22.3 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

lazy_object_proxy-1.6.0-cp37-cp37m-win32.whl (20.4 kB view hashes)

Uploaded CPython 3.7m Windows x86

lazy_object_proxy-1.6.0-cp37-cp37m-manylinux1_x86_64.whl (55.8 kB view hashes)

Uploaded CPython 3.7m

lazy_object_proxy-1.6.0-cp36-cp36m-win_amd64.whl (22.3 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

lazy_object_proxy-1.6.0-cp36-cp36m-win32.whl (20.4 kB view hashes)

Uploaded CPython 3.6m Windows x86

lazy_object_proxy-1.6.0-cp36-cp36m-manylinux1_x86_64.whl (55.7 kB view hashes)

Uploaded CPython 3.6m

lazy_object_proxy-1.6.0-cp27-cp27mu-manylinux1_x86_64.whl (53.9 kB view hashes)

Uploaded CPython 2.7mu

lazy_object_proxy-1.6.0-cp27-cp27m-win_amd64.whl (20.5 kB view hashes)

Uploaded CPython 2.7m Windows x86-64

lazy_object_proxy-1.6.0-cp27-cp27m-win32.whl (18.9 kB view hashes)

Uploaded CPython 2.7m Windows x86

lazy_object_proxy-1.6.0-cp27-cp27m-macosx_10_14_x86_64.whl (21.1 kB view hashes)

Uploaded CPython 2.7m macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page