Skip to content

Commit 06588bb

Browse files
authored
Enhance docstrings (#38)
1 parent cd8473b commit 06588bb

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

pythonkuma/uptimekuma.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,19 @@ def __init__(
2727
api_key: str | None = None,
2828
timeout: float | None = None,
2929
) -> None:
30-
"""Initialize the Uptime Kuma client."""
30+
"""Initialize the Uptime Kuma client.
31+
32+
Parameters
33+
----------
34+
session : ClientSession
35+
An aiohttp ClientSession instance
36+
base_url : URL or str
37+
The base URL of the Uptime Kuma server
38+
api_key : str or None, optional
39+
API key for authentication (default is None).
40+
timeout : float or None, optional
41+
Request timeout in seconds (default is 10 seconds if not specified).
42+
"""
3143
self._base_url = base_url if isinstance(base_url, URL) else URL(base_url)
3244

3345
self._auth = BasicAuth("", api_key) if api_key else None
@@ -36,7 +48,27 @@ def __init__(
3648
self._session = session
3749

3850
async def metrics(self) -> dict[str, UptimeKumaMonitor]:
39-
"""Retrieve metrics from Uptime Kuma."""
51+
"""Retrieve metrics from Uptime Kuma.
52+
53+
Fetches and parses Prometheus-style metrics from the Uptime Kuma API endpoint,
54+
extracting monitor-related metrics and returning them as a dictionary of
55+
UptimeKumaMonitor objects keyed by monitor name.
56+
57+
Returns
58+
-------
59+
dict[str, UptimeKumaMonitor]
60+
A dictionary mapping monitor names to their corresponding UptimeKumaMonitor
61+
objects.
62+
63+
Raises
64+
------
65+
UptimeKumaAuthenticationException
66+
If authentication with the Uptime Kuma API fails.
67+
UptimeKumaConnectionException
68+
If there is a connection error, timeout, or other client error during the
69+
request.
70+
"""
71+
monitors: dict[str, dict[str, Any]] = {}
4072
url = self._base_url / "metrics"
4173

4274
try:
@@ -56,10 +88,7 @@ async def metrics(self) -> dict[str, UptimeKumaMonitor]:
5688
except ClientError as e:
5789
raise UptimeKumaConnectionException from e
5890
else:
59-
parsed = text_string_to_metric_families(await request.text())
60-
61-
monitors: dict[str, dict[str, Any]] = {}
62-
for metric in parsed:
91+
for metric in text_string_to_metric_families(await request.text()):
6392
if not metric.name.startswith("monitor"):
6493
continue
6594
for sample in metric.samples:

0 commit comments

Comments
 (0)