OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[Py OV] Add deprecation warning for runtime module (#27694)
Alicja Miloszewska2b442b43689e
diff --git a/src/bindings/python/src/openvino/__init__.py b/src/bindings/python/src/openvino/__init__.pyindex 70b5f372352..b916a6e1c9b 100644--- a/src/bindings/python/src/openvino/__init__.py+++ b/src/bindings/python/src/openvino/__init__.py@@ -60,7 +60,8 @@ from openvino._ov_api import AsyncInferQueuefrom openvino._ov_api import Op# 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 frontendfrom openvino import helpers as helpersfrom openvino import experimental as experimentaldiff --git a/src/bindings/python/src/openvino/package_utils.py b/src/bindings/python/src/openvino/package_utils.pyindex a863ef9ea7b..feafc35c5ae 100644--- a/src/bindings/python/src/openvino/package_utils.py+++ b/src/bindings/python/src/openvino/package_utils.py@@ -7,6 +7,8 @@ import sysfrom functools import wrapsfrom typing import Callable, Anyfrom pathlib import Path+import importlib.util+from types import ModuleTypedef _add_openvino_libs_to_search_path() -> None:@@ -113,3 +115,19 @@ def deprecatedclassproperty(name: Any = None, version: str = "", message: str =_patch(func, deprecated(name, version, message, stacklevel))return funcreturn 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++ try:+ loader.exec_module(module)+ except Exception as e:+ raise ImportError(f"Failed to load module {module_name}") from e+ return modulediff --git a/src/bindings/python/src/openvino/runtime/__init__.py b/src/bindings/python/src/openvino/runtime/__init__.pyindex ef985c66859..431689eee27 100644--- a/src/bindings/python/src/openvino/runtime/__init__.py+++ b/src/bindings/python/src/openvino/runtime/__init__.py@@ -5,6 +5,16 @@"""openvino module namespace, exposing factory functions for all ops and other classes."""# noqa: F401+import warnings+warnings.simplefilter("always", DeprecationWarning)+warnings.warn(+ "The `openvino.runtime` module is deprecated and will be removed in the 2026.0 release. "+ "Please replace `openvino.runtime` with `openvino`.",+ DeprecationWarning,+ stacklevel=2+)++from openvino._pyopenvino import get_version__version__ = get_version()diff --git a/src/bindings/python/tests/test_runtime/test_deprecated_runtime.py b/src/bindings/python/tests/test_runtime/test_deprecated_runtime.pyindex 05d78e850cc..2ae4ee1b0d1 100644--- a/src/bindings/python/tests/test_runtime/test_deprecated_runtime.py+++ b/src/bindings/python/tests/test_runtime/test_deprecated_runtime.py@@ -6,9 +6,12 @@ import pytestimport numpy as npfrom pathlib import Pathfrom contextlib import nullcontext as does_not_raise+import warnings+with pytest.warns(DeprecationWarning, match="The `openvino.runtime` module is deprecated and will be removed in the 2026.0 release."):+ import openvino.runtime as ov-import openvino.runtime as ov+import openvino.runtime.opset13 as opsfrom openvino.runtime import (Model,Core,@@ -19,8 +22,6 @@ from openvino.runtime import (serialize,Type,)--import openvino.runtime.opset13 as opsimport openvino.runtime.opset8 as ops8from openvino.runtime.op import Constant, Parameterfrom openvino.runtime import Extension@@ -42,6 +43,17 @@ from tests.utils.helpers import ()+def test_no_warning():+ with warnings.catch_warnings(record=True) as w:+ import openvino++ data = np.array([1, 2, 3])+ axis_vector = openvino.AxisVector(data)+ assert np.equal(axis_vector, data).all()++ assert len(w) == 0 # No warning++# request - https://docs.pytest.org/en/7.1.x/reference/reference.html#requestdef test_read_model_from_ir(request, tmp_path):core = Core()diff --git a/tools/benchmark_tool/openvino/__init__.py b/tools/benchmark_tool/openvino/__init__.pyindex 70b5f372352..b916a6e1c9b 100644--- a/tools/benchmark_tool/openvino/__init__.py+++ b/tools/benchmark_tool/openvino/__init__.py@@ -60,7 +60,8 @@ from openvino._ov_api import AsyncInferQueuefrom openvino._ov_api import Op# 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 frontendfrom openvino import helpers as helpersfrom openvino import experimental as experimentaldiff --git a/tools/ovc/openvino/__init__.py b/tools/ovc/openvino/__init__.pyindex 70b5f372352..b916a6e1c9b 100644--- a/tools/ovc/openvino/__init__.py+++ b/tools/ovc/openvino/__init__.py@@ -60,7 +60,8 @@ from openvino._ov_api import AsyncInferQueuefrom openvino._ov_api import Op# 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 frontendfrom openvino import helpers as helpersfrom openvino import experimental as experimental