skillfed

lazy

Lazy attributes for Python objects

lazy v2.0 517.1K downloads/30d#6,228 on PyPI53
Permissive license BSD-2-Clause Active released

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 lazy

uv

uv add lazy

poetry

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 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Typing :: Typed

Tags

lazy attribute decoratordeferred initialization pythoncomputed property cachinglazy evaluation decoratordescriptor lazy loadingon-demand attribute computation
decoratorlazy-evaluationcaching

More Software Development packages