Tool to support lazy imports
Project description
Lazy-Imports
This is a Python tool to support lazy imports.
Likewise, the actual initialization of the module does not occur until usage time
to postpone ModuleNotFoundError
s to the time of the actual usage of the module.
This is useful when using various optional dependencies which might not all be
installed or which have high load times and/or ressource consumption.
This project is maintained by the One Conversation
team of Deutsche Telekom AG.
It is based on
_LazyModule
from the HuggingFace team. Many thanks for
your consent
to publish it as a standalone package 🤗 ♥.
Installation
Lazy-Imports is available at the Python Package Index (PyPI). It can be installed with pip:
$ pip install lazy-imports
Usage & Example
A good and easy to understand example of how to use Lazy-Imports can be found in the
__init__.py
file of the HPOflow package.
It is printed here:
import sys
from typing import TYPE_CHECKING
from lazy_imports import LazyImporter
from hpoflow.version import __version__
_import_structure = {
"mlflow": [
"normalize_mlflow_entry_name",
"normalize_mlflow_entry_names_in_dict",
"check_repo_is_dirty",
],
"optuna": ["SignificanceRepeatedTrainingPruner"],
"optuna_mlflow": ["OptunaMLflow"],
"optuna_transformers": ["OptunaMLflowCallback"],
"utils": ["func_no_exception_caller"],
}
# Direct imports for type-checking
if TYPE_CHECKING:
from hpoflow.mlflow import ( # noqa: F401
check_repo_is_dirty,
normalize_mlflow_entry_name,
normalize_mlflow_entry_names_in_dict,
)
from hpoflow.optuna import SignificanceRepeatedTrainingPruner # noqa: F401
from hpoflow.optuna_mlflow import OptunaMLflow # noqa: F401
from hpoflow.optuna_transformers import OptunaMLflowCallback # noqa: F401
from hpoflow.utils import func_no_exception_caller # noqa: F401
else:
sys.modules[__name__] = LazyImporter(
__name__,
globals()["__file__"],
_import_structure,
extra_objects={"__version__": __version__},
)
Support and Feedback
The following channels are available for discussions, feedback, and support requests:
Working Language
We decided to apply English as the primary project language.
Consequently, all content will be made available primarily in English. We also ask all interested people to use English as language to create issues, in their code (comments, documentation etc.) and when you send requests to us. The application itself and all end-user facing content will be made available in other languages as needed.
Licensing
Copyright (c) 2021 Philip May, Deutsche Telekom AG
Copyright (c) 2020, 2021 The HuggingFace Team
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
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
File details
Details for the file lazy_imports-0.1.0.tar.gz
.
File metadata
- Download URL: lazy_imports-0.1.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fa02daa66b44d831d8c83180cb4bfafa8081f226ed46edf32a1bc11b3d49562 |
|
MD5 | 73819c1876527ad2eef5140811d3f9a1 |
|
BLAKE2b-256 | e081e37dad963f6f16d19f9cea7cd3693e3484f3adc7fc8d29433befb4bfb3dd |
File details
Details for the file lazy_imports-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: lazy_imports-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14e13ef39abe1e4f4f443f9f12e07c6c08e2cdd04dba2ec1042df0272d9b6869 |
|
MD5 | e4e863a4caf76703e72ec1961348204e |
|
BLAKE2b-256 | f5e1e1441968b56b242d202b6f4ed36003f142a603cc56f02b7f880e1e9dc092 |