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.8.0 (2022-10-26)

  • Cleaned up use of cPickle. Contributed by Sandro Tosi in #62.

  • Cleaned up more dead Python 2 code.

  • Added Python 3.11 wheels.

  • Dropped support for Python 3.6.

1.7.1 (2021-12-15)

  • Removed most of the Python 2 support code and fixed python_requires to require at least Python 3.6.

    Note that 1.7.0 has been yanked because it could not install on Python 2.7. Installing lazy-object-proxy on Python 2.7 should automatically fall back to the 1.6.0 release now.

1.7.0 (2021-12-15)

  • Switched CI to GitHub Actions, this has a couple consequences:

    • Support for Python 2.7 is dropped. You can still install it there but it’s not tested anymore and Python 2 specific handling will be removed at some point.

    • Linux wheels are now provided in musllinux and manylinux2014 variants.

  • Fixed __index__ to fallback to int if the wrapped object doesn’t have an __index__ method. This prevents situations where code using a proxy would otherwise likely just call int had the object not have an __index__ method.

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.8.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lazy_object_proxy-1.8.0-pp39-pypy39_pp73-any.whl (11.3 kB view details)

Uploaded PyPy

lazy_object_proxy-1.8.0-pp38-pypy38_pp73-any.whl (11.3 kB view details)

Uploaded PyPy

lazy_object_proxy-1.8.0-pp37-pypy37_pp73-any.whl (11.8 kB view details)

Uploaded PyPy

lazy_object_proxy-1.8.0-cp311-cp311-win_amd64.whl (22.1 kB view details)

Uploaded CPython 3.11Windows x86-64

lazy_object_proxy-1.8.0-cp311-cp311-win32.whl (20.4 kB view details)

Uploaded CPython 3.11Windows x86

lazy_object_proxy-1.8.0-cp311-cp311-macosx_10_9_x86_64.whl (22.0 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

lazy_object_proxy-1.8.0-cp310-cp310-win_amd64.whl (22.1 kB view details)

Uploaded CPython 3.10Windows x86-64

lazy_object_proxy-1.8.0-cp310-cp310-win32.whl (20.4 kB view details)

Uploaded CPython 3.10Windows x86

lazy_object_proxy-1.8.0-cp310-cp310-macosx_10_9_x86_64.whl (22.0 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

lazy_object_proxy-1.8.0-cp39-cp39-win_amd64.whl (22.1 kB view details)

Uploaded CPython 3.9Windows x86-64

lazy_object_proxy-1.8.0-cp39-cp39-win32.whl (20.4 kB view details)

Uploaded CPython 3.9Windows x86

lazy_object_proxy-1.8.0-cp39-cp39-macosx_10_9_x86_64.whl (22.0 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

lazy_object_proxy-1.8.0-cp38-cp38-win_amd64.whl (22.1 kB view details)

Uploaded CPython 3.8Windows x86-64

lazy_object_proxy-1.8.0-cp38-cp38-win32.whl (20.4 kB view details)

Uploaded CPython 3.8Windows x86

lazy_object_proxy-1.8.0-cp38-cp38-macosx_10_9_x86_64.whl (22.0 kB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

lazy_object_proxy-1.8.0-cp37-cp37m-win_amd64.whl (22.0 kB view details)

Uploaded CPython 3.7mWindows x86-64

lazy_object_proxy-1.8.0-cp37-cp37m-win32.whl (20.4 kB view details)

Uploaded CPython 3.7mWindows x86

lazy_object_proxy-1.8.0-cp37-cp37m-macosx_10_9_x86_64.whl (21.8 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ x86-64

File details

Details for the file lazy-object-proxy-1.8.0.tar.gz.

File metadata

  • Download URL: lazy-object-proxy-1.8.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for lazy-object-proxy-1.8.0.tar.gz
Algorithm Hash digest
SHA256 c219a00245af0f6fa4e95901ed28044544f50152840c5b6a3e7b2568db34d156
MD5 05edbb9fb04cef94e186e525aa2fd897
BLAKE2b-256 7437591f89e8a09ae4574391bdf8a5eecd34a3dbe545917333e625c9de9a66b0

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-pp39-pypy39_pp73-any.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-pp39-pypy39_pp73-any.whl
Algorithm Hash digest
SHA256 ce58b2b3734c73e68f0e30e4e725264d4d6be95818ec0a0be4bb6bf9a7e79aa8
MD5 1a13ad93dbd3a468058382e5e455f37b
BLAKE2b-256 f5dc11168f6697ed68ec29a4f0887308c0d7836d96148a81eb0abb7b8e77b8e8

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-pp38-pypy38_pp73-any.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-pp38-pypy38_pp73-any.whl
Algorithm Hash digest
SHA256 7e1561626c49cb394268edd00501b289053a652ed762c58e1081224c8d881cec
MD5 eb06eb510223fcc47c57a269b3e7f5c1
BLAKE2b-256 e3904c8d2ce638791874f48894761e305afa2bf6f85f315f1d51946eb1e2b18f

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-pp37-pypy37_pp73-any.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-pp37-pypy37_pp73-any.whl
Algorithm Hash digest
SHA256 ae032743794fba4d171b5b67310d69176287b5bf82a21f588282406a79498891
MD5 ef944643968ac448d0d426726a678bae
BLAKE2b-256 b9a2e6b92d1ce6da768a1570d436616f4c565420fcf1c4b2b5246cf77624fe36

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 14010b49a2f56ec4943b6cf925f597b534ee2fe1f0738c84b3bce0c1a11ff10d
MD5 c6a268571d06f408a5c3c3e3d3b15a5b
BLAKE2b-256 d78a7bf9154dd7e6e9bda733a105e3baca3636abe72091cd1dcbf636979b667f

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp311-cp311-win32.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 e20bfa6db17a39c706d24f82df8352488d2943a3b7ce7d4c22579cb89ca8896e
MD5 3532c6eb019f002a92ee643da5c40da2
BLAKE2b-256 34c51ef17ab530068f7a5549ab376726f83fe2221db592dbdfd4f8fd4662e45d

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4e2d9f764f1befd8bdc97673261b8bb888764dfdbd7a4d8f55e4fbcabb8c3fb7
MD5 317de6b17f3449bc733b35eed1cde14d
BLAKE2b-256 6508836c9e4e6edf3a267e5b1d0c03923a70ee1a233baf6eb00bfab88d795c51

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 eb329f8d8145379bf5dbe722182410fe8863d186e51bf034d2075eb8d85ee25b
MD5 9ec8757053d828bec469ab532be85e8f
BLAKE2b-256 64edad47931e7780a5c39f7439de9124438794137840ffdb5f3ffd2995228071

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp310-cp310-win32.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 b70d6e7a332eb0217e7872a73926ad4fdc14f846e85ad6749ad111084e76df25
MD5 eec965cb4c8e557da3a31cc8fbba392b
BLAKE2b-256 30c381c176ce53d9107947d355b273f9661a4f4cad6d56d1daf1c9d6969902e8

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4fd031589121ad46e293629b39604031d354043bb5cdf83da4e93c2d7f3389fe
MD5 effd824161e7e5193320f94a3fd5df0e
BLAKE2b-256 7c0f60db0efe9a1d61fc830cfd2806d54c5fb64761e8009b9d163bf0ede5b12d

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 eac3a9a5ef13b332c059772fd40b4b1c3d45a3a2b05e33a361dee48e54a4dad0
MD5 fec9643929b4693b6158fcf302834cea
BLAKE2b-256 9dd16dd90b049748d02d9120a496c3649220ac4f6803dd74c9ae48f2bb001239

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp39-cp39-win32.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 8f6ce2118a90efa7f62dd38c7dbfffd42f468b180287b748626293bf12ed468f
MD5 8b943c67ff51c39863b8664e270a8122
BLAKE2b-256 463555c3650f29858869596871b7fedf4a6b211b61dcc4dd8e8d5702eb85370e

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 71d9ae8a82203511a6f60ca5a1b9f8ad201cac0fc75038b2dc5fa519589c9288
MD5 8a7a4de1d57bb5af6226f8e171aefc0c
BLAKE2b-256 9d237e78292a5b72121a8bdfff128fcfb8d3630af74336855d3e527f73eaa4c0

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 afcaa24e48bb23b3be31e329deb3f1858f1f1df86aea3d70cb5c8578bfe5261c
MD5 7e195584c2f0df8f830c0e94782299c4
BLAKE2b-256 e0d30cdabfa685eb152a9f4d179fa95f121b3810171f246e8e51f45d100b345c

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp38-cp38-win32.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 d176f392dbbdaacccf15919c77f526edf11a34aece58b55ab58539807b85436f
MD5 75132606b001fab3c4fec4ddd1ebc480
BLAKE2b-256 80aa71f82fd17211767419d6b1fc3dc00ba4641c11f9c9358f7acc5222e693b9

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0c1c7c0433154bb7c54185714c6929acc0ba04ee1b167314a779b9025517eada
MD5 ef7d9184129e2973863df9983bb8ad0c
BLAKE2b-256 959744ee4e0247754bcb878886baf2e06856ff268b0d67e86f1d750f251e3c87

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 6f593f26c470a379cf7f5bc6db6b5f1722353e7bf937b8d0d0b3fba911998858
MD5 7925787d27c5a144ef6512734a92219b
BLAKE2b-256 f671e0dbe4172135aca4b4f657cf15fefd34247b5392ae42cf2ca2583dfa332f

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp37-cp37m-win32.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 5b51d6f3bfeb289dfd4e95de2ecd464cd51982fe6f00e2be1d0bf94864d58acd
MD5 dec829d32ba3ed69e2d7205c3fa1c493
BLAKE2b-256 60c1bf324cf9a0577b0e3781b1a38696405235ac784c4a6d889f97a36dcedc70

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.8.0-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.8.0-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6850e4aeca6d0df35bb06e05c8b934ff7c533734eb51d0ceb2d63696f1e6030c
MD5 e50adb9aaf081a9c9831067c33d3da58
BLAKE2b-256 0a685839136508651d813c1adce568e2f7417bb66083dc8d604a69d465ee53c0

See more details on using hashes here.

Supported by

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