automizor 0.4.6__py3-none-any.whl → 0.4.7__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.6"
1
+ version = "0.4.7"
@@ -1,8 +1,6 @@
1
- import sys
2
- import types
3
1
  from functools import lru_cache
4
2
 
5
- from ._datastore import JSON
3
+ from ._container import DataStoreContainer
6
4
 
7
5
 
8
6
  @lru_cache
@@ -12,16 +10,11 @@ def _get_datastore():
12
10
  return DataStore()
13
11
 
14
12
 
15
- class DataStoreProxy(types.ModuleType):
13
+ def get_store(name: str) -> DataStoreContainer:
16
14
  """
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.
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.
25
18
 
26
19
  Example usage:
27
20
 
@@ -29,41 +22,43 @@ class DataStoreProxy(types.ModuleType):
29
22
 
30
23
  from automizor import datastore
31
24
 
25
+ # Get a data store countries
26
+ countries = datastore.get_store("countries")
27
+
32
28
  # Initialize or update json store
33
- datastore.countries = {
34
- "US": {
29
+ countries.set([
30
+ {
35
31
  "name": "United States",
36
- "capital": "Washington, D.C.",
37
- "population": 331449281,
38
- "area": 9833520
32
+ "code": "US",
39
33
  },
40
- "CA": {
34
+ {
41
35
  "name": "Canada",
42
- "capital": "Ottawa",
43
- "population": 38005238,
44
- "area": 9984670
45
- }
46
- }
36
+ "code": "CA",
37
+ },
38
+ ])
47
39
 
48
40
  # Get values from json store
49
- countries = datastore.countries()
41
+ result = countries.get()
42
+
43
+ # Get a data store movies
44
+ movies = datastore.get_store("movies")
50
45
 
51
46
  # Initialize or update kkv store
52
- datastore.movies = {
47
+ movies.set({
53
48
  "US": {
54
49
  "action": {
55
50
  "Die Hard": 1988,
56
51
  "The Matrix": 1999
57
52
  }
58
53
  }
59
- }
54
+ })
60
55
 
61
56
  # Get values from kkv store
62
- movies = datastore.movies("US")
63
- movies_action = datastore.movies("US", "action")
57
+ result = movies.get("US")
58
+ result = movies.get("US", "action")
64
59
 
65
60
  # Insert or update values
66
- datastore.movies = {
61
+ movies.set({
67
62
  "US": {
68
63
  "action": {
69
64
  "Die Hard": 1988,
@@ -75,33 +70,24 @@ class DataStoreProxy(types.ModuleType):
75
70
  "Superbad": 2007
76
71
  }
77
72
  }
78
- }
73
+ })
79
74
 
80
75
  # Delete secondary key
81
- datastore.movies = {
76
+ movies.set({
82
77
  "US": {
83
78
  "action": None
84
79
  }
85
- }
80
+ })
86
81
 
87
82
  # Delete primary key
88
- datastore.movies = {
83
+ movies.set({
89
84
  "US": None
90
- }
85
+ })
91
86
 
92
87
  """
93
88
 
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__)
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 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):
@@ -39,8 +40,8 @@ class DataStore:
39
40
 
40
41
  Parameters:
41
42
  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.
43
+ primary_key (str, optional): The primary key for the values.
44
+ secondary_key (str, optional): The secondary key for the values.
44
45
 
45
46
  Returns:
46
47
  JSON: The values from the data store.
@@ -64,7 +65,7 @@ class DataStore:
64
65
  name: str,
65
66
  primary_key: str | None = None,
66
67
  secondary_key: str | None = None,
67
- ) -> dict:
68
+ ) -> JSON:
68
69
  params = (
69
70
  {"primary_key": primary_key, "secondary_key": secondary_key}
70
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.6
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
@@ -1,7 +1,8 @@
1
- automizor/__init__.py,sha256=DWNNbWBv-hyqVy76bKbnHWaDUbqL0BOtdkPSV_88dx0,18
1
+ automizor/__init__.py,sha256=m3H0nxC6dWftoBK74_V3kjhpRmKkLX6wTCtSlFvMbjI,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
+ automizor/datastore/__init__.py,sha256=NA7gJ9qFoBQYNKWHzwPqzEMwo4u0ysXlVRczmzY27BI,2303
4
+ automizor/datastore/_container.py,sha256=2WOthNSshwsRc_3vujcr8D1dK1sTfZvOBbLUTQEBYI0,713
5
+ automizor/datastore/_datastore.py,sha256=4HkNsctxfat64d05EWqweqjZPtUMjvG92SbRyvXIYLc,3336
5
6
  automizor/job/__init__.py,sha256=DNRuT6cyPQBaPRG4vNalCmEvcJQl-73b5ZDFOfNOwIg,1019
6
7
  automizor/job/_job.py,sha256=_-ehqPwJdY89mWm3_VAuh7KRJdv-8iUu6iMAzwGLHM0,5235
7
8
  automizor/log/__init__.py,sha256=gEr2SuwN1FgX1NMnbphjg8_gfSic9L15H3WC868A-TQ,2104
@@ -12,8 +13,8 @@ automizor/utils/__init__.py,sha256=2trRoR5lljYKbYdxmioSlvzajjQM0Wnoq3bvF9lEZ6w,8
12
13
  automizor/vault/__init__.py,sha256=UjRiW3J0R9ABXc1gXIPyS3cqNCwMWxx0l-C0PsIg7R0,1699
13
14
  automizor/vault/_container.py,sha256=-2y7kASigoIVAebuQBk-0R_sI4gfmvjsMLuMg_tR1xA,1945
14
15
  automizor/vault/_vault.py,sha256=uRsjOjzsstZpYwJoHNg_cpv803Dzo4T2oF6hwiG3Eww,4688
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,,
16
+ automizor-0.4.7.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
17
+ automizor-0.4.7.dist-info/METADATA,sha256=htYUcD3zFZeSVoC-AsbOdQGJNv8warmJijBy2YxWMoU,668
18
+ automizor-0.4.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
19
+ automizor-0.4.7.dist-info/top_level.txt,sha256=gScDy4I3tP6BMYAsTAlBXrxVh3E00zV0UioxwXJOI3Y,10
20
+ automizor-0.4.7.dist-info/RECORD,,