{"id":774,"library":"lazy-object-proxy","title":"Lazy Object Proxy","description":"lazy-object-proxy is a Python library that provides a fast and thorough lazy object proxy implementation. It defers the initialization of an object until its first access, which can be highly beneficial for performance optimization and handling circular dependencies. The library is currently at version 1.12.0 and maintains an active development cycle with regular updates. [5, 10]","status":"active","version":"1.12.0","language":"python","source_language":"en","source_url":"https://github.com/ionelmc/python-lazy-object-proxy","tags":["lazy loading","proxy","performance","optimization"],"install":[{"cmd":"pip install lazy-object-proxy","lang":"bash","label":"Latest stable version"}],"dependencies":[],"imports":[{"symbol":"Proxy","correct":"from lazy_object_proxy import Proxy"}],"quickstart":{"code":"import lazy_object_proxy\nimport time\n\ndef expensive_function():\n    \"\"\"Simulates an expensive operation.\"\"\"\n    print('Starting expensive calculation...')\n    time.sleep(2) # Simulate work\n    print('Finished expensive calculation.')\n    return 'Expensive Result'\n\n# The expensive_function is not called yet\nobj = lazy_object_proxy.Proxy(expensive_function)\n\nprint('Proxy object created, but function not called yet.')\n\n# The function is called only when the object is actually used\nprint(f'First access: {obj}') # This will trigger expensive_function\nprint(f'Second access: {obj}') # This will use the cached result\n","lang":"python","description":"This quickstart demonstrates how to create a lazy object proxy. The `expensive_function` is wrapped by `lazy_object_proxy.Proxy`. The actual execution of `expensive_function` is delayed until `obj` is accessed for the first time (e.g., when printed). Subsequent accesses use the cached result without re-executing the wrapped function. [4, 6]"},"warnings":[{"fix":"Ensure your project's Python environment meets the minimum requirement of `lazy-object-proxy` (currently >=3.9). Upgrade Python or pin `lazy-object-proxy` to an older compatible version if necessary.","message":"Support for older Python versions has been progressively dropped. Version 1.12.0 requires Python >=3.9. Previous versions (e.g., 1.11.0, 1.10.0, 1.8.0, 1.7.1) dropped support for Python 3.8, 3.7, 3.6, and 2.7 respectively. [2, 6, 8]","severity":"breaking","affected_versions":"<1.12.0"},{"fix":"To maximize performance, ensure a suitable C compiler is available in your environment during installation. On systems where C extensions are intentionally disabled (e.g., PyPy), be aware of the potential for slight performance degradation.","message":"When `lazy-object-proxy`'s C extension fails to compile (e.g., due to missing build tools or specific environments like PyPy/GraalPy), it gracefully falls back to a pure Python implementation. While functional, this can result in a performance overhead. [11]","severity":"gotcha","affected_versions":"All versions"},{"fix":"For versions 1.6.0 and newer, use `proxy_object.__resolved__` to check if the wrapped object has been resolved. For older versions, direct checking without triggering resolution is not straightforward.","message":"The `__resolved__` property was added in version 1.6.0. Before this, there was no direct public API to check if the factory function had been called without triggering its execution. [2, 8]","severity":"gotcha","affected_versions":"<1.6.0"},{"fix":"Prefer `isinstance()` for type checking as it generally works correctly. If you need to access the actual wrapped object's type or properties before resolution, you might need to reconsider if lazy loading is appropriate for that specific use case or trigger resolution explicitly.","message":"While `lazy-object-proxy` aims for transparency, deep introspection or specific type comparisons (especially direct `type()` checks) on the proxy object might not always yield the underlying object's type until it's resolved. `isinstance()` typically works as expected due to how proxies handle `__class__` attribute. [3]","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T18:53:34.181Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Run `pip install lazy-object-proxy` to install the package. If using a virtual environment, ensure it is activated before installation and execution. [3, 6, 28]","cause":"The 'lazy-object-proxy' package is not installed in the Python environment being used, or the virtual environment is not activated. [6, 28]","error":"ModuleNotFoundError: No module named 'lazy_object_proxy'"},{"fix":"Ensure that the proxy has been accessed in a way that triggers its initialization (e.g., calling a method or accessing an attribute that forces the underlying object to load). Verify that the `some_attribute` exists on the target object that the proxy is meant to represent. [3, 12]","cause":"This typically occurs when attempting to access an attribute on the lazy proxy object before the actual underlying object has been initialized, or if the attribute truly does not exist on the proxied object. [2, 22, 23]","error":"AttributeError: '__proxy__' object has no attribute 'some_attribute'"},{"fix":"Access the callable method or attribute of the object that the `Proxy` instance represents, rather than attempting to call the `Proxy` object directly. For example, if `obj = lazy_object_proxy.Proxy(expensive_func)`, call `obj()` or `obj.method()` instead of `obj` if `expensive_func` is a callable, or `obj.attribute` if it's an attribute. [3]","cause":"This error arises when you try to call the `lazy_object_proxy.Proxy` instance itself as a function or constructor, instead of calling a method or accessing an attribute of the *proxied* object. [25, 26, 27]","error":"TypeError: 'Proxy' object is not callable"},{"fix":"Ensure that the `lazy_object_proxy.Proxy` is initialized with a valid callable function as its argument, which will be invoked to create the real object upon first access. Example: `obj = lazy_object_proxy.Proxy(my_factory_function)` where `my_factory_function` returns the desired object. [3]","cause":"This internal error indicates that the `lazy_object_proxy.Proxy` instance was created incorrectly or its internal factory function, which is responsible for creating the real object, is somehow missing or inaccessible. [2]","error":"ValueError: Proxy hasn't been initiated: __factory__ is missing."}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"1.12.0","cli_name":"","cli_version":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","installed_version":null,"pypi_latest":"1.12.0","is_stale":null,"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1,"disk_size":"18.1M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1,"disk_size":"18.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.4,"import_time_s":0.01,"mem_mb":1,"disk_size":"19M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.1,"disk_size":"19.9M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.1,"disk_size":"19.9M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.6,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"20M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1,"disk_size":"11.8M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1,"disk_size":"11.8M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.4,"import_time_s":0.04,"mem_mb":1,"disk_size":"12M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.7,"disk_size":"11.5M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.3,"disk_size":"11.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.5,"import_time_s":0.04,"mem_mb":1.5,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.05,"mem_mb":1.1,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"17.5M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"17.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.9,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"lazy-object-proxy","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}