cloud-python-vars 0.2.0__py3-none-any.whl → 0.2.1__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.
- {cloud_python_vars-0.2.0.dist-info → cloud_python_vars-0.2.1.dist-info}/METADATA +17 -1
- cloud_python_vars-0.2.1.dist-info/RECORD +6 -0
- cloud_variables.py +71 -4
- cloud_python_vars-0.2.0.dist-info/RECORD +0 -6
- {cloud_python_vars-0.2.0.dist-info → cloud_python_vars-0.2.1.dist-info}/WHEEL +0 -0
- {cloud_python_vars-0.2.0.dist-info → cloud_python_vars-0.2.1.dist-info}/licenses/LICENSE +0 -0
- {cloud_python_vars-0.2.0.dist-info → cloud_python_vars-0.2.1.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloud-python-vars
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: To manage and create raw Python variables on cloud servers.
|
|
5
5
|
Author-email: ThatOnePythonDev <khakhang2h5e@gmail.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -58,6 +58,14 @@ print(cloudvar.items()) # {'string': 'Hello, World!', 'list': [1, 2, 3, 4]}
|
|
|
58
58
|
# Clearing everything
|
|
59
59
|
cloudvar.clear()
|
|
60
60
|
print(cloudvar.items()) # {}
|
|
61
|
+
|
|
62
|
+
# Setting the client's data directly
|
|
63
|
+
cloudvar.set_dict({"key1": ["item1", "item2", "item3"], "key2": "value2", "key3": 3})
|
|
64
|
+
print(cloudvar.items()) # {'key1': ['item1', 'item2', 'item3'], 'key2': 'value2', 'key3': 3}
|
|
65
|
+
|
|
66
|
+
# __ior__
|
|
67
|
+
cloudvar |= {"key1": "value1", "key3": "value3"}
|
|
68
|
+
print(cloudvar.items()) # {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
|
|
61
69
|
```
|
|
62
70
|
|
|
63
71
|
### Example 2 for the class `AsyncCloudVar`.
|
|
@@ -100,6 +108,14 @@ async def main(): # Use asynchronous functions for full functionality access.
|
|
|
100
108
|
await async_cloudvar.clear()
|
|
101
109
|
print(await async_cloudvar.items()) # {}
|
|
102
110
|
|
|
111
|
+
# Setting the client's data directly
|
|
112
|
+
await async_cloudvar.set_dict({"key1": ["item1", "item2", "item3"], "key2": "value2", "key3": 3})
|
|
113
|
+
print(await async_cloudvar.items()) # {'key1': ['item1', 'item2', 'item3'], 'key2': 'value2', 'key3': 3}
|
|
114
|
+
|
|
115
|
+
# __ior__
|
|
116
|
+
async_cloudvar |= {"key1": "value1", "key3": "value3"}
|
|
117
|
+
print(await async_cloudvar.items()) # {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
|
|
118
|
+
|
|
103
119
|
asyncio.run(main())
|
|
104
120
|
```
|
|
105
121
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
cloud_variables.py,sha256=OpH68A3eJJu0I3x2U1F_JkBPSq7wSPPJqJU85DFPiBs,14400
|
|
2
|
+
cloud_python_vars-0.2.1.dist-info/licenses/LICENSE,sha256=QrYZJWmrewKHOtQwd1ymTUDpPzhnXt9Fhv6PGf-JfGs,35788
|
|
3
|
+
cloud_python_vars-0.2.1.dist-info/METADATA,sha256=grelx0CWMnxTPn5vQ-C2u0iUx5IRgzd_pieyGe53JzU,3890
|
|
4
|
+
cloud_python_vars-0.2.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
cloud_python_vars-0.2.1.dist-info/top_level.txt,sha256=DxTkZ9m7oYGS873O2K7iiP6cP4t0LRqo9jL1wn-Voog,16
|
|
6
|
+
cloud_python_vars-0.2.1.dist-info/RECORD,,
|
cloud_variables.py
CHANGED
|
@@ -15,18 +15,22 @@ Visit the link https://console.upstash.com/redis to create tokens and urls.
|
|
|
15
15
|
:meth:`CloudVar.__setitem__`
|
|
16
16
|
:meth:`CloudVar.__getitem__`
|
|
17
17
|
:meth:`CloudVar.__delitem__`
|
|
18
|
+
:meth:`CloudVar.__ior__`
|
|
19
|
+
:meth:`CloudVar.set_dict`
|
|
18
20
|
:meth:`CloudVar.pop`
|
|
19
21
|
:meth:`CloudVar.items`
|
|
20
22
|
:meth:`AsyncCloudVar.__init__`
|
|
21
23
|
:meth:`AsyncCloudVar.__setitem__`
|
|
22
24
|
:meth:`AsyncCloudVar.__getitem__`
|
|
23
25
|
:meth:`AsyncCloudVar.__delitem__`
|
|
26
|
+
:meth:`AsyncCloudVar.__ior__`
|
|
27
|
+
:meth:`AsyncCloudVar.set_dict`
|
|
24
28
|
:meth:`AsyncCloudVar.pop`
|
|
25
29
|
:meth:`AsyncCloudVar.items`
|
|
26
30
|
:meth:`CloudProxy.__init__`
|
|
27
31
|
:meth:`CloudProxy.__repr__`
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
Imports:
|
|
30
34
|
* :mod:`__future__`
|
|
31
35
|
* :mod:`typing`
|
|
32
36
|
* :mod:`time`
|
|
@@ -40,7 +44,9 @@ The example code for the class `CloudVar`:
|
|
|
40
44
|
import cloud_variable as cv
|
|
41
45
|
from typing import Any # I love type annotating :)
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
|
|
48
|
+
# You could use optional delay or tb parameters to customize this too
|
|
49
|
+
cloudvar: cv.CloudVar = cv.CloudVar("https://apparent-gopher-******.upstash.io", "******") # Use your actual values.
|
|
44
50
|
|
|
45
51
|
while True:
|
|
46
52
|
cloudvar["key"] = "value"
|
|
@@ -59,6 +65,12 @@ while True:
|
|
|
59
65
|
|
|
60
66
|
# Clearing the entire client data:
|
|
61
67
|
cloudvar.clear()
|
|
68
|
+
|
|
69
|
+
# Setting the client data:
|
|
70
|
+
cloudvar.set_dict({"data": {"score": 100, "player": "Player123"}})
|
|
71
|
+
|
|
72
|
+
# Whatever it is idk :P |= / __ior__
|
|
73
|
+
cloudvar |= {"some_key_here": "some value here 123"}
|
|
62
74
|
```
|
|
63
75
|
|
|
64
76
|
The example code for the class `AsyncCloudVar`:
|
|
@@ -69,7 +81,8 @@ from typing import Any # I love type annotating :)
|
|
|
69
81
|
|
|
70
82
|
|
|
71
83
|
async def main() -> None: # You're recommended to put this in an asynchronous function.
|
|
72
|
-
|
|
84
|
+
# You could use optional delay or tb parameters to customize this too
|
|
85
|
+
async_cloudvar: cv.AsyncCloudVar = cv.AsyncCloudVar("https://apparent-gopher-******.upstash.io", "******") # Use your actual values.
|
|
73
86
|
async_cloudvar.start()
|
|
74
87
|
|
|
75
88
|
while True:
|
|
@@ -90,6 +103,12 @@ async def main() -> None: # You're recommended to put this in an asynchronous fu
|
|
|
90
103
|
# Clearing the entire client data:
|
|
91
104
|
await async_cloudvar.clear()
|
|
92
105
|
|
|
106
|
+
# Setting the data:
|
|
107
|
+
await async_cloudvar.set_dict("data": {"score": 100, "player": "Player123"})
|
|
108
|
+
|
|
109
|
+
# Whatever it is idk :P |= / __ior__
|
|
110
|
+
async_cloudvar |= {"some_key_here": "some value here 123"}
|
|
111
|
+
|
|
93
112
|
... # some long/complex task here
|
|
94
113
|
```
|
|
95
114
|
"""
|
|
@@ -138,6 +157,7 @@ class CloudVar(redis.Redis):
|
|
|
138
157
|
rest_retry_interval: float = 3,
|
|
139
158
|
allow_telemetry: bool = True,
|
|
140
159
|
read_your_writes: bool = True,
|
|
160
|
+
*,
|
|
141
161
|
delay: float = 0.1,
|
|
142
162
|
tb: Literal["strict", "log", "ignore"] = "log"
|
|
143
163
|
) -> None:
|
|
@@ -217,10 +237,24 @@ class CloudVar(redis.Redis):
|
|
|
217
237
|
return self.__data[key].value
|
|
218
238
|
|
|
219
239
|
def __delitem__(self, key: str) -> None:
|
|
220
|
-
"""
|
|
240
|
+
"""
|
|
241
|
+
Deletes the key from the client.
|
|
242
|
+
|
|
243
|
+
:param
|
|
244
|
+
"""
|
|
221
245
|
|
|
222
246
|
self.pop(key)
|
|
223
247
|
|
|
248
|
+
def __ior__(self, other: dict[str, Any]) -> None:
|
|
249
|
+
"""
|
|
250
|
+
Sets multiple key-value pairs.
|
|
251
|
+
|
|
252
|
+
:param other: The dictionary to change the data to.
|
|
253
|
+
:type other: dict[str, Any]
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
self.__data |= {k: CloudProxy(v) for k, v in self.items()}
|
|
257
|
+
|
|
224
258
|
def pop(self, *keys: str) -> tuple[Any, ...]:
|
|
225
259
|
"""
|
|
226
260
|
Deletes keys from the client and returns them all as a tuple.
|
|
@@ -261,6 +295,17 @@ class CloudVar(redis.Redis):
|
|
|
261
295
|
|
|
262
296
|
return {k: self.get(k) for k in self.keys(r"[\s\S]*") if self.get(k)}
|
|
263
297
|
|
|
298
|
+
def set_dict(self, dictionary: dict[str, Any], /) -> None:
|
|
299
|
+
"""
|
|
300
|
+
Sets the data of the client.
|
|
301
|
+
|
|
302
|
+
:param dictionary: The dictionary value.
|
|
303
|
+
:type dictionary: dict[str, Any]
|
|
304
|
+
"""
|
|
305
|
+
|
|
306
|
+
self.clear()
|
|
307
|
+
self.__data = dictionary
|
|
308
|
+
|
|
264
309
|
class AsyncCloudVar(redis.AsyncRedis):
|
|
265
310
|
"""
|
|
266
311
|
An asynchronous Cloud Variable class that contains some methods for managing cloud variables.
|
|
@@ -275,6 +320,7 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
275
320
|
rest_retry_interval: float = 3,
|
|
276
321
|
allow_telemetry: bool = True,
|
|
277
322
|
read_your_writes: bool = True,
|
|
323
|
+
*,
|
|
278
324
|
delay: float = 0.1,
|
|
279
325
|
tb: Literal["strict", "log", "ignore"] = "log"
|
|
280
326
|
) -> None:
|
|
@@ -357,6 +403,27 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
357
403
|
"""Deletes the key from the client."""
|
|
358
404
|
|
|
359
405
|
await self.pop(key)
|
|
406
|
+
|
|
407
|
+
def __ior__(self, other: dict[str, Any]) -> None:
|
|
408
|
+
"""
|
|
409
|
+
Sets multiple key-value pairs.
|
|
410
|
+
|
|
411
|
+
:param other: The dictionary to change the data to.
|
|
412
|
+
:type other: dict[str, Any]
|
|
413
|
+
"""
|
|
414
|
+
|
|
415
|
+
self.__data |= {k: CloudProxy(v) for k, v in other.items()}
|
|
416
|
+
|
|
417
|
+
async def set_dict(self, dictionary: dict[str, Any]) -> None:
|
|
418
|
+
"""
|
|
419
|
+
Sets the data of the client.
|
|
420
|
+
|
|
421
|
+
:param dictionary: The dictionary value.
|
|
422
|
+
:type dictionary: dict[str, Any]
|
|
423
|
+
"""
|
|
424
|
+
|
|
425
|
+
await self.clear()
|
|
426
|
+
self.__data = {k: CloudProxy(v) for k, v in dictionary.items()}
|
|
360
427
|
|
|
361
428
|
async def pop(self, *keys: str) -> tuple[Any, ...]:
|
|
362
429
|
"""
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
cloud_variables.py,sha256=5Yfsd697M9hZG0fvk7eiGglknHVx57HzFf_akPjJNpI,12359
|
|
2
|
-
cloud_python_vars-0.2.0.dist-info/licenses/LICENSE,sha256=QrYZJWmrewKHOtQwd1ymTUDpPzhnXt9Fhv6PGf-JfGs,35788
|
|
3
|
-
cloud_python_vars-0.2.0.dist-info/METADATA,sha256=7hQbkTHZZC7MIM3Ifd9d_erQFg0aG237e-pCnqAxpUE,3088
|
|
4
|
-
cloud_python_vars-0.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
-
cloud_python_vars-0.2.0.dist-info/top_level.txt,sha256=DxTkZ9m7oYGS873O2K7iiP6cP4t0LRqo9jL1wn-Voog,16
|
|
6
|
-
cloud_python_vars-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|