--- id: lazy version: "2.0" license: BSD-2-Clause license_treatment: permissive maintenance: active --- # lazy — Lazy attributes for Python objects License: permissive · Maintenance: active · Downloads: 517.1K/mo ## 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 above — 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 pip install lazy uv add lazy poetry add lazy ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 517.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags lazy attribute decorator, deferred initialization python, computed property caching, lazy evaluation decorator, descriptor lazy loading, on-demand attribute computation, decorator, lazy-evaluation, caching [View on SkillFed](https://skillfed.io/packages/lazy) · [View on PyPI](https://pypi.org/project/lazy/)