LazImp, The "don't wait for it..." package
LazImp is a package that allows lazy loading of python modules, packages and symboles for python 3.10+. This package allows you to load modules and packages only when the user use it. From dynamic import to "I only need this function, not the whole framework", the start-up time is speed-up and delayed over the execution of the software.
Using LazImp, you will reduce the memory usage and the start-up time of your software.
Example
First, you may have long loading or memory heavy modules to expose in your package api:
# package/heavy_module.py
print('Heavy module is loading...')
from time import sleep
sleep(10)
print('heavy_module loaded')
But instead of importing them directly, you can do a lazy import in
the __init__.py:
# package/__init__.py of a package
import lazimp
math: lazimp.ModuleType
heavy_module: lazimp.ModuleType
__getattr__ = lazimp.lazy_import(
'math',
heavy_module='package',
)
Now, when you import the package:
# main.py
import package
print('Before access to heavy_module')
print(package.heavy_module)
print('After access to heavy_module')
print('Before access to math')
print(package.math)
print('After access to math')
And the output:
Before access to heavy_module
Heavy module is loading...
(wait 10 sec)
heavy_module loaded
<module 'heavy_module' from '...'>
After access to heavy_module
Before access to math
# math loaded
<module 'math' (built-in)>
After access to math
Without the lazy loading of heavy_module.py, the output would have been:
Heavy module is loading...
(wait 10 sec)
heavy_module loaded # math loaded too
Before access to heavy_module
<module 'heavy_module' from '...'>
After access to heavy_module
Before access to math
<module 'math' (built-in)>
After access to math
Why this name: LazImp?
lazimp is a portmanteau of lazy and imp.
imp was the name of the module importlib before python 3.4 and its
deprecation: What's new in Python 3.4: Deprecations in the Python API
The name could have been lazy_import but the imp part was preferred as a
reference to the original module and because an
imp with sunglasses and cocktail is cool 😎, and lazy shorten because it
sounded better.
Metadata
Release files for lazimp 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| lazimp-0.0.5.tar.gz | 3.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lazimp-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.8 kB
Release files / lazimp-0.0.5.tar.gz
| Download URL | lazimp-0.0.5.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
822f7f524726cc54e3b6af53bec3e79d1e18fba77f16819cc32031212275863c
|
|
BLAKE2b-256 checksum How to use checksums |
3f630c6276a8489b8d0652a04c50b129d919817894f0b520193e5481c4819231
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.0
|
Release files / lazimp-0.0.5-py3-none-any.whl
| Download URL | lazimp-0.0.5-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
83ead6000b453c3dc43a35d0b333b5bb088ce8a7ca572780e5bf2596d1cb6041
|
|
BLAKE2b-256 checksum How to use checksums |
0144de808c68d598d23052aa97f0fa1cd73ea7e4494f354bd5977db092babcbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.0
|
Security for lazimp 0.0.5
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.