Skip to main content

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.

Metadata

Release files for lazy-object-proxy 1.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lazy-object-proxy 1.11.0
File Size Uploaded
lazy_object_proxy-1.11.0.tar.gz 44.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for lazy-object-proxy 1.11.0
File
lazy_object_proxy-1.11.0-py3-none-any.whl Python 3 none any Details
lazy_object_proxy-1.11.0-cp313-cp313t-win_amd64.whl CPython 3.13 CPython 3.13 free-threading Windows x86-64 Details
lazy_object_proxy-1.11.0-cp313-cp313t-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 free-threading macOS 11.0+ ARM64 Details
lazy_object_proxy-1.11.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
lazy_object_proxy-1.11.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
lazy_object_proxy-1.11.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
lazy_object_proxy-1.11.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
lazy_object_proxy-1.11.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
lazy_object_proxy-1.11.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
lazy_object_proxy-1.11.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
lazy_object_proxy-1.11.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
lazy_object_proxy-1.11.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
lazy_object_proxy-1.11.0-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details

Total release size: 402.1 kB

Release files / lazy_object_proxy-1.11.0.tar.gz

Download URL lazy_object_proxy-1.11.0.tar.gz
Size 44.7 kB
Tags Source
SHA-256 checksum
How to use checksums
18874411864c9fbbbaa47f9fc1dd7aea754c86cfde21278ef427639d1dd78e9c
BLAKE2b-256 checksum
How to use checksums
57f91f56571ed82fb324f293661690635cf42c41deb8a70a6c9e6edc3e9bb3c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-py3-none-any.whl

Download URL lazy_object_proxy-1.11.0-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a56a5093d433341ff7da0e89f9b486031ccd222ec8e52ec84d0ec1cdc819674b
BLAKE2b-256 checksum
How to use checksums
e71efb441c07b6662ec1fc92b249225ba6e6e5221b05623cb0131d082f782edc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp313-cp313t-win_amd64.whl

Download URL lazy_object_proxy-1.11.0-cp313-cp313t-win_amd64.whl
Size 29.6 kB
Tags CPython 3.13 CPython 3.13 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
bb03c507d96b65f617a6337dedd604399d35face2cdf01526b913fb50c4cb6e8
BLAKE2b-256 checksum
How to use checksums
39d07e967689e24de8ea6368ec33295f9abc94b9f3f0cd4571bfe148dc432190
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp313-cp313t-macosx_11_0_arm64.whl

Download URL lazy_object_proxy-1.11.0-cp313-cp313t-macosx_11_0_arm64.whl
Size 28.8 kB
Tags CPython 3.13 CPython 3.13 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0613116156801ab3fccb9e2b05ed83b08ea08c2517fdc6c6bc0d4697a1a376e3
BLAKE2b-256 checksum
How to use checksums
7b8968c50fcfd81e11480cd8ee7f654c9bd790a9053b9a0efe9983d46106f6a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp313-cp313-win_amd64.whl

Download URL lazy_object_proxy-1.11.0-cp313-cp313-win_amd64.whl
Size 28.4 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
d2503427bda552d3aefcac92f81d9e7ca631e680a2268cbe62cd6a58de6409b7
BLAKE2b-256 checksum
How to use checksums
63cbb8363110e32cc1fd82dc91296315f775d37a39df1c1cfa976ec1803dac89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL lazy_object_proxy-1.11.0-cp313-cp313-macosx_11_0_arm64.whl
Size 28.1 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
fd4c84eafd8dd15ea16f7d580758bc5c2ce1f752faec877bb2b1f9f827c329cd
BLAKE2b-256 checksum
How to use checksums
a80f6e004f928f7ff5abae2b8e1f68835a3870252f886e006267702e1efc5c7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp312-cp312-win_amd64.whl

Download URL lazy_object_proxy-1.11.0-cp312-cp312-win_amd64.whl
Size 28.4 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
ee13f67f4fcd044ef27bfccb1c93d39c100046fec1fad6e9a1fcdfd17492aeb3
BLAKE2b-256 checksum
How to use checksums
de0c645a881f5f27952a02f24584d96f9f326748be06ded2cee25f8f8d1cd196
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL lazy_object_proxy-1.11.0-cp312-cp312-macosx_11_0_arm64.whl
Size 28.1 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9a9f39098e93a63618a79eef2889ae3cf0605f676cd4797fdfd49fcd7ddc318b
BLAKE2b-256 checksum
How to use checksums
4d24dae4759469e9cd318fef145f7cfac7318261b47b23a4701aa477b0c3b42c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp311-cp311-win_amd64.whl

Download URL lazy_object_proxy-1.11.0-cp311-cp311-win_amd64.whl
Size 28.4 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
76ec715017f06410f57df442c1a8d66e6b5f7035077785b129817f5ae58810a4
BLAKE2b-256 checksum
How to use checksums
139caabbe1e8b99b8b0edb846b49a517edd636355ac97364419d9ba05b8fa19f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL lazy_object_proxy-1.11.0-cp311-cp311-macosx_11_0_arm64.whl
Size 28.0 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
090935756cc041e191f22f4f9c7fd4fe9a454717067adf5b1bbd2ce3046b556e
BLAKE2b-256 checksum
How to use checksums
51f6eb645ca1ff7408bb69e9b1fe692cce1d74394efdbb40d6207096c0cd8381
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp310-cp310-win_amd64.whl

Download URL lazy_object_proxy-1.11.0-cp310-cp310-win_amd64.whl
Size 28.4 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
01261a3afd8621a1accb5682df2593dc7ec7d21d38f411011a5712dcd418fbed
BLAKE2b-256 checksum
How to use checksums
18333260b4f8de6f0942008479fee6950b2b40af11fc37dba23aa3672b0ce8a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL lazy_object_proxy-1.11.0-cp310-cp310-macosx_11_0_arm64.whl
Size 28.0 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
132bc8a34f2f2d662a851acfd1b93df769992ed1b81e2b1fda7db3e73b0d5a18
BLAKE2b-256 checksum
How to use checksums
21c8457f1555f066f5bacc44337141294153dc993b5e9132272ab54a64ee98a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp39-cp39-win_amd64.whl

Download URL lazy_object_proxy-1.11.0-cp39-cp39-win_amd64.whl
Size 28.3 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
d662f0669e27704495ff1f647070eb8816931231c44e583f4d0701b7adf6272f
BLAKE2b-256 checksum
How to use checksums
a3be5d7a93ad2892584c7aaad3db78fd5b4c14020d6f076b1f736825b7bbe2b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / lazy_object_proxy-1.11.0-cp39-cp39-macosx_11_0_arm64.whl

Download URL lazy_object_proxy-1.11.0-cp39-cp39-macosx_11_0_arm64.whl
Size 28.0 kB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
28c174db37946f94b97a97b579932ff88f07b8d73a46b6b93322b9ac06794a3b
BLAKE2b-256 checksum
How to use checksums
046124ad1506df7edc9f8fa396fd5bbe66bdfb41c1f3d131a04802fb1a48615b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

1.11.0 This release

14 release files

1.8.0

19 release files

1.7.1

37 release files

1.7.0

37 release files

1.6.0

22 release files

1.5.2

24 release files

1.5.1

22 release files

1.4.3

21 release files

1.4.2

18 release files

1.4.1

18 release files

1.2.2

16 release files

1.2.1

11 release files

1.2.0

7 release files

1.1.0

7 release files

1.0.2

7 release files

1.0.1

7 release files

1.0.0

7 release files

0.1.0

7 release files

0.0.1

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