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

You can also install the in-development version with:

pip install https://github.com/ionelmc/python-lazy-object-proxy/archive/master.zip

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.11.0 (2025-04-16)

  • Added Python 3.13 wheels.

  • Added support for __format__.

  • Dropped support for Python 3.8.

1.10.0 (2023-12-15)

  • Added Python 3.12 wheels.

  • Dropped support for Python 3.7.

  • Applied some reformatting and lint fixes using ruff to the codebase (mostly more Python 2 leftover cleanups).

1.9.0 (2023-01-04)

  • Added support for matrix multiplication operator (@).

  • Should have all the wheels now (including the manylinux ones).

  • Bumped minimum version requirements for setuptools and setuptools-scm.

  • Switched the default pure python fallback implementation to the “simple” one (when you from lazy_object_proxy import Proxy and the C extension is not available). Previously the “slots” implementation was used but as it turns out it is slower on Python 3.

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

Uploaded Source

Built Distributions

lazy_object_proxy-1.11.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

lazy_object_proxy-1.11.0-cp313-cp313t-win_amd64.whl (29.6 kB view details)

Uploaded CPython 3.13tWindows x86-64

lazy_object_proxy-1.11.0-cp313-cp313t-macosx_11_0_arm64.whl (28.8 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

lazy_object_proxy-1.11.0-cp313-cp313-win_amd64.whl (28.4 kB view details)

Uploaded CPython 3.13Windows x86-64

lazy_object_proxy-1.11.0-cp313-cp313-macosx_11_0_arm64.whl (28.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

lazy_object_proxy-1.11.0-cp312-cp312-win_amd64.whl (28.4 kB view details)

Uploaded CPython 3.12Windows x86-64

lazy_object_proxy-1.11.0-cp312-cp312-macosx_11_0_arm64.whl (28.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lazy_object_proxy-1.11.0-cp311-cp311-win_amd64.whl (28.4 kB view details)

Uploaded CPython 3.11Windows x86-64

lazy_object_proxy-1.11.0-cp311-cp311-macosx_11_0_arm64.whl (28.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lazy_object_proxy-1.11.0-cp310-cp310-win_amd64.whl (28.4 kB view details)

Uploaded CPython 3.10Windows x86-64

lazy_object_proxy-1.11.0-cp310-cp310-macosx_11_0_arm64.whl (28.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

lazy_object_proxy-1.11.0-cp39-cp39-win_amd64.whl (28.3 kB view details)

Uploaded CPython 3.9Windows x86-64

lazy_object_proxy-1.11.0-cp39-cp39-macosx_11_0_arm64.whl (28.0 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file lazy_object_proxy-1.11.0.tar.gz.

File metadata

  • Download URL: lazy_object_proxy-1.11.0.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for lazy_object_proxy-1.11.0.tar.gz
Algorithm Hash digest
SHA256 18874411864c9fbbbaa47f9fc1dd7aea754c86cfde21278ef427639d1dd78e9c
MD5 0cac82f66458b23d6e5b0da11bce7663
BLAKE2b-256 57f91f56571ed82fb324f293661690635cf42c41deb8a70a6c9e6edc3e9bb3c8

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a56a5093d433341ff7da0e89f9b486031ccd222ec8e52ec84d0ec1cdc819674b
MD5 4a1371539d5503486a62fa44119fdf1b
BLAKE2b-256 e71efb441c07b6662ec1fc92b249225ba6e6e5221b05623cb0131d082f782edc

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp313-cp313t-win_amd64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp313-cp313t-win_amd64.whl
Algorithm Hash digest
SHA256 bb03c507d96b65f617a6337dedd604399d35face2cdf01526b913fb50c4cb6e8
MD5 00f77c2f369bbfe7c1e1b5ce695f7586
BLAKE2b-256 39d07e967689e24de8ea6368ec33295f9abc94b9f3f0cd4571bfe148dc432190

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp313-cp313t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0613116156801ab3fccb9e2b05ed83b08ea08c2517fdc6c6bc0d4697a1a376e3
MD5 ac1dc1e5a9fc1b945486bd00820fb351
BLAKE2b-256 7b8968c50fcfd81e11480cd8ee7f654c9bd790a9053b9a0efe9983d46106f6a9

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d2503427bda552d3aefcac92f81d9e7ca631e680a2268cbe62cd6a58de6409b7
MD5 188bee2be9e3ada91502516c3bb81706
BLAKE2b-256 63cbb8363110e32cc1fd82dc91296315f775d37a39df1c1cfa976ec1803dac89

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fd4c84eafd8dd15ea16f7d580758bc5c2ce1f752faec877bb2b1f9f827c329cd
MD5 499863f51cac5bd03fa1ee949f914146
BLAKE2b-256 a80f6e004f928f7ff5abae2b8e1f68835a3870252f886e006267702e1efc5c7b

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ee13f67f4fcd044ef27bfccb1c93d39c100046fec1fad6e9a1fcdfd17492aeb3
MD5 311e98c0ffb45387ad911102bc8c4ee5
BLAKE2b-256 de0c645a881f5f27952a02f24584d96f9f326748be06ded2cee25f8f8d1cd196

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a9f39098e93a63618a79eef2889ae3cf0605f676cd4797fdfd49fcd7ddc318b
MD5 a3855486834b6b8ee547cbefa230804e
BLAKE2b-256 4d24dae4759469e9cd318fef145f7cfac7318261b47b23a4701aa477b0c3b42c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 76ec715017f06410f57df442c1a8d66e6b5f7035077785b129817f5ae58810a4
MD5 23826f55526b2ad61ef11ce1b165b76c
BLAKE2b-256 139caabbe1e8b99b8b0edb846b49a517edd636355ac97364419d9ba05b8fa19f

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 090935756cc041e191f22f4f9c7fd4fe9a454717067adf5b1bbd2ce3046b556e
MD5 e900d32c8d8986859a32ae2693133e0a
BLAKE2b-256 51f6eb645ca1ff7408bb69e9b1fe692cce1d74394efdbb40d6207096c0cd8381

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 01261a3afd8621a1accb5682df2593dc7ec7d21d38f411011a5712dcd418fbed
MD5 36e127bebd4fa7b44e2e5517a0eaf601
BLAKE2b-256 18333260b4f8de6f0942008479fee6950b2b40af11fc37dba23aa3672b0ce8a6

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 132bc8a34f2f2d662a851acfd1b93df769992ed1b81e2b1fda7db3e73b0d5a18
MD5 ef282aeb2d513de40a353c4c4fd5ab08
BLAKE2b-256 21c8457f1555f066f5bacc44337141294153dc993b5e9132272ab54a64ee98a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d662f0669e27704495ff1f647070eb8816931231c44e583f4d0701b7adf6272f
MD5 72fbb788c7c0a05aba1f10f4f75828fe
BLAKE2b-256 a3be5d7a93ad2892584c7aaad3db78fd5b4c14020d6f076b1f736825b7bbe2b3

See more details on using hashes here.

File details

Details for the file lazy_object_proxy-1.11.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lazy_object_proxy-1.11.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 28c174db37946f94b97a97b579932ff88f07b8d73a46b6b93322b9ac06794a3b
MD5 cca421a43ac21234292a3259f24c225f
BLAKE2b-256 046124ad1506df7edc9f8fa396fd5bbe66bdfb41c1f3d131a04802fb1a48615b

See more details on using hashes here.

Supported by

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