Skip to main content

lazypkg: lazy import modules and subpackages

Version_status license

What is lazypkg?

lazypkg features the LazyPkg object, a ModuleType object that lazy imports subpackages and allows access to subpackage objects. Lazy importing is when a submodule is not imported along with the top level module, but is still accessible on demand.

Installation

Get the latest version of lazypkg from https://pypi.python.org/pypi/lazypkg/

If you have an installation of Python with pip, simple install it with:

$ pip install lazypkg

To get the git version, run:

$ git clone git://github.com/yoelcortes/lazypkg

Getting started

LazyPkg objects are straight forward. First assume the following package structure:

package/
  __init__.py
  module.py
  ...
  subpackage/
    __init__.py
    submodule.py
    ...

Here is an example implementation of a LazyPkg object in the package __init__.py file:

from lazypkg import LazyPkg
from .module import obj
__all__ = ['obj']
LazyPkg(__name__, ['subpackage'])
# This converts the package into a LazyPkg object and lazy imports 'subpackage'

Say the subpackage __init__.py file looks like this:

from . import submodule
__all__ = ['submodule']
print('imported subpackage')

When the subpackage is accessed, only then will it be imported:

>>> import package # Subpackages are not imported
>>> package.obj
# -> Works just like an ordinary package
>>> package.subpackage
imported subpackage

Additionally, subpackage object are directly accessible:

>>> import package
>>> package.submodule
# -> Assuming "submodule" is not defined in the top level package,
#    this will import and search subpackages for the "submodule"

This is all possible because the package become a LazyPkg instance:

>>> import package
>>> type(package)
lazypkg.LazyPkg

Bug reports

To report bugs, please use the lazypkg’s Bug Tracker at:

https://github.com/yoelcortes/lazypkg

License information

See LICENSE.txt for information on the terms & conditions for usage of this software, and a DISCLAIMER OF ALL WARRANTIES.

Although not required by the lazypkg license, if it is convenient for you, please cite lazypkg if used in your work. Please also consider contributing any changes you make back, and benefit the community.

Citation

To cite lazypkg in publications use:

Yoel Cortes-Pena. lazypkg: lazy import modules and subpackages.
https://github.com/yoelcortes/lazypkg

Metadata

Release files for lazypkg 1.4

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

Source distribution (sdist)

Source distribution for lazypkg 1.4
File Size Uploaded Provenance Actions
lazypkg-1.4.tar.gz 3.5 kB Without provenance Details for lazypkg-1.4.tar.gz

Release files / lazypkg-1.4.tar.gz

Download URL lazypkg-1.4.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
80aac786f902cf5468401a070186fff0e587d2fba5c24cb4c0dbbb074bb8c9a6
BLAKE2b-256 checksum
How to use checksums
18fad903b770526912c5c84d97d25d1798ed09474f7c2a6399964ac50563d497
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Security for lazypkg 1.4

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.

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