automizor 0.4.5__tar.gz → 0.4.7__tar.gz

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.
Files changed (28) hide show
  1. {automizor-0.4.5/automizor.egg-info → automizor-0.4.7}/PKG-INFO +1 -1
  2. automizor-0.4.7/automizor/__init__.py +1 -0
  3. automizor-0.4.7/automizor/datastore/__init__.py +93 -0
  4. automizor-0.4.7/automizor/datastore/_container.py +26 -0
  5. {automizor-0.4.5 → automizor-0.4.7}/automizor/datastore/_datastore.py +10 -35
  6. {automizor-0.4.5 → automizor-0.4.7/automizor.egg-info}/PKG-INFO +1 -1
  7. {automizor-0.4.5 → automizor-0.4.7}/automizor.egg-info/SOURCES.txt +1 -0
  8. automizor-0.4.5/automizor/__init__.py +0 -1
  9. automizor-0.4.5/automizor/datastore/__init__.py +0 -115
  10. {automizor-0.4.5 → automizor-0.4.7}/LICENSE +0 -0
  11. {automizor-0.4.5 → automizor-0.4.7}/MANIFEST.in +0 -0
  12. {automizor-0.4.5 → automizor-0.4.7}/README.md +0 -0
  13. {automizor-0.4.5 → automizor-0.4.7}/automizor/exceptions.py +0 -0
  14. {automizor-0.4.5 → automizor-0.4.7}/automizor/job/__init__.py +0 -0
  15. {automizor-0.4.5 → automizor-0.4.7}/automizor/job/_job.py +0 -0
  16. {automizor-0.4.5 → automizor-0.4.7}/automizor/log/__init__.py +0 -0
  17. {automizor-0.4.5 → automizor-0.4.7}/automizor/log/_log.py +0 -0
  18. {automizor-0.4.5 → automizor-0.4.7}/automizor/storage/__init__.py +0 -0
  19. {automizor-0.4.5 → automizor-0.4.7}/automizor/storage/_storage.py +0 -0
  20. {automizor-0.4.5 → automizor-0.4.7}/automizor/utils/__init__.py +0 -0
  21. {automizor-0.4.5 → automizor-0.4.7}/automizor/vault/__init__.py +0 -0
  22. {automizor-0.4.5 → automizor-0.4.7}/automizor/vault/_container.py +0 -0
  23. {automizor-0.4.5 → automizor-0.4.7}/automizor/vault/_vault.py +0 -0
  24. {automizor-0.4.5 → automizor-0.4.7}/automizor.egg-info/dependency_links.txt +0 -0
  25. {automizor-0.4.5 → automizor-0.4.7}/automizor.egg-info/requires.txt +0 -0
  26. {automizor-0.4.5 → automizor-0.4.7}/automizor.egg-info/top_level.txt +0 -0
  27. {automizor-0.4.5 → automizor-0.4.7}/setup.cfg +0 -0
  28. {automizor-0.4.5 → automizor-0.4.7}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: automizor
3
- Version: 0.4.5
3
+ Version: 0.4.7
4
4
  Summary: Python Automizor framework
5
5
  Home-page: https://github.com/automizor/automizor-python
6
6
  Author: Christian Fischer
@@ -0,0 +1 @@
1
+ version = "0.4.7"
@@ -0,0 +1,93 @@
1
+ from functools import lru_cache
2
+
3
+ from ._container import DataStoreContainer
4
+
5
+
6
+ @lru_cache
7
+ def _get_datastore():
8
+ from ._datastore import DataStore
9
+
10
+ return DataStore()
11
+
12
+
13
+ def get_store(name: str) -> DataStoreContainer:
14
+ """
15
+ Get a store container by name. The `DataStoreContainer` is a wrapper
16
+ around the data store that provides a get and set method to interact
17
+ with the data store.
18
+
19
+ Example usage:
20
+
21
+ .. code-block:: python
22
+
23
+ from automizor import datastore
24
+
25
+ # Get a data store countries
26
+ countries = datastore.get_store("countries")
27
+
28
+ # Initialize or update json store
29
+ countries.set([
30
+ {
31
+ "name": "United States",
32
+ "code": "US",
33
+ },
34
+ {
35
+ "name": "Canada",
36
+ "code": "CA",
37
+ },
38
+ ])
39
+
40
+ # Get values from json store
41
+ result = countries.get()
42
+
43
+ # Get a data store movies
44
+ movies = datastore.get_store("movies")
45
+
46
+ # Initialize or update kkv store
47
+ movies.set({
48
+ "US": {
49
+ "action": {
50
+ "Die Hard": 1988,
51
+ "The Matrix": 1999
52
+ }
53
+ }
54
+ })
55
+
56
+ # Get values from kkv store
57
+ result = movies.get("US")
58
+ result = movies.get("US", "action")
59
+
60
+ # Insert or update values
61
+ movies.set({
62
+ "US": {
63
+ "action": {
64
+ "Die Hard": 1988,
65
+ "The Matrix": 1999,
66
+ "John Wick": 2014
67
+ },
68
+ "comedy": {
69
+ "The Hangover": 2009,
70
+ "Superbad": 2007
71
+ }
72
+ }
73
+ })
74
+
75
+ # Delete secondary key
76
+ movies.set({
77
+ "US": {
78
+ "action": None
79
+ }
80
+ })
81
+
82
+ # Delete primary key
83
+ movies.set({
84
+ "US": None
85
+ })
86
+
87
+ """
88
+
89
+ datastore = _get_datastore()
90
+ return DataStoreContainer(
91
+ datastore=datastore,
92
+ name=name,
93
+ )
@@ -0,0 +1,26 @@
1
+ from dataclasses import dataclass
2
+
3
+ from ._datastore import JSON, DataStore
4
+
5
+
6
+ @dataclass
7
+ class DataStoreContainer:
8
+ """
9
+ The `DataStoreContainer` is a wrapper around the data store that
10
+ provides a get and set method to interact with the data store.
11
+
12
+ Attributes:
13
+ datastore: The data store.
14
+ name: The name of the data store.
15
+ """
16
+
17
+ datastore: DataStore
18
+ name: str
19
+
20
+ def get(self, primary_key=None, secondary_key=None):
21
+ """Get values from the datastore."""
22
+ return self.datastore.get_values(self.name, primary_key, secondary_key)
23
+
24
+ def set(self, values: JSON):
25
+ """Set values in the datastore."""
26
+ self.datastore.set_values(self.name, values)
@@ -10,17 +10,18 @@ JSON = Union[str, int, float, bool, None, Dict[str, "JSON"], List["JSON"]]
10
10
 
11
11
  class DataStore:
12
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.
13
+ `DataStore` is a class designed to interface with the `Automizor Platform`
14
+ to manage and manipulate data stored in various formats. It supports
15
+ operations to retrieve and update data using a unified API.
16
16
 
17
- The class initializes an HTTP session with the necessary headers for authentication, and
18
- provides methods to get the type of data store, retrieve values, and set values in the store.
17
+ The class initializes an HTTP session with the necessary headers for
18
+ authentication, and provides methods to retrieve values, and set values in
19
+ the store.
19
20
 
20
21
  Attributes:
21
22
  url (str): The base URL for the API endpoint.
22
23
  token (str): The authentication token for API access.
23
- session (requests.Session): The HTTP session used for making API requests.
24
+ session (requests.Session): The HTTP session used to make API requests.
24
25
  """
25
26
 
26
27
  def __init__(self):
@@ -28,19 +29,6 @@ class DataStore:
28
29
  self.session = requests.Session()
29
30
  self.session.headers.update(get_headers(self.token))
30
31
 
31
- def type(self, name: str) -> str:
32
- """
33
- Gets the type of the specified data store.
34
-
35
- Parameters:
36
- name (str): The name of the data store.
37
-
38
- Returns:
39
- str: The type of the data store.
40
- """
41
-
42
- return self._get_type(name)
43
-
44
32
  def get_values(
45
33
  self,
46
34
  name: str,
@@ -52,8 +40,8 @@ class DataStore:
52
40
 
53
41
  Parameters:
54
42
  name (str): The name of the data store.
55
- primary_key (str, optional): The primary key for the values. Defaults to None.
56
- secondary_key (str, optional): The secondary key for the values. Defaults to None.
43
+ primary_key (str, optional): The primary key for the values.
44
+ secondary_key (str, optional): The secondary key for the values.
57
45
 
58
46
  Returns:
59
47
  JSON: The values from the data store.
@@ -72,25 +60,12 @@ class DataStore:
72
60
 
73
61
  return self._set_values(name, values)
74
62
 
75
- def _get_type(self, name: str) -> str:
76
- url = f"https://{self.url}/api/v1/workflow/datastore/{name}/"
77
- try:
78
- response = self.session.get(url, timeout=10)
79
- response.raise_for_status()
80
- return response.json().get("datastore_type")
81
- except requests.HTTPError as exc:
82
- raise AutomizorError.from_response(
83
- exc.response, "Failed to get datastore values"
84
- ) from exc
85
- except Exception as exc:
86
- raise AutomizorError("Failed to get datastore values") from exc
87
-
88
63
  def _get_values(
89
64
  self,
90
65
  name: str,
91
66
  primary_key: str | None = None,
92
67
  secondary_key: str | None = None,
93
- ) -> dict:
68
+ ) -> JSON:
94
69
  params = (
95
70
  {"primary_key": primary_key, "secondary_key": secondary_key}
96
71
  if primary_key or secondary_key
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: automizor
3
- Version: 0.4.5
3
+ Version: 0.4.7
4
4
  Summary: Python Automizor framework
5
5
  Home-page: https://github.com/automizor/automizor-python
6
6
  Author: Christian Fischer
@@ -11,6 +11,7 @@ automizor.egg-info/dependency_links.txt
11
11
  automizor.egg-info/requires.txt
12
12
  automizor.egg-info/top_level.txt
13
13
  automizor/datastore/__init__.py
14
+ automizor/datastore/_container.py
14
15
  automizor/datastore/_datastore.py
15
16
  automizor/job/__init__.py
16
17
  automizor/job/_job.py
@@ -1 +0,0 @@
1
- version = "0.4.5"
@@ -1,115 +0,0 @@
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
- The `DataStoreProxy` dynamically determines the type of data store being accessed
27
- and adapts its behavior accordingly. For JSON data stores, it directly retrieves
28
- values. For KKV stores, it provides a wrapper function that facilitates more complex
29
- data retrieval operations based on primary and secondary keys.
30
-
31
- Example usage:
32
-
33
- .. code-block:: python
34
-
35
- from automizor import datastore
36
-
37
- # Initialize or update json store
38
- datastore.countries = {
39
- "US": {
40
- "name": "United States",
41
- "capital": "Washington, D.C.",
42
- "population": 331449281,
43
- "area": 9833520
44
- },
45
- "CA": {
46
- "name": "Canada",
47
- "capital": "Ottawa",
48
- "population": 38005238,
49
- "area": 9984670
50
- }
51
- }
52
-
53
- # Get values from json store
54
- countries = datastore.countries
55
-
56
- # Initialize or update kkv store
57
- datastore.movies = {
58
- "US": {
59
- "action": {
60
- "Die Hard": 1988,
61
- "The Matrix": 1999
62
- }
63
- }
64
- }
65
-
66
- # Get values from kkv store
67
- movies = datastore.movies("US")
68
- movies_action = datastore.movies("US", "action")
69
-
70
- # Insert or update values
71
- datastore.movies = {
72
- "US": {
73
- "action": {
74
- "Die Hard": 1988,
75
- "The Matrix": 1999,
76
- "John Wick": 2014
77
- },
78
- "comedy": {
79
- "The Hangover": 2009,
80
- "Superbad": 2007
81
- }
82
- }
83
- }
84
-
85
- # Delete secondary key
86
- datastore.movies = {
87
- "US": {
88
- "action": None
89
- }
90
- }
91
-
92
- # Delete primary key
93
- datastore.movies = {
94
- "US": None
95
- }
96
-
97
- """
98
-
99
- def __getattr__(self, name):
100
- datastore = _get_datastore()
101
- datastore_type = datastore.type(name)
102
-
103
- def wrapper(primary_key=None, secondary_key=None):
104
- return datastore.get_values(name, primary_key, secondary_key)
105
-
106
- if datastore_type == "JSONDataStore":
107
- return datastore.get_values(name)
108
- return wrapper
109
-
110
- def __setattr__(self, name, values: JSON):
111
- datastore = _get_datastore()
112
- datastore.set_values(name, values)
113
-
114
-
115
- sys.modules[__name__] = DataStoreProxy(__name__)
File without changes
File without changes
File without changes
File without changes
File without changes