Name | auto-lazy-imports JSON |
Version |
0.2.0
JSON |
| download |
home_page | None |
Summary | A module to enable lazy imports using native python syntax |
upload_time | 2025-02-05 14:04:35 |
maintainer | None |
docs_url | None |
author | Dhia Hmila |
requires_python | >=3.9 |
license | MIT License |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Lazyimports
[](https://pypi.org/project/auto-lazy-imports/)
[](https://pypi.org/project/auto-lazy-imports/)
[](https://pypi.org/project/auto-lazy-imports/)
[](https://pypi.org/project/auto-lazy-imports/)

[](https://github.com/copier-org/copier)
[](https://github.com/astral-sh/ruff)
## Overview ๐
**Lazyimports** is a Python module that enables lazy imports using native Python syntax, reducing startup time and improving performance by delaying module loading until needed.
## Installation ๐จ
Install `lazyimports` via pip:
```sh
pip install auto-lazy-imports
```
## Usage ๐
### 1. Using a `with` Statement
Wrap imports in a `with` statement to enable lazy loading:
```python
import lazyimports
with lazyimports.lazy_imports("package", "package.submodule"):
from package import submodule
submodule.hello()
```
### 2. Configuring via `pyproject.toml`
Define lazy-loaded modules and objects in pyproject.toml for package-based usage.
#### Standard configuration:
```toml
[project.entry-points.lazyimports]
"lazy_modules" = "package,package.submodule"
"lazy_functions" = "package:hello"
"lazy_objects" = "package:array,package:integer"
```
#### Poetry-based configuration:
```toml
[tool.poetry.plugins.lazyimports]
"lazy_modules" = "package,package.submodule"
"lazy_functions" = "package:hello"
"lazy_objects" = "package:array,package:integer"
```
๐ก The keys (lazy_modules, lazy_functions, etc.) can be listed in any order, using comma-separated values.
The previous example is also equivalent to:
```toml
[project.entry-points.lazyimports]
"custom_key" = "package,package.submodule,package:hello,package:array,package:integer"
```
After defining the configuration, import modules as usualโno code modifications needed:
```python
from package import submodule
from package import hello
```
### 3. Using an Environment Variable (for Development)
Dynamically enable lazy imports by setting an environment variable:
```sh
export PYTHON_LAZY_IMPORTS="package,package.submodule,package:array,package:integer,package:hello"
python script.py
```
Raw data
{
"_id": null,
"home_page": null,
"name": "auto-lazy-imports",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Dhia Hmila",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/ba/e2/9e1ae087ea8c4a99244f88cbd35a6b34e0865b0dd9c319aa335a9ca94261/auto_lazy_imports-0.2.0.tar.gz",
"platform": null,
"description": "# Lazyimports\n\n[](https://pypi.org/project/auto-lazy-imports/)\n\n[](https://pypi.org/project/auto-lazy-imports/)\n[](https://pypi.org/project/auto-lazy-imports/)\n[](https://pypi.org/project/auto-lazy-imports/)\n\n[](https://github.com/copier-org/copier)\n[](https://github.com/astral-sh/ruff)\n\n## Overview \ud83c\udf10\n\n**Lazyimports** is a Python module that enables lazy imports using native Python syntax, reducing startup time and improving performance by delaying module loading until needed.\n\n## Installation \ud83d\udd28\n\nInstall `lazyimports` via pip:\n\n```sh\npip install auto-lazy-imports\n```\n\n## Usage \ud83d\udc4d\n\n### 1. Using a `with` Statement\n\nWrap imports in a `with` statement to enable lazy loading:\n\n```python\nimport lazyimports\n\nwith lazyimports.lazy_imports(\"package\", \"package.submodule\"):\n from package import submodule\n\nsubmodule.hello()\n```\n\n### 2. Configuring via `pyproject.toml`\n\nDefine lazy-loaded modules and objects in pyproject.toml for package-based usage.\n\n#### Standard configuration:\n\n```toml\n[project.entry-points.lazyimports]\n\"lazy_modules\" = \"package,package.submodule\"\n\"lazy_functions\" = \"package:hello\"\n\"lazy_objects\" = \"package:array,package:integer\"\n```\n\n#### Poetry-based configuration:\n\n```toml\n[tool.poetry.plugins.lazyimports]\n\"lazy_modules\" = \"package,package.submodule\"\n\"lazy_functions\" = \"package:hello\"\n\"lazy_objects\" = \"package:array,package:integer\"\n```\n\n\ud83d\udca1 The keys (lazy_modules, lazy_functions, etc.) can be listed in any order, using comma-separated values.\n\nThe previous example is also equivalent to:\n\n```toml\n[project.entry-points.lazyimports]\n\"custom_key\" = \"package,package.submodule,package:hello,package:array,package:integer\"\n```\n\n\nAfter defining the configuration, import modules as usual\u2014no code modifications needed:\n\n```python\nfrom package import submodule\nfrom package import hello\n```\n\n### 3. Using an Environment Variable (for Development)\n\nDynamically enable lazy imports by setting an environment variable:\n\n```sh\nexport PYTHON_LAZY_IMPORTS=\"package,package.submodule,package:array,package:integer,package:hello\"\npython script.py\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "A module to enable lazy imports using native python syntax",
"version": "0.2.0",
"project_urls": {
"Issues": "https://github.com/hmiladhia/lazyimports/issues",
"Repository": "https://github.com/hmiladhia/lazyimports"
},
"split_keywords": [],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "1600c00e9f38ac51ff3471b7a7fa526b26196d2fce690523f48abdd81a6ea5d3",
"md5": "e731af2ccd00b5f750f6cc71d3fdc8a2",
"sha256": "0e07f5c51c9928b7ceb8c05291f7712b5d56797d6c308541fb8acf190c573b1b"
},
"downloads": -1,
"filename": "auto_lazy_imports-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e731af2ccd00b5f750f6cc71d3fdc8a2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 5134,
"upload_time": "2025-02-05T14:04:34",
"upload_time_iso_8601": "2025-02-05T14:04:34.637045Z",
"url": "https://files.pythonhosted.org/packages/16/00/c00e9f38ac51ff3471b7a7fa526b26196d2fce690523f48abdd81a6ea5d3/auto_lazy_imports-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "bae29e1ae087ea8c4a99244f88cbd35a6b34e0865b0dd9c319aa335a9ca94261",
"md5": "ffb4b7dd92da3591f6e7490950a82ec0",
"sha256": "b9c3b342cceabe0b1d499c7986840eeea6fa233cdcc384b428c99e61c3e08d9d"
},
"downloads": -1,
"filename": "auto_lazy_imports-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "ffb4b7dd92da3591f6e7490950a82ec0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 206574,
"upload_time": "2025-02-05T14:04:35",
"upload_time_iso_8601": "2025-02-05T14:04:35.979702Z",
"url": "https://files.pythonhosted.org/packages/ba/e2/9e1ae087ea8c4a99244f88cbd35a6b34e0865b0dd9c319aa335a9ca94261/auto_lazy_imports-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-05 14:04:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hmiladhia",
"github_project": "lazyimports",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "auto-lazy-imports"
}