A simple lazy module loader for python
Project description
lazy-loading
lazy-loading is a simple lazy module loader for python.
Usage:
First, you'll need to import lazy-loading.
To lazily load a package, use:
package = lazy-loading.lazyload("package")
You can lazily load submodules of your package:
lazy-loading.lazyload("mypacakge.submodule")
[!IMPORTANT] Relative imports (e.g.
.submodule) are not supported. You need to use absolute module paths.
IDE autocompletion & type-checking
To get type-checking and autocompletion, you need to import all lazy-loaded packages
if typing.TYPE_CHECKING is True:
from lazy-loading import lazyload
from typing import TYPE_CHECKING
lazyload("package1")
lazyload("package2")
if TYPE_CHECKING:
import package1
import package2
This will only run if a type-checker or linter is checking your code and will not cause packages to not lazy load in normal contexts.
Limitations:
Partial lazy loading
Partial lazy loading (e.g. from package import symbol) is not supported.
Accessing an attribute or function will automatically import the entire module.
Relative imports
As mentioned previously, relative imports are not supported. You can lazy-load modules in your script's directory:
lazy-loading.lazyload("module")
If you are building a package:
lazy-loading.lazyload("package.module")
Lazily-loaded module dependencies
Imports called by lazily-loaded modules will not be lazy-loaded (unless the module uses lazy loading itself.)
Global name injection
Global name injection is not supported. You'll need to set a variable to the returned lazy-loaded package. It will replace itself with the lazy-loaded package when a symbol is accessed.
- Removed global name injection because it doesn't work in most contexts and can cause a security risk
Full Changelog: https://github.com/yesser-studios/lazy-loading/commits/0.2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lazy_loading-0.2.0.tar.gz.
File metadata
- Download URL: lazy_loading-0.2.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de48de022250f17497e3ff40bbeaa5e8b0c65a555d492d23021e8731435a23d1
|
|
| MD5 |
b2523b9c5a58f58876d7713b152da68c
|
|
| BLAKE2b-256 |
92c518c895a48be169fc9aa1af4d2fc244035b24bf31db70cb93e62f26528470
|
File details
Details for the file lazy_loading-0.2.0-py3-none-any.whl.
File metadata
- Download URL: lazy_loading-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9982d66e9d8d6d685be8d8980b14b8bd4c3506c66365de4eec2cff2ad6a75c10
|
|
| MD5 |
bc4418577cebad76d8f5d45c3b2e5c73
|
|
| BLAKE2b-256 |
389025d4466a7d583ca6816ea43d6b33f2e783fd1455870f5d148a9ab5a1475e
|