persidict 0.21.0__py3-none-any.whl → 0.23.0__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.
Potentially problematic release.
This version of persidict might be problematic. Click here for more details.
- persidict/file_dir_dict.py +23 -4
- persidict/nochange_const.py +1 -1
- persidict/persi_dict.py +19 -3
- persidict/s3_dict.py +13 -3
- {persidict-0.21.0.dist-info → persidict-0.23.0.dist-info}/METADATA +3 -2
- persidict-0.23.0.dist-info/RECORD +12 -0
- persidict-0.21.0.dist-info/RECORD +0 -12
- {persidict-0.21.0.dist-info → persidict-0.23.0.dist-info}/WHEEL +0 -0
persidict/file_dir_dict.py
CHANGED
|
@@ -115,8 +115,12 @@ class FileDirDict(PersiDict):
|
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
def get_params(self):
|
|
118
|
-
"""Return configuration parameters of the dictionary.
|
|
119
|
-
|
|
118
|
+
"""Return configuration parameters of the dictionary.
|
|
119
|
+
|
|
120
|
+
This method is needed to support Parameterizable API.
|
|
121
|
+
The method is absent in the original dict API.
|
|
122
|
+
"""
|
|
123
|
+
params = PersiDict.get_params(self)
|
|
120
124
|
additional_params = dict(
|
|
121
125
|
base_dir=self.base_dir
|
|
122
126
|
, file_type=self.file_type)
|
|
@@ -126,13 +130,19 @@ class FileDirDict(PersiDict):
|
|
|
126
130
|
|
|
127
131
|
@property
|
|
128
132
|
def base_url(self) -> str:
|
|
129
|
-
"""Return dictionary's URL
|
|
133
|
+
"""Return dictionary's URL.
|
|
134
|
+
|
|
135
|
+
This property is absent in the original dict API.
|
|
136
|
+
"""
|
|
130
137
|
return f"file://{self._base_dir}"
|
|
131
138
|
|
|
132
139
|
|
|
133
140
|
@property
|
|
134
141
|
def base_dir(self) -> str:
|
|
135
|
-
"""Return dictionary's base directory
|
|
142
|
+
"""Return dictionary's base directory.
|
|
143
|
+
|
|
144
|
+
This property is absent in the original dict API.
|
|
145
|
+
"""
|
|
136
146
|
return self._base_dir
|
|
137
147
|
|
|
138
148
|
|
|
@@ -212,6 +222,7 @@ class FileDirDict(PersiDict):
|
|
|
212
222
|
, digest_len=self.digest_len
|
|
213
223
|
, base_class_for_values=self.base_class_for_values)
|
|
214
224
|
|
|
225
|
+
|
|
215
226
|
def _read_from_file_impl(self, file_name:str) -> Any:
|
|
216
227
|
"""Read a value from a file. """
|
|
217
228
|
|
|
@@ -226,6 +237,7 @@ class FileDirDict(PersiDict):
|
|
|
226
237
|
result = f.read()
|
|
227
238
|
return result
|
|
228
239
|
|
|
240
|
+
|
|
229
241
|
def _read_from_file(self,file_name:str) -> Any:
|
|
230
242
|
"""Read a value from a file. """
|
|
231
243
|
|
|
@@ -244,6 +256,7 @@ class FileDirDict(PersiDict):
|
|
|
244
256
|
|
|
245
257
|
return self._read_from_file_impl(file_name)
|
|
246
258
|
|
|
259
|
+
|
|
247
260
|
def _save_to_file_impl(self, file_name:str, value:Any) -> None:
|
|
248
261
|
"""Save a value to a file. """
|
|
249
262
|
|
|
@@ -257,6 +270,7 @@ class FileDirDict(PersiDict):
|
|
|
257
270
|
with open(file_name, 'w') as f:
|
|
258
271
|
f.write(value)
|
|
259
272
|
|
|
273
|
+
|
|
260
274
|
def _save_to_file(self, file_name:str, value:Any) -> None:
|
|
261
275
|
"""Save a value to a file. """
|
|
262
276
|
|
|
@@ -276,12 +290,14 @@ class FileDirDict(PersiDict):
|
|
|
276
290
|
|
|
277
291
|
self._save_to_file_impl(file_name, value)
|
|
278
292
|
|
|
293
|
+
|
|
279
294
|
def __contains__(self, key:PersiDictKey) -> bool:
|
|
280
295
|
"""True if the dictionary has the specified key, else False. """
|
|
281
296
|
key = SafeStrTuple(key)
|
|
282
297
|
filename = self._build_full_path(key)
|
|
283
298
|
return os.path.isfile(filename)
|
|
284
299
|
|
|
300
|
+
|
|
285
301
|
def __getitem__(self, key:PersiDictKey) -> Any:
|
|
286
302
|
""" Implementation for x[y] syntax. """
|
|
287
303
|
key = SafeStrTuple(key)
|
|
@@ -296,6 +312,7 @@ class FileDirDict(PersiDict):
|
|
|
296
312
|
+ f" but it is {type(result)} instead.")
|
|
297
313
|
return result
|
|
298
314
|
|
|
315
|
+
|
|
299
316
|
def __setitem__(self, key:PersiDictKey, value:Any):
|
|
300
317
|
"""Set self[key] to value."""
|
|
301
318
|
|
|
@@ -319,6 +336,7 @@ class FileDirDict(PersiDict):
|
|
|
319
336
|
raise KeyError("Can't modify an immutable item")
|
|
320
337
|
self._save_to_file(filename, value)
|
|
321
338
|
|
|
339
|
+
|
|
322
340
|
def __delitem__(self, key:PersiDictKey) -> None:
|
|
323
341
|
"""Delete self[key]."""
|
|
324
342
|
key = SafeStrTuple(key)
|
|
@@ -328,6 +346,7 @@ class FileDirDict(PersiDict):
|
|
|
328
346
|
raise KeyError(f"File {filename} does not exist")
|
|
329
347
|
os.remove(filename)
|
|
330
348
|
|
|
349
|
+
|
|
331
350
|
def _generic_iter(self, iter_type: str):
|
|
332
351
|
"""Underlying implementation for .items()/.keys()/.values() iterators"""
|
|
333
352
|
assert iter_type in {"keys", "values", "items"}
|
persidict/nochange_const.py
CHANGED
persidict/persi_dict.py
CHANGED
|
@@ -93,10 +93,15 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
93
93
|
raise ValueError("digest_len must be non-negative")
|
|
94
94
|
self.immutable_items = bool(immutable_items)
|
|
95
95
|
self.base_class_for_values = base_class_for_values
|
|
96
|
+
ParameterizableClass.__init__(self)
|
|
96
97
|
|
|
97
98
|
|
|
98
99
|
def get_params(self):
|
|
99
|
-
"""Return a dictionary of parameters for the PersiDict object.
|
|
100
|
+
"""Return a dictionary of parameters for the PersiDict object.
|
|
101
|
+
|
|
102
|
+
This method is needed to support Parameterizable API.
|
|
103
|
+
The method is absent in the original dict API.
|
|
104
|
+
"""
|
|
100
105
|
params = dict(
|
|
101
106
|
immutable_items=self.immutable_items
|
|
102
107
|
, digest_len=self.digest_len
|
|
@@ -108,14 +113,20 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
108
113
|
@property
|
|
109
114
|
@abstractmethod
|
|
110
115
|
def base_url(self):
|
|
111
|
-
"""Return dictionary's URL
|
|
116
|
+
"""Return dictionary's URL
|
|
117
|
+
|
|
118
|
+
This property is absent in the original dict API.
|
|
119
|
+
"""
|
|
112
120
|
raise NotImplementedError
|
|
113
121
|
|
|
114
122
|
|
|
115
123
|
@property
|
|
116
124
|
@abstractmethod
|
|
117
125
|
def base_dir(self):
|
|
118
|
-
"""Return dictionary's base directory in the local filesystem
|
|
126
|
+
"""Return dictionary's base directory in the local filesystem.
|
|
127
|
+
|
|
128
|
+
This property is absent in the original dict API.
|
|
129
|
+
"""
|
|
119
130
|
raise NotImplementedError
|
|
120
131
|
|
|
121
132
|
|
|
@@ -224,9 +235,11 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
224
235
|
except:
|
|
225
236
|
return False
|
|
226
237
|
|
|
238
|
+
|
|
227
239
|
def __getstate__(self):
|
|
228
240
|
raise TypeError("PersiDict is not picklable.")
|
|
229
241
|
|
|
242
|
+
|
|
230
243
|
def __setstate__(self, state):
|
|
231
244
|
raise TypeError("PersiDict is not picklable.")
|
|
232
245
|
|
|
@@ -275,6 +288,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
275
288
|
"""
|
|
276
289
|
raise NotImplementedError
|
|
277
290
|
|
|
291
|
+
|
|
278
292
|
def subdicts(self) -> dict[str, PersiDict]:
|
|
279
293
|
"""Get a dictionary of sub-dictionaries.
|
|
280
294
|
|
|
@@ -337,6 +351,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
337
351
|
result = all_keys[:max_n]
|
|
338
352
|
return result
|
|
339
353
|
|
|
354
|
+
|
|
340
355
|
def oldest_values(self, max_n=None):
|
|
341
356
|
"""Return max_n the oldest values in the dictionary.
|
|
342
357
|
|
|
@@ -346,6 +361,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
346
361
|
"""
|
|
347
362
|
return [self[k] for k in self.oldest_keys(max_n)]
|
|
348
363
|
|
|
364
|
+
|
|
349
365
|
def newest_values(self, max_n=None):
|
|
350
366
|
"""Return max_n the newest values in the dictionary.
|
|
351
367
|
|
persidict/s3_dict.py
CHANGED
|
@@ -111,7 +111,11 @@ class S3Dict(PersiDict):
|
|
|
111
111
|
|
|
112
112
|
|
|
113
113
|
def get_params(self):
|
|
114
|
-
"""Return configuration parameters of the object as a dictionary.
|
|
114
|
+
"""Return configuration parameters of the object as a dictionary.
|
|
115
|
+
|
|
116
|
+
This method is needed to support Parameterizable API.
|
|
117
|
+
The method is absent in the original dict API.
|
|
118
|
+
"""
|
|
115
119
|
params = self.local_cache.get_params()
|
|
116
120
|
params["region"] = self.region
|
|
117
121
|
params["bucket_name"] = self.bucket_name
|
|
@@ -121,13 +125,19 @@ class S3Dict(PersiDict):
|
|
|
121
125
|
|
|
122
126
|
@property
|
|
123
127
|
def base_url(self):
|
|
124
|
-
"""Return dictionary's URl
|
|
128
|
+
"""Return dictionary's URl.
|
|
129
|
+
|
|
130
|
+
This property is absent in the original dict API.
|
|
131
|
+
"""
|
|
125
132
|
return f"s3://{self.bucket_name}/{self.root_prefix}"
|
|
126
133
|
|
|
127
134
|
|
|
128
135
|
@property
|
|
129
136
|
def base_dir(self) -> str:
|
|
130
|
-
"""Return dictionary's base directory in the local filesystem
|
|
137
|
+
"""Return dictionary's base directory in the local filesystem.
|
|
138
|
+
|
|
139
|
+
This property is absent in the original dict API.
|
|
140
|
+
"""
|
|
131
141
|
return self.local_cache.base_dir
|
|
132
142
|
|
|
133
143
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: persidict
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.23.0
|
|
4
4
|
Summary: Simple persistent key-value store for Python. Values are stored as files on a disk or as S3 objects on AWS cloud.
|
|
5
5
|
Keywords: persistence,dicts,distributed,parallel
|
|
6
6
|
Author: Vlad (Volodymyr) Pavlov
|
|
@@ -161,7 +161,8 @@ that simultaneously work with the same instance of a dictionary.
|
|
|
161
161
|
`oldest_keys()`, `newest_values()`, `oldest_values()`,
|
|
162
162
|
`get_params()`, `get_metaparams()`, and `get_default_metaparams()`,
|
|
163
163
|
which are not available in native Python dicts.
|
|
164
|
-
* You can use NO_CHANGE constant
|
|
164
|
+
* You can use NO_CHANGE constant as a fake new value
|
|
165
|
+
to avoid actually setting/updating a value.
|
|
165
166
|
|
|
166
167
|
## Fine Tuning
|
|
167
168
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
persidict/.DS_Store,sha256=d65165279105ca6773180500688df4bdc69a2c7b771752f0a46ef120b7fd8ec3,6148
|
|
2
|
+
persidict/__init__.py,sha256=34e758e6e566fc18225214b430cf492938d6f3d48b36e678ab947f15c780a699,1185
|
|
3
|
+
persidict/file_dir_dict.py,sha256=8b722dbd30b179b26cd5cddd567487648e24db33949aa9785800e9861be1ccde,14412
|
|
4
|
+
persidict/nochange_const.py,sha256=a449c356b44a145b8118bdd846d3e517f9211887b39688e7918ddb214e856f25,436
|
|
5
|
+
persidict/persi_dict.py,sha256=5bc315b09e422b37b4de439e581b28e4a5ed1cd5bc3346cf3a33662314a8afa2,12041
|
|
6
|
+
persidict/s3_dict.py,sha256=f757a5a1fa6c0865fcd9468eb248dab3d2e8aacdcfd108dbfb137a3a1522b161,12099
|
|
7
|
+
persidict/safe_chars.py,sha256=59a20e96205d2e5675d827a911ad42ddbd553f1bd7e2cda1be765a9c2c4ce814,565
|
|
8
|
+
persidict/safe_str_tuple.py,sha256=71393904bdebfb213ad8429fed59e04da52964076c01324f2238821aa4339325,3717
|
|
9
|
+
persidict/safe_str_tuple_signing.py,sha256=e6e0a3015651a8ea2ef8aa43670f84c5ba1cdfedefb9ac8932aaebb7c699d1c9,3742
|
|
10
|
+
persidict-0.23.0.dist-info/WHEEL,sha256=c133ef911c90b05f7e14d8679ba99146f9154fcd271b7398cf8f672283b94e05,79
|
|
11
|
+
persidict-0.23.0.dist-info/METADATA,sha256=a48859d85a3e0d532c80ba35b15e92e76424a3f057266a68a8f0470d44d38a68,9193
|
|
12
|
+
persidict-0.23.0.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
persidict/.DS_Store,sha256=d65165279105ca6773180500688df4bdc69a2c7b771752f0a46ef120b7fd8ec3,6148
|
|
2
|
-
persidict/__init__.py,sha256=34e758e6e566fc18225214b430cf492938d6f3d48b36e678ab947f15c780a699,1185
|
|
3
|
-
persidict/file_dir_dict.py,sha256=438558ea1f06a8e280609a4aaa94a6fea05d82ce2ef79bd401af94b014da82a6,14132
|
|
4
|
-
persidict/nochange_const.py,sha256=679081a68766dfe3da694bca73500fc971cc7418074bfe168ae8b13609c73d80,437
|
|
5
|
-
persidict/persi_dict.py,sha256=7301a8a6a41bb4c2fbd29d31e0421287d53f6a88c66e9324656db1043e5e2b55,11728
|
|
6
|
-
persidict/s3_dict.py,sha256=acc676f92ae993364f1fa70d74e95c182b2f263f29eae99f3b554f45aededfe5,11834
|
|
7
|
-
persidict/safe_chars.py,sha256=59a20e96205d2e5675d827a911ad42ddbd553f1bd7e2cda1be765a9c2c4ce814,565
|
|
8
|
-
persidict/safe_str_tuple.py,sha256=71393904bdebfb213ad8429fed59e04da52964076c01324f2238821aa4339325,3717
|
|
9
|
-
persidict/safe_str_tuple_signing.py,sha256=e6e0a3015651a8ea2ef8aa43670f84c5ba1cdfedefb9ac8932aaebb7c699d1c9,3742
|
|
10
|
-
persidict-0.21.0.dist-info/WHEEL,sha256=c133ef911c90b05f7e14d8679ba99146f9154fcd271b7398cf8f672283b94e05,79
|
|
11
|
-
persidict-0.21.0.dist-info/METADATA,sha256=7e184bbdf462da4cb66a3abb276975d28d30bf1076ea5a9ed706c5e78e6595bf,9172
|
|
12
|
-
persidict-0.21.0.dist-info/RECORD,,
|
|
File without changes
|