Skip to main content

lazyshell

Lazy optional imports for Python projects. shell_import lets you declare optional dependencies once and load them on first use. Missing packages can degrade gracefully using sink proxies so your code keeps running.

Installation

pip install lazyshell

Supports Python 3.9 and newer and has no runtime dependencies.

Quick start

from lazyshell import shell_import

# request multiple modules at once
np, hass, missing = shell_import(
    "numpy",
    ("hass", "homeassistant.core"),
    "not_installed",
    sink=True,                      # return sink proxies for missing packages
    sink_map={"hass.log": print},  # route hass.log -> print
)

# modules are imported on first use
arr = np.arange(3)

# sink proxies are truthy and return None by default
missing.anything()  # -> None

# override behaviour for a specific attribute
hass.log("hello")  # prints "hello"

Proxy behaviour

  • bool(proxy) is False until the real module or object is successfully imported.
  • Accessing an attribute or calling the proxy triggers the import.
  • If the import fails:
    • with sink=False (default) a MissingPackage sentinel is returned and attribute access raises ImportError.
    • with sink=True a SinkProxy is returned. It is truthy, attribute access returns further sink proxies and method calls are no-ops unless a fallback is provided via set.
  • The .with_sink() helper enables sink mode on creation; .enable_sink() enables it after a failed import.
  • Register fallbacks with proxy.set("attr", value) or via attribute proxies: proxy.attr.set(value).
  • The is_loaded property reports whether the underlying import has occurred.

Set the environment variable LAZYSHELL_DEBUG=1 to get a one-time warning when a sink proxy is instantiated.

License

lazyshell is distributed under the terms of the MIT License. See LICENSE for details.

Metadata

Release files for lazyshell 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lazyshell 0.2.1
File Size Uploaded Provenance
lazyshell-0.2.1.tar.gz 5.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for lazyshell 0.2.1
File Interpreter ABI Platform
lazyshell-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / lazyshell-0.2.1.tar.gz

Download URL lazyshell-0.2.1.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
65061346cb939366cc61aded7e5518fa3fc0c789614c1e0be0b0722c934863c9
BLAKE2b-256 checksum
How to use checksums
fe46b0942d2c396f58b833ebcf45658d3f9895ef256ace3ca89fe3f50184a06b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Release files / lazyshell-0.2.1-py3-none-any.whl

Download URL lazyshell-0.2.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
711f0ded4c43e36f0aa74a6d65efa959a8d9084a941bdbf0a9cfc631aba305ae
BLAKE2b-256 checksum
How to use checksums
4c10df579ef46738bf266e4d08393cdeefcfa972cd9db0e2f8672a33965ada8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Security for lazyshell 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page