automizor 0.4.9__py3-none-any.whl → 0.4.11__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.
automizor/__init__.py CHANGED
@@ -1 +1 @@
1
- version = "0.4.9"
1
+ version = "0.4.11"
@@ -1,3 +1,5 @@
1
+ from typing import Optional
2
+
1
3
  import requests
2
4
 
3
5
  from automizor.exceptions import AutomizorError
@@ -10,27 +12,21 @@ class DataStore:
10
12
  to manage and manipulate data stored in various formats. It supports
11
13
  operations to retrieve and update data using a unified API.
12
14
 
13
- The class initializes an HTTP session with the necessary headers for
15
+ The class initializes an HTTP request with the necessary headers for
14
16
  authentication, and provides methods to retrieve values, and set values in
15
17
  the store.
16
-
17
- Attributes:
18
- url (str): The base URL for the API endpoint.
19
- token (str): The authentication token for API access.
20
- session (requests.Session): The HTTP session used to make API requests.
21
18
  """
22
19
 
23
20
  _instance = None
24
21
 
22
+ def __init__(self, api_token: Optional[str] = None):
23
+ self.url, self.token = get_api_config(api_token)
24
+ self.headers = get_headers(self.token)
25
+
25
26
  @classmethod
26
- def configure(cls, api_token: str | None = None):
27
+ def configure(cls, api_token: Optional[str] = None):
27
28
  cls._instance = cls(api_token)
28
29
 
29
- def __init__(self, api_token: str | None = None):
30
- self.url, self.token = get_api_config(api_token)
31
- self.session = requests.Session()
32
- self.session.headers.update(get_headers(self.token))
33
-
34
30
  @classmethod
35
31
  def get_instance(cls):
36
32
  if cls._instance is None:
@@ -40,8 +36,8 @@ class DataStore:
40
36
  def get_values(
41
37
  self,
42
38
  name: str,
43
- primary_key: str | None = None,
44
- secondary_key: str | None = None,
39
+ primary_key: Optional[str] = None,
40
+ secondary_key: Optional[str] = None,
45
41
  ) -> JSON:
46
42
  """
47
43
  Retrieves values from the specified data store.
@@ -71,8 +67,8 @@ class DataStore:
71
67
  def _get_values(
72
68
  self,
73
69
  name: str,
74
- primary_key: str | None = None,
75
- secondary_key: str | None = None,
70
+ primary_key: Optional[str] = None,
71
+ secondary_key: Optional[str] = None,
76
72
  ) -> JSON:
77
73
  params = (
78
74
  {"primary_key": primary_key, "secondary_key": secondary_key}
@@ -81,7 +77,9 @@ class DataStore:
81
77
  )
82
78
  url = f"https://{self.url}/api/v1/workflow/datastore/{name}/values/"
83
79
  try:
84
- response = self.session.get(url, timeout=10, params=params)
80
+ response = requests.get(
81
+ url, headers=self.headers, params=params, timeout=10
82
+ )
85
83
  response.raise_for_status()
86
84
  return response.json()
87
85
  except requests.HTTPError as exc:
@@ -94,7 +92,7 @@ class DataStore:
94
92
  def _set_values(self, name: str, values: JSON) -> None:
95
93
  url = f"https://{self.url}/api/v1/workflow/datastore/{name}/values/"
96
94
  try:
97
- response = self.session.post(url, json=values, timeout=10)
95
+ response = requests.post(url, headers=self.headers, json=values, timeout=10)
98
96
  response.raise_for_status()
99
97
  except requests.HTTPError as exc:
100
98
  raise AutomizorError.from_response(
automizor/job/_job.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import json
2
2
  import os
3
+ from typing import Optional
3
4
 
4
5
  import requests
5
6
 
@@ -48,17 +49,16 @@ class Job:
48
49
 
49
50
  _instance = None
50
51
 
51
- @classmethod
52
- def configure(cls, api_token: str | None = None):
53
- cls._instance = cls(api_token)
54
-
55
- def __init__(self, api_token: str | None = None):
52
+ def __init__(self, api_token: Optional[str] = None):
56
53
  self._context_file = os.getenv("AUTOMIZOR_CONTEXT_FILE", None)
57
54
  self._job_id = os.getenv("AUTOMIZOR_JOB_ID", None)
58
55
 
59
56
  self.url, self.token = get_api_config(api_token)
60
- self.session = requests.Session()
61
- self.session.headers.update(get_headers(self.token))
57
+ self.headers = get_headers(self.token)
58
+
59
+ @classmethod
60
+ def configure(cls, api_token: Optional[str] = None):
61
+ cls._instance = cls(api_token)
62
62
 
63
63
  @classmethod
64
64
  def get_instance(cls):
@@ -129,7 +129,7 @@ class Job:
129
129
  def _read_job_context(self) -> dict:
130
130
  url = f"https://{self.url}/api/v1/rpa/job/{self._job_id}/"
131
131
  try:
132
- response = self.session.get(url, timeout=10)
132
+ response = requests.get(url, headers=self.headers, timeout=10)
133
133
  response.raise_for_status()
134
134
  return response.json().get("context", {})
135
135
  except requests.HTTPError as exc:
@@ -1,7 +1,7 @@
1
1
  import json
2
2
  import mimetypes
3
3
  from pathlib import Path
4
- from typing import List
4
+ from typing import List, Optional
5
5
 
6
6
  from automizor.utils import JSON
7
7
 
@@ -114,7 +114,7 @@ def set_bytes(name: str, data: bytes, content_type="application/octet-stream"):
114
114
  storage.set_bytes(name, data, content_type)
115
115
 
116
116
 
117
- def set_file(name: str, path: str, content_type: str = None):
117
+ def set_file(name: str, path: str, content_type: Optional[str] = None):
118
118
  """
119
119
  Uploads a file as an asset.
120
120
 
@@ -1,4 +1,4 @@
1
- from typing import List
1
+ from typing import List, Optional
2
2
 
3
3
  import requests
4
4
 
@@ -50,15 +50,14 @@ class Storage:
50
50
 
51
51
  _instance = None
52
52
 
53
+ def __init__(self, api_token: Optional[str] = None):
54
+ self.url, self.token = get_api_config(api_token)
55
+ self.headers = get_headers(self.token)
56
+
53
57
  @classmethod
54
- def configure(cls, api_token: str | None = None):
58
+ def configure(cls, api_token: Optional[str] = None):
55
59
  cls._instance = cls(api_token)
56
60
 
57
- def __init__(self, api_token: str | None = None):
58
- self.url, self.token = get_api_config(api_token)
59
- self.session = requests.Session()
60
- self.session.headers.update(get_headers(self.token))
61
-
62
61
  @classmethod
63
62
  def get_instance(cls):
64
63
  if cls._instance is None:
@@ -80,7 +79,7 @@ class Storage:
80
79
 
81
80
  try:
82
81
  while url:
83
- response = self.session.get(url, timeout=10)
82
+ response = requests.get(url, headers=self.headers, timeout=10)
84
83
  response.raise_for_status()
85
84
  data = response.json()
86
85
 
@@ -109,7 +108,7 @@ class Storage:
109
108
 
110
109
  url = f"https://{self.url}/api/v1/storage/asset/{name}/"
111
110
  try:
112
- response = self.session.delete(url, timeout=10)
111
+ response = requests.delete(url, headers=self.headers, timeout=10)
113
112
  response.raise_for_status()
114
113
  except requests.HTTPError as exc:
115
114
  raise AutomizorError.from_response(
@@ -231,7 +230,9 @@ class Storage:
231
230
  "name": name,
232
231
  }
233
232
  files = {"file": ("text.txt", content, content_type)}
234
- response = self.session.post(url, files=files, data=data, timeout=10)
233
+ response = requests.post(
234
+ url, headers=self.headers, files=files, data=data, timeout=10
235
+ )
235
236
  response.raise_for_status()
236
237
  except requests.HTTPError as exc:
237
238
  raise AutomizorError.from_response(
@@ -265,7 +266,7 @@ class Storage:
265
266
  def _get_asset_url(self, name: str) -> str:
266
267
  url = f"https://{self.url}/api/v1/storage/asset/{name}/"
267
268
  try:
268
- response = self.session.get(url, timeout=10)
269
+ response = requests.get(url, headers=self.headers, timeout=10)
269
270
  response.raise_for_status()
270
271
 
271
272
  url = response.json().get("file")
@@ -300,7 +301,9 @@ class Storage:
300
301
  "name": name,
301
302
  }
302
303
  files = {"file": ("text.txt", content, content_type)}
303
- response = self.session.put(url, files=files, data=data, timeout=10)
304
+ response = requests.put(
305
+ url, headers=self.headers, files=files, data=data, timeout=10
306
+ )
304
307
  response.raise_for_status()
305
308
  except requests.HTTPError as exc:
306
309
  raise AutomizorError.from_response(
@@ -1,6 +1,6 @@
1
1
  import os
2
2
  import platform
3
- from typing import Dict, List, Union
3
+ from typing import Dict, List, Optional, Union
4
4
 
5
5
  from automizor import version
6
6
  from automizor.exceptions import AutomizorError
@@ -13,7 +13,7 @@ OS_SYSTEM, OS_RELEASE, _ = platform.system_alias(
13
13
  )
14
14
 
15
15
 
16
- def get_api_config(api_token: str | None = None) -> tuple[str, str]:
16
+ def get_api_config(api_token: Optional[str] = None) -> tuple[str, str]:
17
17
  if api_token is None:
18
18
  api_token = os.getenv("AUTOMIZOR_AGENT_TOKEN")
19
19
 
automizor/vault/_vault.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from dataclasses import asdict
2
+ from typing import Optional
2
3
 
3
4
  import requests
4
5
 
@@ -44,15 +45,14 @@ class Vault:
44
45
 
45
46
  _instance = None
46
47
 
48
+ def __init__(self, api_token: Optional[str] = None):
49
+ self.url, self.token = get_api_config(api_token)
50
+ self.headers = get_headers(self.token)
51
+
47
52
  @classmethod
48
- def configure(cls, api_token: str | None = None):
53
+ def configure(cls, api_token: Optional[str] = None):
49
54
  cls._instance = cls(api_token)
50
55
 
51
- def __init__(self, api_token: str | None = None):
52
- self.url, self.token = get_api_config(api_token)
53
- self.session = requests.Session()
54
- self.session.headers.update(get_headers(self.token))
55
-
56
56
  @classmethod
57
57
  def get_instance(cls):
58
58
  if cls._instance is None:
@@ -114,7 +114,9 @@ class Vault:
114
114
  def _create_secret(self, secret: SecretContainer) -> SecretContainer:
115
115
  url = f"https://{self.url}/api/v1/vault/secret/"
116
116
  try:
117
- response = self.session.post(url, timeout=10, json=asdict(secret))
117
+ response = requests.post(
118
+ url, headers=self.headers, timeout=10, json=asdict(secret)
119
+ )
118
120
  response.raise_for_status()
119
121
  return SecretContainer(**response.json())
120
122
  except requests.HTTPError as exc:
@@ -127,7 +129,7 @@ class Vault:
127
129
  def _get_secret(self, name: str) -> SecretContainer:
128
130
  url = f"https://{self.url}/api/v1/vault/secret/{name}/"
129
131
  try:
130
- response = self.session.get(url, timeout=10)
132
+ response = requests.get(url, headers=self.headers, timeout=10)
131
133
  response.raise_for_status()
132
134
  return SecretContainer(**response.json())
133
135
  except requests.HTTPError as exc:
@@ -140,7 +142,9 @@ class Vault:
140
142
  def _update_secret(self, secret: SecretContainer) -> SecretContainer:
141
143
  url = f"https://{self.url}/api/v1/vault/secret/{secret.name}/"
142
144
  try:
143
- response = self.session.put(url, timeout=10, json=asdict(secret))
145
+ response = requests.put(
146
+ url, headers=self.headers, timeout=10, json=asdict(secret)
147
+ )
144
148
  response.raise_for_status()
145
149
  return SecretContainer(**response.json())
146
150
  except requests.HTTPError as exc:
@@ -0,0 +1,40 @@
1
+ import json
2
+ from typing import Optional
3
+
4
+ from automizor.utils import JSON
5
+
6
+ from ._workflow import Workflow
7
+
8
+
9
+ def configure(api_token: str):
10
+ """
11
+ Configures the Worflow instance with the provided API token.
12
+ """
13
+ Workflow.configure(api_token)
14
+
15
+
16
+ def start_by_name(
17
+ process_model: str,
18
+ workspace: str,
19
+ business_key: Optional[str] = None,
20
+ data: Optional[JSON] = None,
21
+ ):
22
+ """
23
+ Starts a workflow instance by process model and workspace name.
24
+
25
+ Parameters:
26
+ process_model: The name of the process model to start.
27
+ workspace: The workspace name to which the process model belongs.
28
+ business_key: An optional business identifier.
29
+ data: Optional initial instance data.
30
+ """
31
+ payload = json.dumps(data).encode("utf-8")
32
+
33
+ workflow = Workflow.get_instance()
34
+ workflow.start_by_name(process_model, workspace, business_key, payload)
35
+
36
+
37
+ __all__ = [
38
+ "configure",
39
+ "start_by_name",
40
+ ]
@@ -0,0 +1,102 @@
1
+ from typing import Optional
2
+
3
+ import requests
4
+
5
+ from automizor.exceptions import AutomizorError
6
+ from automizor.utils import get_api_config, get_headers
7
+
8
+
9
+ class Workflow:
10
+ """
11
+ The `Workflow` class is designed to interact with the `Automizor Platform` to manage
12
+ workflow instances and facilitate the initiation of workflows based on specified
13
+ process models and workspaces.
14
+
15
+ This class uses environment variables for configuration, particularly to retrieve the
16
+ API host and API token, which are essential for authenticating requests to the
17
+ `Automizor Workflow API`. These variables are typically configured by the `Automizor Agent`.
18
+
19
+ Required environment variable:
20
+ - ``AUTOMIZOR_AGENT_TOKEN``: The token used for authenticating API requests.
21
+
22
+ Example usage:
23
+
24
+ .. code-block:: python
25
+
26
+ from automizor import workflow
27
+
28
+ # Start a workflow instance by name
29
+ workflow.start_by_name("ModelName", "WorkspaceName")
30
+ workflow.start_by_name("ModelName", "WorkspaceName", "BusinessKey")
31
+ workflow.start_by_name("ModelName", "WorkspaceName", "BusinessKey", {"initial": "data"})
32
+ """
33
+
34
+ _instance = None
35
+
36
+ def __init__(self, api_token: Optional[str] = None):
37
+ self.url, self.token = get_api_config(api_token)
38
+ self.headers = get_headers(self.token)
39
+
40
+ @classmethod
41
+ def configure(cls, api_token: Optional[str] = None):
42
+ cls._instance = cls(api_token)
43
+
44
+ @classmethod
45
+ def get_instance(cls):
46
+ if cls._instance is None:
47
+ cls.configure()
48
+ return cls._instance
49
+
50
+ def start_by_name(
51
+ self,
52
+ process_model: str,
53
+ workspace: str,
54
+ business_key: Optional[str],
55
+ payload: Optional[bytes],
56
+ ):
57
+ """
58
+ Initiates a workflow instance based on a given process model and workspace.
59
+
60
+ Parameters:
61
+ process_model: The name of the process model to start.
62
+ workspace: The workspace name to which the process model belongs.
63
+ business_key: An optional business identifier.
64
+ payload: Optional json payload in bytes.
65
+ """
66
+ self._create_instance(process_model, workspace, business_key, payload)
67
+
68
+ def _create_instance(
69
+ self,
70
+ process_model: str,
71
+ workspace: str,
72
+ business_key: Optional[str],
73
+ payload: Optional[bytes],
74
+ ):
75
+ """
76
+ Creates a new workflow instance based on a given process model and workspace.
77
+
78
+ Parameters:
79
+ process_model: The name of the process model to start.
80
+ workspace: The workspace name to which the process model belongs.
81
+ business_key: An optional business identifier.
82
+ payload: Optional json payload in bytes.
83
+
84
+ Raises:
85
+ AutomizorError: If there is an error in creating the instance.
86
+ """
87
+ url = f"https://{self.url}/api/v1/workflow/instance/"
88
+ try:
89
+ data = {
90
+ "business_key": business_key,
91
+ "initial_data": payload,
92
+ "process_model": process_model,
93
+ "workspace": workspace,
94
+ }
95
+ response = requests.post(url, headers=self.headers, data=data, timeout=10)
96
+ response.raise_for_status()
97
+ except requests.HTTPError as exc:
98
+ raise AutomizorError.from_response(
99
+ exc.response, "Failed to create instance"
100
+ ) from exc
101
+ except Exception as exc:
102
+ raise AutomizorError(f"Failed to create instance: {exc}") from exc
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: automizor
3
- Version: 0.4.9
3
+ Version: 0.4.11
4
4
  Summary: Python Automizor framework
5
5
  Home-page: https://github.com/automizor/automizor-python
6
6
  Author: Christian Fischer
@@ -0,0 +1,22 @@
1
+ automizor/__init__.py,sha256=BgTmI_pMMS3dXctT_oRAuEr_Pn2I3qHQCFooYZOzQ1Q,19
2
+ automizor/exceptions.py,sha256=P5imySIOtG3ZIk2kh41Yod4RnlgTj7Vf0P3M-RuxQJs,1382
3
+ automizor/datastore/__init__.py,sha256=_rAdRfKnTa4SuSLl9GkAYziBPPLsy6yGfS0HprgokOk,2418
4
+ automizor/datastore/_container.py,sha256=rHRkSWaRgy2rk6Qy-7ADFKvuET_COZ2i9VD7gvRDnlM,745
5
+ automizor/datastore/_datastore.py,sha256=Tv0vRjIyeUfVy3V8pcZVN1dX7q7v8JbJ9L3SCIxX8aM,3396
6
+ automizor/job/__init__.py,sha256=pDqSfR4lAyJNCi-fpG6byUPidHz8sntBs0bB2lJFVAY,1118
7
+ automizor/job/_job.py,sha256=XJX9Q7GeOErb7U9Wb01Wv1twIlBqNnJePb0Epc8NdTs,5440
8
+ automizor/log/__init__.py,sha256=gEr2SuwN1FgX1NMnbphjg8_gfSic9L15H3WC868A-TQ,2104
9
+ automizor/log/_log.py,sha256=P9jAFXVANs5bAGH6-S0pzuSbRKEcX8VlQ_3uu690awE,2948
10
+ automizor/storage/__init__.py,sha256=vCez0LucHQeRZDfX5xZulxf06i3ezVyFl4vL3-EYXXU,4160
11
+ automizor/storage/_storage.py,sha256=VPIahpIjCBU7pT-2qvleWcYOMWoffR_x3XUk6nGzUmI,11372
12
+ automizor/utils/__init__.py,sha256=UDYuSERa3IrS_1NreBTNBYf6j25ga2AiwRdq0c3kfvM,965
13
+ automizor/vault/__init__.py,sha256=21Ag2zQk7x27Bh0yt_kSO2MkgT3eafbdlKe0NuQEqr8,1796
14
+ automizor/vault/_container.py,sha256=-2y7kASigoIVAebuQBk-0R_sI4gfmvjsMLuMg_tR1xA,1945
15
+ automizor/vault/_vault.py,sha256=n_ZgzSOdG0nTFnO8J3D69fgmcsRPRwmSDd5fvn2ZkUI,5112
16
+ automizor/workflow/__init__.py,sha256=rfaqZojz35cEPN4WnqlvG_G9xzMDUDZIfwib17AQLQw,952
17
+ automizor/workflow/_workflow.py,sha256=l4kb-eMdBpewa0inmseQMREorImjY829dDLA3DzCC7c,3561
18
+ automizor-0.4.11.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
19
+ automizor-0.4.11.dist-info/METADATA,sha256=WKjbnfWNrOW_QZ_mrVdD0baRkmhZM9uTB0MnGBPwYcQ,669
20
+ automizor-0.4.11.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
21
+ automizor-0.4.11.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
22
+ automizor-0.4.11.dist-info/RECORD,,
@@ -1,20 +0,0 @@
1
- automizor/__init__.py,sha256=ElLL68L1maenU2D5V6AoUj5l5Opu9EHBBw3V9qIFxV4,18
2
- automizor/exceptions.py,sha256=P5imySIOtG3ZIk2kh41Yod4RnlgTj7Vf0P3M-RuxQJs,1382
3
- automizor/datastore/__init__.py,sha256=_rAdRfKnTa4SuSLl9GkAYziBPPLsy6yGfS0HprgokOk,2418
4
- automizor/datastore/_container.py,sha256=rHRkSWaRgy2rk6Qy-7ADFKvuET_COZ2i9VD7gvRDnlM,745
5
- automizor/datastore/_datastore.py,sha256=EW8AnZPvr32Yz3bC6SxadRgihY7_G-XcwSfLV5CMzMg,3552
6
- automizor/job/__init__.py,sha256=pDqSfR4lAyJNCi-fpG6byUPidHz8sntBs0bB2lJFVAY,1118
7
- automizor/job/_job.py,sha256=oVv7utlpaIPVBSnBXcV9jf7B3UNsWCDLtPkw0m3IJio,5444
8
- automizor/log/__init__.py,sha256=gEr2SuwN1FgX1NMnbphjg8_gfSic9L15H3WC868A-TQ,2104
9
- automizor/log/_log.py,sha256=P9jAFXVANs5bAGH6-S0pzuSbRKEcX8VlQ_3uu690awE,2948
10
- automizor/storage/__init__.py,sha256=RF4ccSAd0UepvJx5NFiotKt9mVr5WiZCb_4qrJ5OKx0,4140
11
- automizor/storage/_storage.py,sha256=ah8sCpRQm0MOnZgOgiBQF1Oamq_mz1VWrV17z6XOuFw,11262
12
- automizor/utils/__init__.py,sha256=W0JNrn7GByjJXi60djS6vluo__Tj6AyJioqu9D41tto,952
13
- automizor/vault/__init__.py,sha256=21Ag2zQk7x27Bh0yt_kSO2MkgT3eafbdlKe0NuQEqr8,1796
14
- automizor/vault/_container.py,sha256=-2y7kASigoIVAebuQBk-0R_sI4gfmvjsMLuMg_tR1xA,1945
15
- automizor/vault/_vault.py,sha256=-Xi_xMQLRB9patFTiZ4Z817F9VEvhIvx-YOOH8z_BKc,5020
16
- automizor-0.4.9.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
17
- automizor-0.4.9.dist-info/METADATA,sha256=uNVJ3mjxM7iZZRRzbzTCdCE6FlUYdkXiNqLCJZZSG_c,668
18
- automizor-0.4.9.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
19
- automizor-0.4.9.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
20
- automizor-0.4.9.dist-info/RECORD,,