diff --git a/src/bindings/python/src/openvino/__init__.py b/src/bindings/python/src/openvino/__init__.py index 7643f742e0067d..15bf3c6eb9671e 100644 --- a/src/bindings/python/src/openvino/__init__.py +++ b/src/bindings/python/src/openvino/__init__.py @@ -59,7 +59,8 @@ from openvino._ov_api import AsyncInferQueue # Import all public modules -from openvino import runtime as runtime +from openvino.package_utils import lazy_import +runtime = lazy_import("openvino.runtime") from openvino import frontend as frontend from openvino import helpers as helpers from openvino import experimental as experimental diff --git a/src/bindings/python/src/openvino/package_utils.py b/src/bindings/python/src/openvino/package_utils.py index 6aa3f3ed39b556..2a89703d647983 100644 --- a/src/bindings/python/src/openvino/package_utils.py +++ b/src/bindings/python/src/openvino/package_utils.py @@ -7,6 +7,8 @@ from functools import wraps from typing import Callable, Any from pathlib import Path +import importlib.util +from types import ModuleType def _add_openvino_libs_to_search_path() -> None: @@ -113,3 +115,16 @@ def __get__(self, obj: Any, cls: Any = None) -> Any: _patch(func, deprecated(name, version, message, stacklevel)) return func return decorator + + +def lazy_import(module_name: str) -> ModuleType: + spec = importlib.util.find_spec(module_name) + if spec is None or spec.loader is None: + raise ImportError(f"Module {module_name} not found") + + loader = importlib.util.LazyLoader(spec.loader) + module = importlib.util.module_from_spec(spec) + sys.modules[module_name] = module + + loader.exec_module(module) + return module diff --git a/src/bindings/python/src/openvino/runtime/__init__.py b/src/bindings/python/src/openvino/runtime/__init__.py index e22e2be08cacea..63367b9ab875f9 100644 --- a/src/bindings/python/src/openvino/runtime/__init__.py +++ b/src/bindings/python/src/openvino/runtime/__init__.py @@ -5,6 +5,27 @@ """openvino module namespace, exposing factory functions for all ops and other classes.""" # noqa: F401 +import warnings +warnings.simplefilter("always", DeprecationWarning) +import inspect +stack = inspect.stack() + +if stack[-1].code_context is None: # python interactive mode + warnings.warn( + "The `openvino.runtime` module is deprecated and will be removed in the 2026.0 release. " + "Please replace `openvino.runtime` with `openvino` after 25.1 release.", + DeprecationWarning, + stacklevel=2 + ) +else: + warnings.warn( + "The `openvino.runtime` module is deprecated and will be removed in the 2026.0 release. " + "Please replace `openvino.runtime` with `openvino` after 25.1 release.\n" + f"{stack[-1].filename}:{stack[-1].lineno}:\n\t{stack[-1].code_context[0]}", + DeprecationWarning, + stacklevel=2 + ) + from openvino._pyopenvino import get_version __version__ = get_version() diff --git a/tools/benchmark_tool/openvino/__init__.py b/tools/benchmark_tool/openvino/__init__.py index 7643f742e0067d..15bf3c6eb9671e 100644 --- a/tools/benchmark_tool/openvino/__init__.py +++ b/tools/benchmark_tool/openvino/__init__.py @@ -59,7 +59,8 @@ from openvino._ov_api import AsyncInferQueue # Import all public modules -from openvino import runtime as runtime +from openvino.package_utils import lazy_import +runtime = lazy_import("openvino.runtime") from openvino import frontend as frontend from openvino import helpers as helpers from openvino import experimental as experimental diff --git a/tools/ovc/openvino/__init__.py b/tools/ovc/openvino/__init__.py index 7643f742e0067d..15bf3c6eb9671e 100644 --- a/tools/ovc/openvino/__init__.py +++ b/tools/ovc/openvino/__init__.py @@ -59,7 +59,8 @@ from openvino._ov_api import AsyncInferQueue # Import all public modules -from openvino import runtime as runtime +from openvino.package_utils import lazy_import +runtime = lazy_import("openvino.runtime") from openvino import frontend as frontend from openvino import helpers as helpers from openvino import experimental as experimental