automizor 0.4.4__py3-none-any.whl → 0.4.6__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.4"
1
+ version = "0.4.6"
@@ -0,0 +1,107 @@
1
+ import sys
2
+ import types
3
+ from functools import lru_cache
4
+
5
+ from ._datastore import JSON
6
+
7
+
8
+ @lru_cache
9
+ def _get_datastore():
10
+ from ._datastore import DataStore
11
+
12
+ return DataStore()
13
+
14
+
15
+ class DataStoreProxy(types.ModuleType):
16
+ """
17
+ `DataStoreProxy` acts as a dynamic interface for interacting with various types of
18
+ data stores within the `Automizor Platform`. It provides a convenient way to access
19
+ and manipulate data stored in JSON and Key-Key-Value (KKV) formats.
20
+
21
+ This class leverages the `Automizor DataStore` module to fetch and update data,
22
+ utilizing a caching mechanism to enhance performance. The primary interaction is
23
+ through attribute access and assignment, making it simple to work with different
24
+ data structures.
25
+
26
+ Example usage:
27
+
28
+ .. code-block:: python
29
+
30
+ from automizor import datastore
31
+
32
+ # Initialize or update json store
33
+ datastore.countries = {
34
+ "US": {
35
+ "name": "United States",
36
+ "capital": "Washington, D.C.",
37
+ "population": 331449281,
38
+ "area": 9833520
39
+ },
40
+ "CA": {
41
+ "name": "Canada",
42
+ "capital": "Ottawa",
43
+ "population": 38005238,
44
+ "area": 9984670
45
+ }
46
+ }
47
+
48
+ # Get values from json store
49
+ countries = datastore.countries()
50
+
51
+ # Initialize or update kkv store
52
+ datastore.movies = {
53
+ "US": {
54
+ "action": {
55
+ "Die Hard": 1988,
56
+ "The Matrix": 1999
57
+ }
58
+ }
59
+ }
60
+
61
+ # Get values from kkv store
62
+ movies = datastore.movies("US")
63
+ movies_action = datastore.movies("US", "action")
64
+
65
+ # Insert or update values
66
+ datastore.movies = {
67
+ "US": {
68
+ "action": {
69
+ "Die Hard": 1988,
70
+ "The Matrix": 1999,
71
+ "John Wick": 2014
72
+ },
73
+ "comedy": {
74
+ "The Hangover": 2009,
75
+ "Superbad": 2007
76
+ }
77
+ }
78
+ }
79
+
80
+ # Delete secondary key
81
+ datastore.movies = {
82
+ "US": {
83
+ "action": None
84
+ }
85
+ }
86
+
87
+ # Delete primary key
88
+ datastore.movies = {
89
+ "US": None
90
+ }
91
+
92
+ """
93
+
94
+ def __getattr__(self, name):
95
+ datastore = _get_datastore()
96
+
97
+ def wrapper(primary_key=None, secondary_key=None):
98
+ return datastore.get_values(name, primary_key, secondary_key)
99
+
100
+ return wrapper
101
+
102
+ def __setattr__(self, name, values: JSON):
103
+ datastore = _get_datastore()
104
+ datastore.set_values(name, values)
105
+
106
+
107
+ sys.modules[__name__] = DataStoreProxy(__name__)
@@ -0,0 +1,95 @@
1
+ from typing import Dict, List, Union
2
+
3
+ import requests
4
+
5
+ from automizor.exceptions import AutomizorError
6
+ from automizor.utils import get_api_config, get_headers
7
+
8
+ JSON = Union[str, int, float, bool, None, Dict[str, "JSON"], List["JSON"]]
9
+
10
+
11
+ class DataStore:
12
+ """
13
+ `DataStore` is a class designed to interface with the `Automizor Platform` to manage and
14
+ manipulate data stored in various formats. It supports operations to retrieve and update
15
+ data using a unified API.
16
+
17
+ The class initializes an HTTP session with the necessary headers for authentication, and
18
+ provides methods to retrieve values, and set values in the store.
19
+
20
+ Attributes:
21
+ url (str): The base URL for the API endpoint.
22
+ token (str): The authentication token for API access.
23
+ session (requests.Session): The HTTP session used for making API requests.
24
+ """
25
+
26
+ def __init__(self):
27
+ self.url, self.token = get_api_config()
28
+ self.session = requests.Session()
29
+ self.session.headers.update(get_headers(self.token))
30
+
31
+ def get_values(
32
+ self,
33
+ name: str,
34
+ primary_key: str | None = None,
35
+ secondary_key: str | None = None,
36
+ ) -> JSON:
37
+ """
38
+ Retrieves values from the specified data store.
39
+
40
+ Parameters:
41
+ name (str): The name of the data store.
42
+ primary_key (str, optional): The primary key for the values. Defaults to None.
43
+ secondary_key (str, optional): The secondary key for the values. Defaults to None.
44
+
45
+ Returns:
46
+ JSON: The values from the data store.
47
+ """
48
+
49
+ return self._get_values(name, primary_key, secondary_key)
50
+
51
+ def set_values(self, name: str, values: JSON) -> None:
52
+ """
53
+ Sets values in the specified data store.
54
+
55
+ Parameters:
56
+ name (str): The name of the data store.
57
+ values (JSON): The values to set in the data store.
58
+ """
59
+
60
+ return self._set_values(name, values)
61
+
62
+ def _get_values(
63
+ self,
64
+ name: str,
65
+ primary_key: str | None = None,
66
+ secondary_key: str | None = None,
67
+ ) -> dict:
68
+ params = (
69
+ {"primary_key": primary_key, "secondary_key": secondary_key}
70
+ if primary_key or secondary_key
71
+ else {}
72
+ )
73
+ url = f"https://{self.url}/api/v1/workflow/datastore/{name}/values/"
74
+ try:
75
+ response = self.session.get(url, timeout=10, params=params)
76
+ response.raise_for_status()
77
+ return response.json()
78
+ except requests.HTTPError as exc:
79
+ raise AutomizorError.from_response(
80
+ exc.response, "Failed to get datastore values"
81
+ ) from exc
82
+ except Exception as exc:
83
+ raise AutomizorError("Failed to get datastore values") from exc
84
+
85
+ def _set_values(self, name: str, values: JSON) -> None:
86
+ url = f"https://{self.url}/api/v1/workflow/datastore/{name}/values/"
87
+ try:
88
+ response = self.session.post(url, json=values, timeout=10)
89
+ response.raise_for_status()
90
+ except requests.HTTPError as exc:
91
+ raise AutomizorError.from_response(
92
+ exc.response, "Failed to set datastore values"
93
+ ) from exc
94
+ except Exception as exc:
95
+ raise AutomizorError("Failed to set datastore values") from exc
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: automizor
3
- Version: 0.4.4
3
+ Version: 0.4.6
4
4
  Summary: Python Automizor framework
5
5
  Home-page: https://github.com/automizor/automizor-python
6
6
  Author: Christian Fischer
@@ -1,5 +1,7 @@
1
- automizor/__init__.py,sha256=Qk6wsgzl7cSMWWZ902odoQ-wBV5Fda2ShX82NN7uHzM,18
1
+ automizor/__init__.py,sha256=DWNNbWBv-hyqVy76bKbnHWaDUbqL0BOtdkPSV_88dx0,18
2
2
  automizor/exceptions.py,sha256=P5imySIOtG3ZIk2kh41Yod4RnlgTj7Vf0P3M-RuxQJs,1382
3
+ automizor/datastore/__init__.py,sha256=lOCAgf-976kgD1bo7rBi43Ahh9NK8TahOktTfHi0DBA,3016
4
+ automizor/datastore/_datastore.py,sha256=f2SAmsn5HWMYN_WGar6q0PioIfEJQdWbGC-REKFI5Cw,3371
3
5
  automizor/job/__init__.py,sha256=DNRuT6cyPQBaPRG4vNalCmEvcJQl-73b5ZDFOfNOwIg,1019
4
6
  automizor/job/_job.py,sha256=_-ehqPwJdY89mWm3_VAuh7KRJdv-8iUu6iMAzwGLHM0,5235
5
7
  automizor/log/__init__.py,sha256=gEr2SuwN1FgX1NMnbphjg8_gfSic9L15H3WC868A-TQ,2104
@@ -10,8 +12,8 @@ automizor/utils/__init__.py,sha256=2trRoR5lljYKbYdxmioSlvzajjQM0Wnoq3bvF9lEZ6w,8
10
12
  automizor/vault/__init__.py,sha256=UjRiW3J0R9ABXc1gXIPyS3cqNCwMWxx0l-C0PsIg7R0,1699
11
13
  automizor/vault/_container.py,sha256=-2y7kASigoIVAebuQBk-0R_sI4gfmvjsMLuMg_tR1xA,1945
12
14
  automizor/vault/_vault.py,sha256=uRsjOjzsstZpYwJoHNg_cpv803Dzo4T2oF6hwiG3Eww,4688
13
- automizor-0.4.4.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
14
- automizor-0.4.4.dist-info/METADATA,sha256=ov8bVxRLQVqu-Q5opOucEST3mEOJmQbpblVy1UF3fIA,668
15
- automizor-0.4.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
16
- automizor-0.4.4.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
17
- automizor-0.4.4.dist-info/RECORD,,
15
+ automizor-0.4.6.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
16
+ automizor-0.4.6.dist-info/METADATA,sha256=7njCCq1Bqgh7kwvoBAr-cdwr-vdNUxjPPS-DfvAWKMs,668
17
+ automizor-0.4.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
18
+ automizor-0.4.6.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
19
+ automizor-0.4.6.dist-info/RECORD,,