solidping 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- solidping/__init__.py +29 -0
- solidping/_client.py +175 -0
- solidping/_errors.py +88 -0
- solidping/_generated/__init__.py +5 -0
- solidping/_generated/models.py +7140 -0
- solidping/_generated/operations.py +3247 -0
- solidping/_model.py +90 -0
- solidping/_operation.py +20 -0
- solidping/_pagination.py +32 -0
- solidping/_retry.py +74 -0
- solidping/py.typed +0 -0
- solidping/resources/__init__.py +0 -0
- solidping/resources/_base.py +56 -0
- solidping/resources/channels.py +24 -0
- solidping/resources/checks.py +34 -0
- solidping/resources/incidents.py +31 -0
- solidping/resources/maintenance_windows.py +24 -0
- solidping/resources/status_pages.py +24 -0
- solidping-0.1.0.dist-info/METADATA +134 -0
- solidping-0.1.0.dist-info/RECORD +22 -0
- solidping-0.1.0.dist-info/WHEEL +4 -0
- solidping-0.1.0.dist-info/licenses/LICENSE +21 -0
solidping/_model.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Base class of the generated models.
|
|
2
|
+
|
|
3
|
+
A model is a plain object whose attributes are the API field names. It is built from a decoded
|
|
4
|
+
JSON dict, keeps the fields it does not know (forward compatibility, see ``to_dict``) and never
|
|
5
|
+
validates values, so an unknown enum value is accepted as is.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import sys
|
|
11
|
+
from typing import Any, ClassVar, Self
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Model:
|
|
15
|
+
# wire name -> attribute name, only when they differ (Python keywords, odd characters)
|
|
16
|
+
_aliases: ClassVar[dict[str, str]] = {}
|
|
17
|
+
# wire name -> (kind, model class name), kind is "one", "list" or "map"
|
|
18
|
+
_nested: ClassVar[dict[str, tuple[str, str]]] = {}
|
|
19
|
+
# wire names of the declared fields
|
|
20
|
+
_fields: ClassVar[tuple[str, ...]] = ()
|
|
21
|
+
|
|
22
|
+
def __init__(self, **data: Any) -> None:
|
|
23
|
+
self._extra: dict[str, Any] = {}
|
|
24
|
+
for key, value in data.items():
|
|
25
|
+
self._set(key, value)
|
|
26
|
+
|
|
27
|
+
@classmethod
|
|
28
|
+
def from_dict(cls, data: dict[str, Any]) -> Self:
|
|
29
|
+
return cls(**data)
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def _resolve(cls, name: str) -> type[Model]:
|
|
33
|
+
return getattr(sys.modules[cls.__module__], name)
|
|
34
|
+
|
|
35
|
+
def _set(self, key: str, value: Any) -> None:
|
|
36
|
+
if key not in self._fields:
|
|
37
|
+
self._extra[key] = value
|
|
38
|
+
return
|
|
39
|
+
nested = self._nested.get(key)
|
|
40
|
+
if nested is not None and value is not None:
|
|
41
|
+
kind, name = nested
|
|
42
|
+
model = self._resolve(name)
|
|
43
|
+
if kind == "one" and isinstance(value, dict):
|
|
44
|
+
value = model.from_dict(value)
|
|
45
|
+
elif kind == "list" and isinstance(value, list):
|
|
46
|
+
value = [model.from_dict(v) if isinstance(v, dict) else v for v in value]
|
|
47
|
+
elif kind == "map" and isinstance(value, dict):
|
|
48
|
+
value = {
|
|
49
|
+
k: model.from_dict(v) if isinstance(v, dict) else v for k, v in value.items()
|
|
50
|
+
}
|
|
51
|
+
setattr(self, self._aliases.get(key, key), value)
|
|
52
|
+
|
|
53
|
+
def __getattr__(self, name: str) -> Any:
|
|
54
|
+
# Only reached when normal lookup fails: serve the unknown fields of the response.
|
|
55
|
+
if name.startswith("_"):
|
|
56
|
+
raise AttributeError(name)
|
|
57
|
+
extra = self.__dict__.get("_extra", {})
|
|
58
|
+
if name in extra:
|
|
59
|
+
return extra[name]
|
|
60
|
+
raise AttributeError(f"{type(self).__name__!r} object has no attribute {name!r}")
|
|
61
|
+
|
|
62
|
+
def to_dict(self) -> dict[str, Any]:
|
|
63
|
+
"""The model as a JSON-ready dict: the fields that are set, then the unknown ones."""
|
|
64
|
+
out: dict[str, Any] = {}
|
|
65
|
+
for key in self._fields:
|
|
66
|
+
attr = self._aliases.get(key, key)
|
|
67
|
+
if attr in self.__dict__:
|
|
68
|
+
out[key] = _dump(self.__dict__[attr])
|
|
69
|
+
for key, value in self._extra.items():
|
|
70
|
+
out[key] = _dump(value)
|
|
71
|
+
return out
|
|
72
|
+
|
|
73
|
+
def __eq__(self, other: object) -> bool:
|
|
74
|
+
return isinstance(other, type(self)) and self.to_dict() == other.to_dict()
|
|
75
|
+
|
|
76
|
+
__hash__ = None # type: ignore[assignment]
|
|
77
|
+
|
|
78
|
+
def __repr__(self) -> str:
|
|
79
|
+
items = ", ".join(f"{k}={v!r}" for k, v in self.to_dict().items())
|
|
80
|
+
return f"{type(self).__name__}({items})"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _dump(value: Any) -> Any:
|
|
84
|
+
if isinstance(value, Model):
|
|
85
|
+
return value.to_dict()
|
|
86
|
+
if isinstance(value, list):
|
|
87
|
+
return [_dump(v) for v in value]
|
|
88
|
+
if isinstance(value, dict):
|
|
89
|
+
return {k: _dump(v) for k, v in value.items()}
|
|
90
|
+
return value
|
solidping/_operation.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Metadata of an API operation, filled in by the generated ``_generated/operations.py``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True, slots=True)
|
|
9
|
+
class Operation:
|
|
10
|
+
operation_id: str
|
|
11
|
+
method: str
|
|
12
|
+
# Path template, with ``{org}`` and the other path parameters.
|
|
13
|
+
path: str
|
|
14
|
+
path_params: tuple[str, ...] = ()
|
|
15
|
+
query_params: tuple[str, ...] = ()
|
|
16
|
+
request_model: str | None = None
|
|
17
|
+
# Model of the successful response; ``None`` when there is no body (204).
|
|
18
|
+
response_model: str | None = None
|
|
19
|
+
# For a list operation, the model of the items of ``data``.
|
|
20
|
+
item_model: str | None = None
|
solidping/_pagination.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Iteration over a paginated list."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Iterator
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def paginate(
|
|
10
|
+
fetch: Callable[[dict[str, Any]], dict[str, Any]],
|
|
11
|
+
query: dict[str, Any],
|
|
12
|
+
) -> Iterator[Any]:
|
|
13
|
+
"""Yield the items of ``data`` page after page.
|
|
14
|
+
|
|
15
|
+
``fetch(query)`` returns one decoded page. The next page is requested with
|
|
16
|
+
``pagination.cursor`` verbatim. The API returns a cursor even on the last page, so the cursor
|
|
17
|
+
is not a stop signal: iteration ends on an empty page, on a page shorter than the requested
|
|
18
|
+
``size``, when there is no cursor (lists that are not paginated) or when it does not move.
|
|
19
|
+
"""
|
|
20
|
+
query = dict(query)
|
|
21
|
+
size = query.get("size") or query.get("limit")
|
|
22
|
+
while True:
|
|
23
|
+
page = fetch(query)
|
|
24
|
+
items = page.get("data") or []
|
|
25
|
+
yield from items
|
|
26
|
+
pagination = page.get("pagination") or {}
|
|
27
|
+
cursor = pagination.get("cursor")
|
|
28
|
+
if not items or not cursor or cursor == query.get("cursor"):
|
|
29
|
+
return
|
|
30
|
+
if isinstance(size, int) and len(items) < size:
|
|
31
|
+
return
|
|
32
|
+
query["cursor"] = cursor
|
solidping/_retry.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Retry policy: exponential backoff with jitter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import random
|
|
6
|
+
import time
|
|
7
|
+
from collections.abc import Callable
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
|
|
11
|
+
# Never wait longer than this for a Retry-After, whatever the server says.
|
|
12
|
+
MAX_RETRY_AFTER = 60.0
|
|
13
|
+
BASE_DELAY = 0.5
|
|
14
|
+
MAX_DELAY = 8.0
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def is_retryable(method: str, status: int) -> bool:
|
|
18
|
+
"""429 is always retried; 5xx only for methods that are safe to repeat.
|
|
19
|
+
|
|
20
|
+
The API has no idempotency key, so a POST that failed after the server received it must not be
|
|
21
|
+
sent again: only a 429 (the request was refused before any work) is retried for it.
|
|
22
|
+
"""
|
|
23
|
+
if status == 429:
|
|
24
|
+
return True
|
|
25
|
+
return status >= 500 and method.upper() != "POST"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def retry_delay(attempt: int, response: httpx.Response | None) -> float:
|
|
29
|
+
"""Seconds to wait before retry number ``attempt + 1`` (``attempt`` starts at 0)."""
|
|
30
|
+
if response is not None and response.status_code == 429:
|
|
31
|
+
retry_after = response.headers.get("Retry-After", "")
|
|
32
|
+
try:
|
|
33
|
+
return min(max(float(retry_after), 0.0), MAX_RETRY_AFTER)
|
|
34
|
+
except ValueError:
|
|
35
|
+
pass
|
|
36
|
+
delay = min(BASE_DELAY * 2**attempt, MAX_DELAY)
|
|
37
|
+
return delay * random.uniform(0.5, 1.0)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def sleep(seconds: float) -> None:
|
|
41
|
+
time.sleep(seconds)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def send_with_retries(
|
|
45
|
+
send: Callable[[], httpx.Response],
|
|
46
|
+
method: str,
|
|
47
|
+
max_retries: int,
|
|
48
|
+
on_retry: Callable[[int, str], None] | None = None,
|
|
49
|
+
) -> httpx.Response:
|
|
50
|
+
"""Call ``send`` until it succeeds or the retries are used up.
|
|
51
|
+
|
|
52
|
+
Connection errors and timeouts raise ``httpx.TransportError`` after the last attempt; a
|
|
53
|
+
retryable status is returned as is after the last attempt.
|
|
54
|
+
"""
|
|
55
|
+
attempt = 0
|
|
56
|
+
while True:
|
|
57
|
+
try:
|
|
58
|
+
response = send()
|
|
59
|
+
except httpx.TransportError:
|
|
60
|
+
# A POST is not retried on connection errors either: the server may have received it.
|
|
61
|
+
if attempt >= max_retries or method.upper() == "POST":
|
|
62
|
+
raise
|
|
63
|
+
if on_retry:
|
|
64
|
+
on_retry(attempt, "connection error")
|
|
65
|
+
sleep(retry_delay(attempt, None))
|
|
66
|
+
attempt += 1
|
|
67
|
+
continue
|
|
68
|
+
if attempt < max_retries and is_retryable(method, response.status_code):
|
|
69
|
+
if on_retry:
|
|
70
|
+
on_retry(attempt, f"status {response.status_code}")
|
|
71
|
+
sleep(retry_delay(attempt, response))
|
|
72
|
+
attempt += 1
|
|
73
|
+
continue
|
|
74
|
+
return response
|
solidping/py.typed
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Shared plumbing of the resources: one attribute of the client per API resource.
|
|
2
|
+
|
|
3
|
+
Operation ids come from the generated table (``_generated/operations.py``), which also says which
|
|
4
|
+
model a response is wrapped in, so a spec bump that renames an operation fails loudly (a test
|
|
5
|
+
checks that every id used here exists).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Iterator
|
|
11
|
+
from typing import TYPE_CHECKING, Any
|
|
12
|
+
|
|
13
|
+
from solidping._generated import models
|
|
14
|
+
from solidping._generated.operations import OPERATIONS
|
|
15
|
+
from solidping._model import Model
|
|
16
|
+
from solidping._pagination import paginate
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from solidping._client import SolidPing
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def wrap(model_name: str | None, data: Any) -> Any:
|
|
23
|
+
"""Wrap a decoded response in its generated model (the raw value if there is none)."""
|
|
24
|
+
if model_name is None or not isinstance(data, dict):
|
|
25
|
+
return data
|
|
26
|
+
return getattr(models, model_name).from_dict(data)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class Resource:
|
|
30
|
+
def __init__(self, client: SolidPing) -> None:
|
|
31
|
+
self._client = client
|
|
32
|
+
|
|
33
|
+
def _call(
|
|
34
|
+
self,
|
|
35
|
+
operation_id: str,
|
|
36
|
+
id: str | None = None,
|
|
37
|
+
params: dict[str, Any] | None = None,
|
|
38
|
+
body: dict[str, Any] | None = None,
|
|
39
|
+
) -> Any:
|
|
40
|
+
"""Call one operation; ``id`` fills the path parameter that follows the org."""
|
|
41
|
+
op = OPERATIONS[operation_id]
|
|
42
|
+
path_args = {}
|
|
43
|
+
if id is not None:
|
|
44
|
+
path_args[next(p for p in op.path_params if p != "org")] = id
|
|
45
|
+
data = self._client._call(operation_id, path_args, params, body)
|
|
46
|
+
return wrap(op.response_model, data)
|
|
47
|
+
|
|
48
|
+
def _iter(self, operation_id: str, **query: Any) -> Iterator[Model]:
|
|
49
|
+
"""Iterate a list operation, following the pagination cursor."""
|
|
50
|
+
item_model = OPERATIONS[operation_id].item_model
|
|
51
|
+
|
|
52
|
+
def fetch(q: dict[str, Any]) -> dict[str, Any]:
|
|
53
|
+
return self._client._call(operation_id, None, q) or {}
|
|
54
|
+
|
|
55
|
+
for item in paginate(fetch, query):
|
|
56
|
+
yield wrap(item_model, item)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from solidping._generated.models import Channel
|
|
7
|
+
from solidping.resources._base import Resource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Channels(Resource):
|
|
11
|
+
def list(self, **query: Any) -> Iterator[Channel]:
|
|
12
|
+
return self._iter("listChannels", **query)
|
|
13
|
+
|
|
14
|
+
def get(self, id: str, **query: Any) -> Channel:
|
|
15
|
+
return self._call("getChannel", id, query)
|
|
16
|
+
|
|
17
|
+
def create(self, **body: Any) -> Channel:
|
|
18
|
+
return self._call("createChannel", body=body)
|
|
19
|
+
|
|
20
|
+
def update(self, id: str, **body: Any) -> Channel:
|
|
21
|
+
return self._call("updateChannel", id, body=body)
|
|
22
|
+
|
|
23
|
+
def delete(self, id: str) -> None:
|
|
24
|
+
self._call("deleteChannel", id)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from solidping._generated.models import Check, CheckListItem, RunNowResponse
|
|
7
|
+
from solidping.resources._base import Resource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Checks(Resource):
|
|
11
|
+
def list(self, **query: Any) -> Iterator[CheckListItem]:
|
|
12
|
+
"""Iterate the checks. Query: ``status``, ``labels``, ``with``, ``internal``, ``sort``."""
|
|
13
|
+
return self._iter("listChecks", **query)
|
|
14
|
+
|
|
15
|
+
def get(self, id: str, **query: Any) -> Check:
|
|
16
|
+
"""One check, by uid or slug."""
|
|
17
|
+
return self._call("getCheck", id, query)
|
|
18
|
+
|
|
19
|
+
def create(self, **body: Any) -> Check:
|
|
20
|
+
return self._call("createCheck", body=body)
|
|
21
|
+
|
|
22
|
+
def upsert(self, slug: str, **body: Any) -> Check:
|
|
23
|
+
"""Create the check with this slug, or replace it if it exists."""
|
|
24
|
+
return self._call("upsertCheck", slug, body=body)
|
|
25
|
+
|
|
26
|
+
def update(self, id: str, **body: Any) -> Check:
|
|
27
|
+
return self._call("updateCheck", id, body=body)
|
|
28
|
+
|
|
29
|
+
def delete(self, id: str) -> None:
|
|
30
|
+
self._call("deleteCheck", id)
|
|
31
|
+
|
|
32
|
+
def run_now(self, id: str) -> RunNowResponse:
|
|
33
|
+
"""Ask for an immediate run of the check."""
|
|
34
|
+
return self._call("runCheckNow", id)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from solidping._generated.models import IncidentDetail
|
|
7
|
+
from solidping.resources._base import Resource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Incidents(Resource):
|
|
11
|
+
def list(self, **query: Any) -> Iterator[IncidentDetail]:
|
|
12
|
+
"""Iterate the incidents. Query: ``state``, ``kind``, ``checkUid``, ``size``, ``order``."""
|
|
13
|
+
return self._iter("listIncidents", **query)
|
|
14
|
+
|
|
15
|
+
def get(self, id: str, **query: Any) -> IncidentDetail:
|
|
16
|
+
return self._call("getIncident", id, query)
|
|
17
|
+
|
|
18
|
+
def acknowledge(self, id: str, **body: Any) -> IncidentDetail:
|
|
19
|
+
return self._call("acknowledgeIncident", id, body=body or None)
|
|
20
|
+
|
|
21
|
+
def unacknowledge(self, id: str) -> IncidentDetail:
|
|
22
|
+
return self._call("unacknowledgeIncident", id)
|
|
23
|
+
|
|
24
|
+
def snooze(self, id: str, **body: Any) -> IncidentDetail:
|
|
25
|
+
return self._call("snoozeIncident", id, body=body)
|
|
26
|
+
|
|
27
|
+
def unsnooze(self, id: str) -> IncidentDetail:
|
|
28
|
+
return self._call("unsnoozeIncident", id)
|
|
29
|
+
|
|
30
|
+
def resolve(self, id: str, **body: Any) -> IncidentDetail:
|
|
31
|
+
return self._call("resolveIncident", id, body=body or None)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from solidping._generated.models import MaintenanceWindow
|
|
7
|
+
from solidping.resources._base import Resource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MaintenanceWindows(Resource):
|
|
11
|
+
def list(self, **query: Any) -> Iterator[MaintenanceWindow]:
|
|
12
|
+
return self._iter("listMaintenanceWindows", **query)
|
|
13
|
+
|
|
14
|
+
def get(self, id: str, **query: Any) -> MaintenanceWindow:
|
|
15
|
+
return self._call("getMaintenanceWindow", id, query)
|
|
16
|
+
|
|
17
|
+
def create(self, **body: Any) -> MaintenanceWindow:
|
|
18
|
+
return self._call("createMaintenanceWindow", body=body)
|
|
19
|
+
|
|
20
|
+
def update(self, id: str, **body: Any) -> MaintenanceWindow:
|
|
21
|
+
return self._call("updateMaintenanceWindow", id, body=body)
|
|
22
|
+
|
|
23
|
+
def delete(self, id: str) -> None:
|
|
24
|
+
self._call("deleteMaintenanceWindow", id)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from solidping._generated.models import StatusPage
|
|
7
|
+
from solidping.resources._base import Resource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class StatusPages(Resource):
|
|
11
|
+
def list(self, **query: Any) -> Iterator[StatusPage]:
|
|
12
|
+
return self._iter("listStatusPages", **query)
|
|
13
|
+
|
|
14
|
+
def get(self, id: str, **query: Any) -> StatusPage:
|
|
15
|
+
return self._call("getStatusPage", id, query)
|
|
16
|
+
|
|
17
|
+
def create(self, **body: Any) -> StatusPage:
|
|
18
|
+
return self._call("createStatusPage", body=body)
|
|
19
|
+
|
|
20
|
+
def update(self, id: str, **body: Any) -> StatusPage:
|
|
21
|
+
return self._call("updateStatusPage", id, body=body)
|
|
22
|
+
|
|
23
|
+
def delete(self, id: str) -> None:
|
|
24
|
+
self._call("deleteStatusPage", id)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: solidping
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for SolidPing
|
|
5
|
+
Project-URL: Homepage, https://www.solidping.io
|
|
6
|
+
Project-URL: Repository, https://github.com/fclairamb/solidping-python
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Typing :: Typed
|
|
11
|
+
Requires-Python: >=3.14
|
|
12
|
+
Requires-Dist: httpx>=0.28
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
# SolidPing Python SDK
|
|
16
|
+
|
|
17
|
+
Official Python SDK for [SolidPing](https://www.solidping.io): manage checks, incidents and status
|
|
18
|
+
pages from Python without writing HTTP calls.
|
|
19
|
+
|
|
20
|
+
Work in progress, not published yet. The target is described in
|
|
21
|
+
[fclairamb/solidping#1117](https://github.com/fclairamb/solidping/issues/1117).
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install solidping
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Python 3.14 or later. The only dependency is `httpx`; the client is synchronous.
|
|
30
|
+
|
|
31
|
+
## Quickstart
|
|
32
|
+
|
|
33
|
+
Create a personal access token in SolidPing and export it:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
export SOLIDPING_TOKEN=pat_...
|
|
37
|
+
export SOLIDPING_ORG=acme
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from solidping import SolidPing
|
|
42
|
+
|
|
43
|
+
sp = SolidPing() # reads SOLIDPING_URL, SOLIDPING_ORG, SOLIDPING_TOKEN
|
|
44
|
+
|
|
45
|
+
# Create a check
|
|
46
|
+
check = sp.checks.create(name="Website", config={"url": "https://acme.com"})
|
|
47
|
+
print(check.slug, check.status)
|
|
48
|
+
|
|
49
|
+
# List the checks that are down
|
|
50
|
+
for check in sp.checks.list(status="down"):
|
|
51
|
+
print(check.name)
|
|
52
|
+
|
|
53
|
+
# Acknowledge every open incident
|
|
54
|
+
for incident in sp.incidents.list(state="active"):
|
|
55
|
+
sp.incidents.acknowledge(incident.uid)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Configuration
|
|
59
|
+
|
|
60
|
+
Each setting is an argument of `SolidPing(...)` or an environment variable:
|
|
61
|
+
|
|
62
|
+
| Argument | Environment | Default |
|
|
63
|
+
|---------------|-------------------|-----------------------|
|
|
64
|
+
| `url` | `SOLIDPING_URL` | `https://solidping.io` |
|
|
65
|
+
| `org` | `SOLIDPING_ORG` | required |
|
|
66
|
+
| `token` | `SOLIDPING_TOKEN` | required |
|
|
67
|
+
| `timeout` | | 30 (seconds) |
|
|
68
|
+
| `max_retries` | | 2 |
|
|
69
|
+
|
|
70
|
+
The client is also a context manager (`with SolidPing() as sp:`) and has a `close()` method.
|
|
71
|
+
|
|
72
|
+
## Resources
|
|
73
|
+
|
|
74
|
+
`sp.checks`, `sp.incidents`, `sp.status_pages`, `sp.maintenance_windows` and `sp.channels`.
|
|
75
|
+
Their methods are `list`, `get`, `create`, `update` and `delete` where the API has them, plus the
|
|
76
|
+
actions of the resource: `sp.checks.run_now(id)`, `sp.incidents.acknowledge(id)`,
|
|
77
|
+
`unacknowledge`, `snooze`, `unsnooze` and `resolve`.
|
|
78
|
+
|
|
79
|
+
Arguments are the API field names, unchanged (`sp.checks.create(name=..., config=...)`), and the
|
|
80
|
+
organization is never an argument. Results are objects with the API field names as attributes
|
|
81
|
+
and a `to_dict()` method. `list` returns an iterator that follows the pagination cursor for you.
|
|
82
|
+
A field the SDK does not know yet is kept (`to_dict()` returns it, and it is readable as an
|
|
83
|
+
attribute), and an unknown enum value, such as a plugin check type, is accepted.
|
|
84
|
+
|
|
85
|
+
## Errors
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
import solidping
|
|
89
|
+
from solidping import SolidPing
|
|
90
|
+
|
|
91
|
+
sp = SolidPing(url="https://solidping.acme.com", org="acme", token="...", timeout=10, max_retries=0)
|
|
92
|
+
|
|
93
|
+
try:
|
|
94
|
+
sp.checks.get("missing")
|
|
95
|
+
except solidping.NotFoundError:
|
|
96
|
+
print("no such check")
|
|
97
|
+
except solidping.APIError as e:
|
|
98
|
+
print(e.status, e.code, e.title, e.detail)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Everything the SDK raises is a `SolidPingError`. An `APIError` carries `status`, `code`, `title`,
|
|
102
|
+
`detail` and `fields` (the invalid fields of a validation error). The subclasses are
|
|
103
|
+
`AuthenticationError` (401), `PermissionDeniedError` (403), `NotFoundError` (404),
|
|
104
|
+
`ValidationError` (400, 422), `ConflictError` (409) and `RateLimitError` (429). A status without
|
|
105
|
+
a subclass is a plain `APIError`, whatever its `code`. `APIConnectionError` means the server
|
|
106
|
+
could not be reached, `APITimeoutError` (a subclass of it) that it did not answer in time.
|
|
107
|
+
|
|
108
|
+
## Retries and timeout
|
|
109
|
+
|
|
110
|
+
Connection errors, timeouts, 429 and 5xx are retried twice with exponential backoff and jitter. A
|
|
111
|
+
429 waits for its `Retry-After`. A `POST` is retried only on 429, because the API has no
|
|
112
|
+
idempotency key. `max_retries=0` disables the retries. The timeout is 30 seconds by default.
|
|
113
|
+
|
|
114
|
+
## Endpoints the SDK does not cover
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
regions = sp.request("GET", "/api/v1/orgs/acme/regions")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`request(method, path, body=None, params=None)` uses the same auth, retries and errors, and returns
|
|
121
|
+
the decoded JSON.
|
|
122
|
+
|
|
123
|
+
## Debugging
|
|
124
|
+
|
|
125
|
+
`SOLIDPING_LOG=debug` logs each request and its response status on stderr (through the
|
|
126
|
+
`solidping` logger). The token is never logged.
|
|
127
|
+
|
|
128
|
+
## Development
|
|
129
|
+
|
|
130
|
+
See [AGENTS.md](AGENTS.md).
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
solidping/__init__.py,sha256=AgwvLTSVXatwK_PKNos8NDbpSpJnGqeWGlQnZP-x1OI,588
|
|
2
|
+
solidping/_client.py,sha256=ry_PvoqSjeXT9JIsVl8eYq-7dcippBWEYncMuRMBAM4,6080
|
|
3
|
+
solidping/_errors.py,sha256=XTM5R3ilHDZ5Ao2GSCVoxatcBm6Vt-6tbK6Crm6Kd20,2475
|
|
4
|
+
solidping/_model.py,sha256=1_5ZN9L6-SJx6Iv8ebsuS5DrwCo9IClgzenllb8leEs,3411
|
|
5
|
+
solidping/_operation.py,sha256=G02zmlWOoVmRzlS55QaT6yoHq6w_w9ih1Txd4kmRbP4,666
|
|
6
|
+
solidping/_pagination.py,sha256=GsX-9MTMbPM_1_xosAkvpJPlHRpwHcicD25ELato9xE,1164
|
|
7
|
+
solidping/_retry.py,sha256=Jy8r8-whMDg7sRLuRvFCKHTPcHqtDCD6-XRan3gWkwk,2468
|
|
8
|
+
solidping/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
solidping/_generated/__init__.py,sha256=PaaWZi1R936kEX7iOVcXq8Lw-MRBNpF_DsGo-ERMN-0,173
|
|
10
|
+
solidping/_generated/models.py,sha256=AbtoieaWsRddzLpDdJEoTsN1AoVPuZJU0Jgtmae3xmQ,212845
|
|
11
|
+
solidping/_generated/operations.py,sha256=p1brEXtnJcxBRm_E_JVnSAuxEg0jJaNycbyimJk3IM8,106718
|
|
12
|
+
solidping/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
+
solidping/resources/_base.py,sha256=krkyO54MqVaNVJXkPO_g83KsAcqtIymr3-UgWJs7XIM,2019
|
|
14
|
+
solidping/resources/channels.py,sha256=hpp24duOR94mnKB6XgMFOB-y2uQhDE-2a5PBZxWshZw,726
|
|
15
|
+
solidping/resources/checks.py,sha256=2_kaiolKW8i8tPebzO3EbPDNASWkPKSBC4eEupuKwm0,1221
|
|
16
|
+
solidping/resources/incidents.py,sha256=bgOf4d5weOYV_LDxAPN9kGtTsWZdvDr4_fbyVW-bp3o,1163
|
|
17
|
+
solidping/resources/maintenance_windows.py,sha256=B7QWxlQAm4AmcuPBTfsWNTr1eXX_WJ8O1amqbT5HzbQ,836
|
|
18
|
+
solidping/resources/status_pages.py,sha256=UirGEuQupboHAnX0O9SKtZkVMpgTangKyws0QDVPMOg,759
|
|
19
|
+
solidping-0.1.0.dist-info/METADATA,sha256=EwkNykq-BtU18DaiO_upr9iiEMaLLpMsZHIVJ8pQPWQ,4562
|
|
20
|
+
solidping-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
21
|
+
solidping-0.1.0.dist-info/licenses/LICENSE,sha256=xXNt0qAdq71nil6zyylUkwM52BoZguvu2Jev7dRekbk,1077
|
|
22
|
+
solidping-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Florent Clairambault
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|