sherlock-api 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.
- sherlock_api/__init__.py +104 -0
- sherlock_api/batches.py +28 -0
- sherlock_api/cases.py +42 -0
- sherlock_api/client.py +622 -0
- sherlock_api/exceptions.py +110 -0
- sherlock_api/files.py +46 -0
- sherlock_api/images.py +45 -0
- sherlock_api/logs.py +84 -0
- sherlock_api/measurements.py +31 -0
- sherlock_api/process.py +131 -0
- sherlock_api/py.typed +0 -0
- sherlock_api/validation.py +24 -0
- sherlock_api-0.1.0.dist-info/METADATA +218 -0
- sherlock_api-0.1.0.dist-info/RECORD +16 -0
- sherlock_api-0.1.0.dist-info/WHEEL +4 -0
- sherlock_api-0.1.0.dist-info/licenses/LICENSE +202 -0
sherlock_api/__init__.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Python client for the Sherlock REST API.
|
|
2
|
+
|
|
3
|
+
Quickstart::
|
|
4
|
+
|
|
5
|
+
from sherlock_api import SherlockAPIClient, CreateCaseRequest, RobotPlatform
|
|
6
|
+
|
|
7
|
+
with SherlockAPIClient(sherlock_port=8080) as client:
|
|
8
|
+
case = client.post_case(
|
|
9
|
+
CreateCaseRequest("My case", RobotPlatform.UNIVERSAL_ROBOTS, "inspect")
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
When a script is launched by Sherlock itself, the connection details come from
|
|
13
|
+
the ``SHERLOCK_*`` environment variables and ``SherlockAPIClient()`` needs no
|
|
14
|
+
arguments at all.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
21
|
+
|
|
22
|
+
from .batches import CreateBatchRequest
|
|
23
|
+
from .cases import CreateCaseRequest, RobotPlatform
|
|
24
|
+
from .client import DEFAULT_TIMEOUT, DEFAULT_URL, SherlockAPIClient
|
|
25
|
+
from .exceptions import (
|
|
26
|
+
SherlockAPIError,
|
|
27
|
+
SherlockBadRequestError,
|
|
28
|
+
SherlockConfigurationError,
|
|
29
|
+
SherlockError,
|
|
30
|
+
SherlockNotFoundError,
|
|
31
|
+
SherlockServerError,
|
|
32
|
+
SherlockTimeoutError,
|
|
33
|
+
)
|
|
34
|
+
from .files import guess_extension_by_magic
|
|
35
|
+
from .images import CreateImageRequest, DecisionClass
|
|
36
|
+
from .logs import (
|
|
37
|
+
CreateBatchLogRequest,
|
|
38
|
+
CreateCaseLogRequest,
|
|
39
|
+
CreateImageLogRequest,
|
|
40
|
+
LogRequest,
|
|
41
|
+
LogType,
|
|
42
|
+
)
|
|
43
|
+
from .measurements import CreateMeasurementRequest
|
|
44
|
+
from .process import (
|
|
45
|
+
CreateNotificationRequest,
|
|
46
|
+
CreateProcessModalDialogRequest,
|
|
47
|
+
DialogResult,
|
|
48
|
+
DialogType,
|
|
49
|
+
Language,
|
|
50
|
+
NotificationAttachment,
|
|
51
|
+
ProcessState,
|
|
52
|
+
)
|
|
53
|
+
from .validation import is_valid_uuid32
|
|
54
|
+
|
|
55
|
+
try:
|
|
56
|
+
__version__ = version("sherlock-api")
|
|
57
|
+
except PackageNotFoundError: # pragma: no cover - running from a source tree
|
|
58
|
+
__version__ = "0.0.0.dev0"
|
|
59
|
+
|
|
60
|
+
# A library should not configure logging for its host application.
|
|
61
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
62
|
+
|
|
63
|
+
__all__ = [
|
|
64
|
+
"__version__",
|
|
65
|
+
# Client
|
|
66
|
+
"SherlockAPIClient",
|
|
67
|
+
"DEFAULT_URL",
|
|
68
|
+
"DEFAULT_TIMEOUT",
|
|
69
|
+
# Exceptions
|
|
70
|
+
"SherlockError",
|
|
71
|
+
"SherlockConfigurationError",
|
|
72
|
+
"SherlockAPIError",
|
|
73
|
+
"SherlockBadRequestError",
|
|
74
|
+
"SherlockNotFoundError",
|
|
75
|
+
"SherlockTimeoutError",
|
|
76
|
+
"SherlockServerError",
|
|
77
|
+
# Cases
|
|
78
|
+
"CreateCaseRequest",
|
|
79
|
+
"RobotPlatform",
|
|
80
|
+
# Batches
|
|
81
|
+
"CreateBatchRequest",
|
|
82
|
+
# Images
|
|
83
|
+
"CreateImageRequest",
|
|
84
|
+
"DecisionClass",
|
|
85
|
+
# Logs
|
|
86
|
+
"LogType",
|
|
87
|
+
"LogRequest",
|
|
88
|
+
"CreateCaseLogRequest",
|
|
89
|
+
"CreateBatchLogRequest",
|
|
90
|
+
"CreateImageLogRequest",
|
|
91
|
+
# Measurements
|
|
92
|
+
"CreateMeasurementRequest",
|
|
93
|
+
# Processes
|
|
94
|
+
"ProcessState",
|
|
95
|
+
"DialogType",
|
|
96
|
+
"DialogResult",
|
|
97
|
+
"Language",
|
|
98
|
+
"CreateProcessModalDialogRequest",
|
|
99
|
+
"CreateNotificationRequest",
|
|
100
|
+
"NotificationAttachment",
|
|
101
|
+
# Helpers
|
|
102
|
+
"guess_extension_by_magic",
|
|
103
|
+
"is_valid_uuid32",
|
|
104
|
+
]
|
sherlock_api/batches.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Request models for Sherlock batches."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
__all__ = ["CreateBatchRequest"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass
|
|
12
|
+
class CreateBatchRequest:
|
|
13
|
+
"""Payload for :meth:`sherlock_api.SherlockAPIClient.post_batch`.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
case_id: Id of the case the batch belongs to.
|
|
17
|
+
batch_name: Human-readable name of the batch.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
case_id: str
|
|
21
|
+
batch_name: str
|
|
22
|
+
|
|
23
|
+
def to_dict(self) -> dict[str, Any]:
|
|
24
|
+
"""Serialize to the JSON body expected by ``POST /batch``."""
|
|
25
|
+
return {
|
|
26
|
+
"case_id": self.case_id,
|
|
27
|
+
"batch_name": self.batch_name,
|
|
28
|
+
}
|
sherlock_api/cases.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Request models for Sherlock cases."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from enum import Enum
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
__all__ = ["RobotPlatform", "CreateCaseRequest"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class RobotPlatform(Enum):
|
|
13
|
+
"""Robot platform a case runs on."""
|
|
14
|
+
|
|
15
|
+
UNIVERSAL_ROBOTS = "UniversalRobots"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass
|
|
19
|
+
class CreateCaseRequest:
|
|
20
|
+
"""Payload for :meth:`sherlock_api.SherlockAPIClient.post_case`.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
case_name: Human-readable name of the case.
|
|
24
|
+
robot_platform: Platform the case's procedure targets.
|
|
25
|
+
robot_procedure: Hash of the robot procedure to run.
|
|
26
|
+
thumbnail: Optional file hash of a thumbnail image, as returned by
|
|
27
|
+
:meth:`~sherlock_api.SherlockAPIClient.post_file`.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
case_name: str
|
|
31
|
+
robot_platform: RobotPlatform
|
|
32
|
+
robot_procedure: str
|
|
33
|
+
thumbnail: str | None = None
|
|
34
|
+
|
|
35
|
+
def to_dict(self) -> dict[str, Any]:
|
|
36
|
+
"""Serialize to the JSON body expected by ``POST /case``."""
|
|
37
|
+
return {
|
|
38
|
+
"case_name": self.case_name,
|
|
39
|
+
"robot_platform": self.robot_platform.value,
|
|
40
|
+
"robot_procedure": self.robot_procedure,
|
|
41
|
+
"thumbnail": self.thumbnail,
|
|
42
|
+
}
|