Skip to main content

A lightweight and extensible way to implement lazy imports globally.

Project description

Lazi: Lazy Imports Everywhere

A lightweight and extensible way to implement lazy imports globally.

Usage:

poetry add lazi
"""Automatic lazy loading example.

Install django to run, or change the imports.
"""
import lazi.auto                 # Install import tracking.
import django.test               # Import stuff.
print(lazi.used_count())         # Count loaded modules.
TestCase = django.test.TestCase  # Trigger lazy loading.
print(lazi.used_count())         # More modules were lazy loaded.
python example.py
0
211
"""Manual lazy loading example.
"""
import lazi.core                        # Import Lazi.
django = lazi.lazy("django")            # Import stuff.
django_test = lazi.lazy("django.test")  # Import more stuff.
print(lazi.used_count())                # Count loaded modules.
TestCase = django_test.TestCase         # Trigger lazy loading.
print(lazi.used_count())                # Module was lazy loaded.
0
2

Configuration

The lazi.conf namespace package contains configuration modules that get autoloaded (in import order) by lazi.conf.conf. It is fully decoupled from the rest of the codebase.

As a result, it's possible configure Lazi by creating lazi.conf modules in your project (within the lazi.conf namespace package), and use conf modules provided by other packages.

Configuration is not yet controllable via environment variables, but this is planned for the future.

It's also possible to manually change the configuration at runtime, with the caveat that some variables may have already been used by lazi.core. To avoid this, configure Lazi before importing it:

from lazi.conf import conf
conf.DEBUG_TRACING = True
import lazi.auto
# ...

Metadata

Reference for developers: The json dict below contains Python versioning parameters:

  • Soft min (ignore rev) & hard max compatible versions.
  • Recommended use & creator's environment dev versions.
{
  "python": {
    "version": {
      "min": "3.10.11",
      "max": "3.12",
      "use": "3.11",
      "dev": "3.11.2"
    }
  }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lazi-1.4.0.32.tar.gz (22.6 kB view hashes)

Uploaded Source

Built Distribution

lazi-1.4.0.32-py3-none-any.whl (24.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page