automizor 0.4.10__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.10"
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
@@ -17,12 +19,12 @@ class DataStore:
17
19
 
18
20
  _instance = None
19
21
 
20
- def __init__(self, api_token: str | None = None):
22
+ def __init__(self, api_token: Optional[str] = None):
21
23
  self.url, self.token = get_api_config(api_token)
22
24
  self.headers = get_headers(self.token)
23
25
 
24
26
  @classmethod
25
- def configure(cls, api_token: str | None = None):
27
+ def configure(cls, api_token: Optional[str] = None):
26
28
  cls._instance = cls(api_token)
27
29
 
28
30
  @classmethod
@@ -34,8 +36,8 @@ class DataStore:
34
36
  def get_values(
35
37
  self,
36
38
  name: str,
37
- primary_key: str | None = None,
38
- secondary_key: str | None = None,
39
+ primary_key: Optional[str] = None,
40
+ secondary_key: Optional[str] = None,
39
41
  ) -> JSON:
40
42
  """
41
43
  Retrieves values from the specified data store.
@@ -65,8 +67,8 @@ class DataStore:
65
67
  def _get_values(
66
68
  self,
67
69
  name: str,
68
- primary_key: str | None = None,
69
- secondary_key: str | None = None,
70
+ primary_key: Optional[str] = None,
71
+ secondary_key: Optional[str] = None,
70
72
  ) -> JSON:
71
73
  params = (
72
74
  {"primary_key": primary_key, "secondary_key": secondary_key}
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,7 +49,7 @@ class Job:
48
49
 
49
50
  _instance = None
50
51
 
51
- def __init__(self, api_token: str | None = None):
52
+ def __init__(self, api_token: Optional[str] = None):
52
53
  self._context_file = os.getenv("AUTOMIZOR_CONTEXT_FILE", None)
53
54
  self._job_id = os.getenv("AUTOMIZOR_JOB_ID", None)
54
55
 
@@ -56,7 +57,7 @@ class Job:
56
57
  self.headers = get_headers(self.token)
57
58
 
58
59
  @classmethod
59
- def configure(cls, api_token: str | None = None):
60
+ def configure(cls, api_token: Optional[str] = None):
60
61
  cls._instance = cls(api_token)
61
62
 
62
63
  @classmethod
@@ -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,12 +50,12 @@ class Storage:
50
50
 
51
51
  _instance = None
52
52
 
53
- def __init__(self, api_token: str | None = None):
53
+ def __init__(self, api_token: Optional[str] = None):
54
54
  self.url, self.token = get_api_config(api_token)
55
55
  self.headers = get_headers(self.token)
56
56
 
57
57
  @classmethod
58
- def configure(cls, api_token: str | None = None):
58
+ def configure(cls, api_token: Optional[str] = None):
59
59
  cls._instance = cls(api_token)
60
60
 
61
61
  @classmethod
@@ -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,12 +45,12 @@ class Vault:
44
45
 
45
46
  _instance = None
46
47
 
47
- def __init__(self, api_token: str | None = None):
48
+ def __init__(self, api_token: Optional[str] = None):
48
49
  self.url, self.token = get_api_config(api_token)
49
50
  self.headers = get_headers(self.token)
50
51
 
51
52
  @classmethod
52
- def configure(cls, api_token: str | None = None):
53
+ def configure(cls, api_token: Optional[str] = None):
53
54
  cls._instance = cls(api_token)
54
55
 
55
56
  @classmethod
@@ -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.10
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=XxfULjVU_ewxlK1iP8zCIo68qAo_TYC2AAlK0zPbeS8,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=Xtl64A-q3N9xP2lppPwgLNpqNMTHA5VoCO74T0vi-ZE,3349
6
- automizor/job/__init__.py,sha256=pDqSfR4lAyJNCi-fpG6byUPidHz8sntBs0bB2lJFVAY,1118
7
- automizor/job/_job.py,sha256=TvZYxrl9JNXV5RZolOSdGMIQTNkiIy_MIPlDP2_-euM,5406
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=fnYsvcExh6nMZg9YnSrDjbRWDD-szzRFTjcxXh4wIyY,11356
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=WTKmm4QQhnBx2oWvYRuXi4hQEcf0srlJ64EN1hUJa6o,5078
16
- automizor-0.4.10.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
17
- automizor-0.4.10.dist-info/METADATA,sha256=plaIwWyN4HB2QZh87NHhHn6uRIvu_4t4Dc5NR6vOYX4,669
18
- automizor-0.4.10.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
19
- automizor-0.4.10.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
20
- automizor-0.4.10.dist-info/RECORD,,