Registry / serialization / lazy
library2.0pypypi✓ verified 22d ago

The `lazy` library (version 1.6) provides a Python descriptor that allows object attributes to be computed only when they are first accessed, and then caches the result for subsequent retrievals. It enables efficient resource usage by deferring potentially expensive computations until absolutely necessary. The project maintains an active, though not rapid, release cadence, with the latest update in 2023.

pip install lazy
INSTALL
IMPORT
SIG · LAZY
L
lazy
serializationpythonv2.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lazy
from lazy import lazy

Demonstrates the basic usage of the `@lazy` decorator on a method, turning it into a lazy-loaded, cached attribute. The computation ('computing bar') runs only on the first access.

from lazy import lazy class Foo(object): @lazy def bar(self): print("computing bar") return 42 f = Foo() print(f.bar) print(f.bar)
Debug
Known issues
gotchaLazy attributes are computed only once and then cached. If the underlying data or state that the lazy attribute depends on changes after its first access, the attribute will continue to return the stale cached value.
fix
Ensure the underlying data is immutable or clear and re-initialize the object if fresh computation is required.
affects: All
gotchaAny side effects within the method decorated with `@lazy` (e.g., logging, modifying other object state) will occur only on the first access when the attribute is initially computed. Subsequent accesses will retrieve the cached value without re-executing the method.
fix
Avoid relying on side effects for subsequent accesses or ensure side effects are idempotent and safe to run once.
affects: All
gotchaThe library's `@lazy` decorator may not be inherently thread-safe. If multiple threads concurrently access a lazy attribute for the very first time, it could lead to the underlying computation running multiple times or result in a race condition for setting the cached value.
fix
Implement explicit locking or ensure thread synchronization if the lazy attribute is accessed by multiple threads before its initial computation.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'lazy'
The 'lazy' library has not been installed in the current Python environment or is not accessible on the PYTHONPATH.
fix
Install the library using pip: `pip install lazy`
AttributeError: can't set attribute
An attempt was made to reassign a value directly to an attribute that was decorated with `@lazy` after it had already been accessed and its value computed. The `@lazy` descriptor typically makes attributes read-only after their initial lazy evaluation.
fix
Avoid direct reassignment to a `@lazy` attribute. If the value needs to change, consider if `@lazy` is the appropriate tool for that attribute, or implement a mechanism to invalidate the cached value if the library provides one.
TypeError: 'dict' object is not callable
A method decorated with `@lazy` was accessed once, which computed and cached its result (e.g., a dictionary). Subsequent attempts treated this cached *result* as if it were still the original callable method, leading to a `TypeError` when trying to call a non-callable object.
fix
Once a `@lazy` attribute has been accessed, its value is cached. To retrieve the cached value, access the attribute directly (e.g., `obj.attribute_name`). Do not attempt to call it like a method (e.g., `obj.attribute_name()`).
Upgrade
Version history
2.0latest on PyPI · released Jul 4, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
lazy — pip install lazy · libregistry