cloud-python-vars 0.1.2__tar.gz → 0.2.1__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.
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/PKG-INFO +17 -1
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/README.md +16 -0
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/cloud_python_vars.egg-info/PKG-INFO +17 -1
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/cloud_variables.py +107 -13
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/pyproject.toml +1 -1
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/LICENSE +0 -0
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/cloud_python_vars.egg-info/SOURCES.txt +0 -0
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/cloud_python_vars.egg-info/dependency_links.txt +0 -0
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/cloud_python_vars.egg-info/requires.txt +0 -0
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/cloud_python_vars.egg-info/top_level.txt +0 -0
- {cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloud-python-vars
|
|
3
|
-
Version: 0.1
|
|
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
|
|
|
@@ -44,6 +44,14 @@ print(cloudvar.items()) # {'string': 'Hello, World!', 'list': [1, 2, 3, 4]}
|
|
|
44
44
|
# Clearing everything
|
|
45
45
|
cloudvar.clear()
|
|
46
46
|
print(cloudvar.items()) # {}
|
|
47
|
+
|
|
48
|
+
# Setting the client's data directly
|
|
49
|
+
cloudvar.set_dict({"key1": ["item1", "item2", "item3"], "key2": "value2", "key3": 3})
|
|
50
|
+
print(cloudvar.items()) # {'key1': ['item1', 'item2', 'item3'], 'key2': 'value2', 'key3': 3}
|
|
51
|
+
|
|
52
|
+
# __ior__
|
|
53
|
+
cloudvar |= {"key1": "value1", "key3": "value3"}
|
|
54
|
+
print(cloudvar.items()) # {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
|
|
47
55
|
```
|
|
48
56
|
|
|
49
57
|
### Example 2 for the class `AsyncCloudVar`.
|
|
@@ -86,6 +94,14 @@ async def main(): # Use asynchronous functions for full functionality access.
|
|
|
86
94
|
await async_cloudvar.clear()
|
|
87
95
|
print(await async_cloudvar.items()) # {}
|
|
88
96
|
|
|
97
|
+
# Setting the client's data directly
|
|
98
|
+
await async_cloudvar.set_dict({"key1": ["item1", "item2", "item3"], "key2": "value2", "key3": 3})
|
|
99
|
+
print(await async_cloudvar.items()) # {'key1': ['item1', 'item2', 'item3'], 'key2': 'value2', 'key3': 3}
|
|
100
|
+
|
|
101
|
+
# __ior__
|
|
102
|
+
async_cloudvar |= {"key1": "value1", "key3": "value3"}
|
|
103
|
+
print(await async_cloudvar.items()) # {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
|
|
104
|
+
|
|
89
105
|
asyncio.run(main())
|
|
90
106
|
```
|
|
91
107
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloud-python-vars
|
|
3
|
-
Version: 0.1
|
|
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
|
|
|
@@ -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,17 +103,23 @@ 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
|
"""
|
|
96
115
|
|
|
97
116
|
from __future__ import annotations
|
|
98
117
|
|
|
99
|
-
from typing import Any, Literal, Never
|
|
100
|
-
|
|
101
|
-
import time
|
|
102
118
|
import asyncio
|
|
103
119
|
import threading
|
|
120
|
+
import time
|
|
121
|
+
from typing import Any, Literal, override
|
|
122
|
+
|
|
104
123
|
import upstash_redis as redis
|
|
105
124
|
|
|
106
125
|
|
|
@@ -120,6 +139,7 @@ class CloudProxy:
|
|
|
120
139
|
|
|
121
140
|
self.value: Any = value
|
|
122
141
|
|
|
142
|
+
@override
|
|
123
143
|
def __repr__(self) -> str:
|
|
124
144
|
return f"CloudProxy({self.value})"
|
|
125
145
|
|
|
@@ -137,6 +157,9 @@ class CloudVar(redis.Redis):
|
|
|
137
157
|
rest_retry_interval: float = 3,
|
|
138
158
|
allow_telemetry: bool = True,
|
|
139
159
|
read_your_writes: bool = True,
|
|
160
|
+
*,
|
|
161
|
+
delay: float = 0.1,
|
|
162
|
+
tb: Literal["strict", "log", "ignore"] = "log"
|
|
140
163
|
) -> None:
|
|
141
164
|
"""
|
|
142
165
|
To initialize the class.
|
|
@@ -148,6 +171,8 @@ class CloudVar(redis.Redis):
|
|
|
148
171
|
:param rest_retry_interval: The number of seconds the client waits before retrying a new request. The default is 3.
|
|
149
172
|
:param allow_telemetry: Controls whether the client is allowed to send telemetry data. The default is True.
|
|
150
173
|
:param read_your_writes: Allows whether the client is allowed to read your writes. The default is True.
|
|
174
|
+
:param delay: The delay to prevent CPU over-usage and network spamming. The default is 0.1.
|
|
175
|
+
:param tb: Controls what to do when an error occurs. 'strict' for letting it raise, 'log' for catching and logging the error, 'ignore' for passing silently. The default is 'log'.
|
|
151
176
|
|
|
152
177
|
:type url: str
|
|
153
178
|
:type token: str
|
|
@@ -156,6 +181,8 @@ class CloudVar(redis.Redis):
|
|
|
156
181
|
:type rest_retry_interval: float
|
|
157
182
|
:type allow_telemetry: bool
|
|
158
183
|
:type read_your_writes: bool
|
|
184
|
+
:type delay: float
|
|
185
|
+
:type tb: Literal["strict", "log", "ignore"]
|
|
159
186
|
"""
|
|
160
187
|
|
|
161
188
|
super().__init__(url, token, rest_encoding, rest_retries, rest_retry_interval, allow_telemetry, read_your_writes,)
|
|
@@ -165,14 +192,23 @@ class CloudVar(redis.Redis):
|
|
|
165
192
|
self.__thread: threading.Thread = threading.Thread(target=self.__loop)
|
|
166
193
|
self.__thread.start()
|
|
167
194
|
|
|
195
|
+
self.delay: float = delay
|
|
196
|
+
self.tb: str = tb
|
|
197
|
+
|
|
168
198
|
def __loop(self) -> None:
|
|
169
199
|
try:
|
|
170
200
|
while True:
|
|
171
201
|
for k, v in self.__data.copy().items():
|
|
172
202
|
self.set(k, repr(v))
|
|
173
|
-
time.sleep(
|
|
203
|
+
time.sleep(self.delay)
|
|
174
204
|
except Exception as e:
|
|
175
|
-
|
|
205
|
+
match self.tb:
|
|
206
|
+
case "strict":
|
|
207
|
+
raise
|
|
208
|
+
case "log":
|
|
209
|
+
print(e.__traceback__)
|
|
210
|
+
case _:
|
|
211
|
+
pass
|
|
176
212
|
|
|
177
213
|
def __setitem__(self, key: str, value: Any) -> None:
|
|
178
214
|
"""
|
|
@@ -201,10 +237,24 @@ class CloudVar(redis.Redis):
|
|
|
201
237
|
return self.__data[key].value
|
|
202
238
|
|
|
203
239
|
def __delitem__(self, key: str) -> None:
|
|
204
|
-
"""
|
|
240
|
+
"""
|
|
241
|
+
Deletes the key from the client.
|
|
242
|
+
|
|
243
|
+
:param
|
|
244
|
+
"""
|
|
205
245
|
|
|
206
246
|
self.pop(key)
|
|
207
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
|
+
|
|
208
258
|
def pop(self, *keys: str) -> tuple[Any, ...]:
|
|
209
259
|
"""
|
|
210
260
|
Deletes keys from the client and returns them all as a tuple.
|
|
@@ -221,7 +271,7 @@ class CloudVar(redis.Redis):
|
|
|
221
271
|
|
|
222
272
|
for key in keys:
|
|
223
273
|
del self.__data[key]
|
|
224
|
-
|
|
274
|
+
|
|
225
275
|
return tuple(values)
|
|
226
276
|
|
|
227
277
|
def clear(self) -> None:
|
|
@@ -245,6 +295,17 @@ class CloudVar(redis.Redis):
|
|
|
245
295
|
|
|
246
296
|
return {k: self.get(k) for k in self.keys(r"[\s\S]*") if self.get(k)}
|
|
247
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
|
+
|
|
248
309
|
class AsyncCloudVar(redis.AsyncRedis):
|
|
249
310
|
"""
|
|
250
311
|
An asynchronous Cloud Variable class that contains some methods for managing cloud variables.
|
|
@@ -259,6 +320,9 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
259
320
|
rest_retry_interval: float = 3,
|
|
260
321
|
allow_telemetry: bool = True,
|
|
261
322
|
read_your_writes: bool = True,
|
|
323
|
+
*,
|
|
324
|
+
delay: float = 0.1,
|
|
325
|
+
tb: Literal["strict", "log", "ignore"] = "log"
|
|
262
326
|
) -> None:
|
|
263
327
|
"""
|
|
264
328
|
To initialize the class.
|
|
@@ -284,6 +348,9 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
284
348
|
|
|
285
349
|
self.__data: dict[str, CloudProxy] = {}
|
|
286
350
|
|
|
351
|
+
self.delay: float = delay
|
|
352
|
+
self.tb: str = tb
|
|
353
|
+
|
|
287
354
|
def start(self) -> None:
|
|
288
355
|
"""Starts the instance's process."""
|
|
289
356
|
|
|
@@ -293,12 +360,18 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
293
360
|
try:
|
|
294
361
|
while True:
|
|
295
362
|
for k, v in self.__data.copy().items():
|
|
296
|
-
await self.set(k, repr(v))
|
|
363
|
+
_ = await self.set(k, repr(v))
|
|
297
364
|
await asyncio.sleep(0.1)
|
|
298
365
|
except Exception as e:
|
|
299
|
-
|
|
366
|
+
match self.tb:
|
|
367
|
+
case "strict":
|
|
368
|
+
raise
|
|
369
|
+
case "log":
|
|
370
|
+
print(e.__traceback__)
|
|
371
|
+
case _:
|
|
372
|
+
pass
|
|
300
373
|
|
|
301
|
-
asyncio.create_task(task())
|
|
374
|
+
_ = asyncio.create_task(task())
|
|
302
375
|
|
|
303
376
|
def __setitem__(self, key: str, value: Any) -> None:
|
|
304
377
|
"""
|
|
@@ -330,6 +403,27 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
330
403
|
"""Deletes the key from the client."""
|
|
331
404
|
|
|
332
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()}
|
|
333
427
|
|
|
334
428
|
async def pop(self, *keys: str) -> tuple[Any, ...]:
|
|
335
429
|
"""
|
|
File without changes
|
|
File without changes
|
{cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/cloud_python_vars.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{cloud_python_vars-0.1.2 → cloud_python_vars-0.2.1}/cloud_python_vars.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|