Skip to content

Commit 61adf20

Browse files
Implements lazy imports in the prometheus_api_client package's __init__.py(#293)
* Refactored __init__.py to improve imports and maintainability
1 parent 7fa71ec commit 61adf20

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

prometheus_api_client/__init__.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@
33
__title__ = "prometheus-connect"
44
__version__ = "0.6.0"
55

6-
from .prometheus_connect import * # noqa F403
7-
from .metric import Metric # noqa F401
8-
from .metrics_list import MetricsList # noqa F401
9-
from .metric_snapshot_df import MetricSnapshotDataFrame # noqa F401
10-
from .metric_range_df import MetricRangeDataFrame # noqa F401
6+
from .exceptions import PrometheusApiClientException, MetricValueConversionError
7+
def __getattr__(name):
8+
if name == "PrometheusConnect":
9+
from .prometheus_connect import PrometheusConnect
10+
return PrometheusConnect
11+
elif name == "Metric":
12+
from .metric import Metric
13+
return Metric
14+
elif name == "MetricsList":
15+
from .metrics_list import MetricsList
16+
return MetricsList
17+
elif name == "MetricSnapshotDataFrame":
18+
from .metric_snapshot_df import MetricSnapshotDataFrame
19+
return MetricSnapshotDataFrame
20+
elif name == "MetricRangeDataFrame":
21+
from .metric_range_df import MetricRangeDataFrame
22+
return MetricRangeDataFrame
23+
raise AttributeError(f"module {__name__} has no attribute {name}")

0 commit comments

Comments
 (0)