lazy
Lazy attributes for Python objects
What it is and what it does
lazy is a single-decorator package that lets you mark methods as lazy attributes—they compute their value only once, on first access, then cache and return that result on every subsequent access. This is useful for deferring expensive initialization until it's actually needed and avoiding redundant computation within an object's lifetime.
The decorator is fully typed, so type checkers can infer the type of a lazy attribute from the method's return annotation. Common use cases include lazy initialization of resource connections (file stores, database sessions) and caching of computed values (query results, derived data). The package has no runtime dependencies, making it lightweight to add to any project.
Use it for:
- Defer expensive resource initialization (file stores, database connections) until first use in a class.
- Cache computed query results or derived data within an object to avoid repeated database or API calls.
- Implement lazy property evaluation in view or request handler classes where data may not always be needed.
- Build descriptor-based lazy loading patterns for large or slow-to-initialize object attributes.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a @lazy decorator that defers computation of object attributes until first access, then caches the result for subsequent uses.
Yes. The package is lightweight (no dependencies), actively maintained, permissively licensed, and solves a common pattern—deferred initialization with caching—cleanly and with full type support. Install it if you need lazy attribute evaluation in your codebase.
Install
lazy on PyPI
pip
pip install lazyuv
uv add lazypoetry
poetry add lazyInstalling lazy
Before you install
No runtime dependencies and low install friction. Actively maintained with a recent release (2026-07-04) and ongoing repository activity.
License in practice
BSD-2-Clause is permissive; you can use this package freely in commercial and private projects with minimal restrictions.
Quickstart
from lazy import lazy
class Example:
@lazy
def expensive_resource(self):
return compute_something()
obj = Example()
result = obj.expensive_resource # computed on first access
result2 = obj.expensive_resource # cached result returned
Requires Python >= 3.5
Package facts
| License | BSD-2-Clause (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 41 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 517,093/month — #6,228 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: lazy-2.0-py3-none-any.whl
Keywords: decorator, lazy, lazy attribute, descriptor, property
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
backports.cached-propertyProvides the cached_property decorator for…
permissive · top 15,000 on PyPI
lazy-modelLazy-model provides on-demand field parsing for…
permissive · top 5,000 on PyPI
LazifyLazify provides lazy evaluation utilities for…
permissive · top 15,000 on PyPI
zope.cachedescriptorsProvides decorator-based caching for computed…
unclear · top 15,000 on PyPI
vineVine provides a Python implementation of…
permissive · top 1,000 on PyPI
lazy-object-proxyProvides a proxy object that defers execution…
permissive · top 1,000 on PyPI
property-managerProvides custom Python property decorators for…
permissive · top 15,000 on PyPI
lazy-loaderLazy-loader defers the import of subpackages…
permissive · top 1,000 on PyPI
lazy-importDefers module loading and ImportErrors until a…
copyleft · top 15,000 on PyPI
proxy_toolsProvides a lazy-evaluation proxy object that…
permissive · top 5,000 on PyPI