automizor 0.4.10__py3-none-any.whl → 0.4.12__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.12"
@@ -0,0 +1,38 @@
1
+ import json
2
+ from typing import Optional
3
+
4
+ from automizor.utils import JSON
5
+
6
+ from ._action import Action
7
+
8
+
9
+ def configure(api_token: str):
10
+ """
11
+ Configures the Action instance with the provided API token.
12
+ """
13
+ Action.configure(api_token)
14
+
15
+
16
+ def run(
17
+ name: str,
18
+ workspace: str,
19
+ data: Optional[JSON] = None,
20
+ ) -> JSON:
21
+ """
22
+ Runs an action using the specified action and workspace name.
23
+
24
+ Parameters:
25
+ name: The name of the action.
26
+ workspace: The workspace name to which the action belongs.
27
+ data: Optional action payload data.
28
+ """
29
+ payload = json.dumps(data or {}).encode("utf-8")
30
+
31
+ action = Action.get_instance()
32
+ return action.run(name, workspace, payload)
33
+
34
+
35
+ __all__ = [
36
+ "configure",
37
+ "run",
38
+ ]
@@ -0,0 +1,94 @@
1
+ from typing import Optional
2
+
3
+ import requests
4
+
5
+ from automizor.exceptions import AutomizorError
6
+ from automizor.utils import JSON, get_api_config, get_headers
7
+
8
+
9
+ class Action:
10
+ """
11
+ The `Action` class is designed to interact with the `Automizor Platform` to run
12
+ action based on specified action name and for a workspaces.
13
+
14
+ This class uses environment variables for configuration, particularly to retrieve the
15
+ API host and API token, which are essential for authenticating requests to the
16
+ `Automizor Action API`. These variables are typically configured by the `Automizor Agent`.
17
+
18
+ Required environment variable:
19
+ - ``AUTOMIZOR_AGENT_TOKEN``: The token used for authenticating API requests.
20
+
21
+ Example usage:
22
+
23
+ .. code-block:: python
24
+
25
+ from automizor import action
26
+
27
+ # Run an action by name
28
+ action.run("action_name", "workspace_name")
29
+ action.run("action_name", "workspace_name", {"name": "John Doe"})
30
+ """
31
+
32
+ _instance = None
33
+
34
+ def __init__(self, api_token: Optional[str] = None):
35
+ self.url, self.token = get_api_config(api_token)
36
+ self.headers = get_headers(self.token)
37
+
38
+ @classmethod
39
+ def configure(cls, api_token: Optional[str] = None):
40
+ cls._instance = cls(api_token)
41
+
42
+ @classmethod
43
+ def get_instance(cls):
44
+ if cls._instance is None:
45
+ cls.configure()
46
+ return cls._instance
47
+
48
+ def run(
49
+ self,
50
+ name: str,
51
+ workspace: str,
52
+ payload: Optional[bytes],
53
+ ) -> JSON:
54
+ """
55
+ Runs an action using the specified action and workspace name.
56
+
57
+ Parameters:
58
+ name: The name of the action.
59
+ workspace: The workspace name to which the action belongs.
60
+ payload: Optional json payload in bytes.
61
+ """
62
+ return self._execute_action(name, workspace, payload)
63
+
64
+ def _execute_action(
65
+ self,
66
+ name: str,
67
+ workspace: str,
68
+ payload: Optional[bytes],
69
+ ) -> JSON:
70
+ """
71
+ Executes an action by action and workspace name.
72
+
73
+ Parameters:
74
+ name: The name of the action.
75
+ workspace: The workspace name to which the action belongs.
76
+ payload: Optional json payload in bytes.
77
+
78
+ Raises:
79
+ AutomizorError: If there is an error executing the action.
80
+ """
81
+ url = f"https://{self.url}/api/v2/action/{name}/execute?workspace={workspace}"
82
+ try:
83
+ print(self.headers)
84
+ response = requests.put(
85
+ url, headers=self.headers, data=payload, timeout=10, verify=False
86
+ )
87
+ response.raise_for_status()
88
+ return response.json()
89
+ except requests.HTTPError as exc:
90
+ raise AutomizorError.from_response(
91
+ exc.response, "Failed to execute action"
92
+ ) from exc
93
+ except Exception as exc:
94
+ raise AutomizorError(f"Failed to execute action: {exc}") from exc
@@ -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
 
@@ -33,29 +33,29 @@ class Storage:
33
33
  asset_names = storage.list_assets()
34
34
 
35
35
  # To delete an asset
36
- storage.delete_asset("AssetName")
36
+ storage.delete_asset("asset_name")
37
37
 
38
38
  # Save an asset
39
- storage.set_bytes("AssetName", b"Hello, World!")
40
- storage.set_file("AssetName", "/path/to/file")
41
- storage.set_json("AssetName", {"key": "value"})
42
- storage.set_text("AssetName", "Hello, World!")
39
+ storage.set_bytes("asset_name", b"Hello, World!")
40
+ storage.set_file("asset_name", "/path/to/file")
41
+ storage.set_json("asset_name", {"key": "value"})
42
+ storage.set_text("asset_name", "Hello, World!")
43
43
 
44
44
  # Get an asset
45
- bytes_data = storage.get_bytes("AssetName")
46
- file_path = storage.get_file("AssetName", "/path/to/save/file")
47
- json_data = storage.get_json("AssetName")
48
- text_data = storage.get_text("AssetName")
45
+ bytes_data = storage.get_bytes("asset_name")
46
+ file_path = storage.get_file("asset_name", "/path/to/save/file")
47
+ json_data = storage.get_json("asset_name")
48
+ text_data = storage.get_text("asset_name")
49
49
  """
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
 
@@ -29,27 +30,27 @@ class Vault:
29
30
  from automizor import vault
30
31
 
31
32
  # Create a new secret
32
- vault.create_secret(name="MySecret", value={"username": "admin", "password": "*****"})
33
+ vault.create_secret("my_secret", {"username": "admin", "password": "*****"})
33
34
 
34
35
  # Retrieve a secret by its name
35
- secret = vault.get_secret("MySecret")
36
+ secret = vault.get_secret("my_secret")
36
37
  print(secret.get("username")) # Output: "admin"
37
38
  print(secret.get("password")) # Output: "*****"
38
39
 
39
40
  # Update a existing secret
40
- secret = vault.get_secret("MySecret")
41
+ secret = vault.get_secret("my_secret")
41
42
  secret.update({"username": "user"})
42
43
  vault.set_secret(secret)
43
44
  """
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 or {}).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("model_name", "workspace_name")
30
+ workflow.start_by_name("model_name", "workspace_name", "BusinessKey")
31
+ workflow.start_by_name("model_name", "workspace_name", "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.12
4
4
  Summary: Python Automizor framework
5
5
  Home-page: https://github.com/automizor/automizor-python
6
6
  Author: Christian Fischer
@@ -0,0 +1,24 @@
1
+ automizor/__init__.py,sha256=HVOv7A4kWYweGJt1C1qauzQhQ7x6c4fG5iHyNQrjLGc,19
2
+ automizor/exceptions.py,sha256=P5imySIOtG3ZIk2kh41Yod4RnlgTj7Vf0P3M-RuxQJs,1382
3
+ automizor/utils.py,sha256=UDYuSERa3IrS_1NreBTNBYf6j25ga2AiwRdq0c3kfvM,965
4
+ automizor/action/__init__.py,sha256=nZinP2WYc8Da3rxE10Ul0V31GbEFXRgCYXtBOQ-0LwQ,767
5
+ automizor/action/_action.py,sha256=QMry9gw4RSBVb3YT_N03t9ECwLiyXOAlX3_sxfGHcPg,2973
6
+ automizor/datastore/__init__.py,sha256=_rAdRfKnTa4SuSLl9GkAYziBPPLsy6yGfS0HprgokOk,2418
7
+ automizor/datastore/_container.py,sha256=rHRkSWaRgy2rk6Qy-7ADFKvuET_COZ2i9VD7gvRDnlM,745
8
+ automizor/datastore/_datastore.py,sha256=Tv0vRjIyeUfVy3V8pcZVN1dX7q7v8JbJ9L3SCIxX8aM,3396
9
+ automizor/job/__init__.py,sha256=pDqSfR4lAyJNCi-fpG6byUPidHz8sntBs0bB2lJFVAY,1118
10
+ automizor/job/_job.py,sha256=XJX9Q7GeOErb7U9Wb01Wv1twIlBqNnJePb0Epc8NdTs,5440
11
+ automizor/log/__init__.py,sha256=gEr2SuwN1FgX1NMnbphjg8_gfSic9L15H3WC868A-TQ,2104
12
+ automizor/log/_log.py,sha256=P9jAFXVANs5bAGH6-S0pzuSbRKEcX8VlQ_3uu690awE,2948
13
+ automizor/storage/__init__.py,sha256=vCez0LucHQeRZDfX5xZulxf06i3ezVyFl4vL3-EYXXU,4160
14
+ automizor/storage/_storage.py,sha256=x5gPxGkzQe21wDDnCLtmVWU0g9JeklPu9iIYVlPDRnk,11381
15
+ automizor/vault/__init__.py,sha256=21Ag2zQk7x27Bh0yt_kSO2MkgT3eafbdlKe0NuQEqr8,1796
16
+ automizor/vault/_container.py,sha256=-2y7kASigoIVAebuQBk-0R_sI4gfmvjsMLuMg_tR1xA,1945
17
+ automizor/vault/_vault.py,sha256=pXS1Qcltjh48n9R0NX4q7PSpXT_XFjifRy9Hu4aQnUQ,5104
18
+ automizor/workflow/__init__.py,sha256=J1K_ogAvbeREPbAmVxsAI1SOVHi_5DXnO9JuEKOMdt8,958
19
+ automizor/workflow/_workflow.py,sha256=XhcDNBmORdqErj25sO1yb2koKObAFXVkgXrV7xx3EtI,3567
20
+ automizor-0.4.12.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
21
+ automizor-0.4.12.dist-info/METADATA,sha256=DLFtVKTjkYkpssJkwszQszv_Lo_ELfBQV5CGxG5m1jY,669
22
+ automizor-0.4.12.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
23
+ automizor-0.4.12.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
24
+ automizor-0.4.12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.2.0)
2
+ Generator: setuptools (75.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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,,