persidict 0.21.1__tar.gz → 0.23.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.
Potentially problematic release.
This version of persidict might be problematic. Click here for more details.
- {persidict-0.21.1 → persidict-0.23.1}/PKG-INFO +1 -1
- {persidict-0.21.1 → persidict-0.23.1}/pyproject.toml +1 -1
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/file_dir_dict.py +25 -5
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/persi_dict.py +21 -4
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/s3_dict.py +15 -4
- {persidict-0.21.1 → persidict-0.23.1}/README.md +0 -0
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/.DS_Store +0 -0
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/__init__.py +0 -0
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/nochange_const.py +0 -0
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/safe_chars.py +0 -0
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/safe_str_tuple.py +0 -0
- {persidict-0.21.1 → persidict-0.23.1}/src/persidict/safe_str_tuple_signing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: persidict
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.23.1
|
|
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
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "persidict"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.23.1"
|
|
8
8
|
description = "Simple persistent key-value store for Python. Values are stored as files on a disk or as S3 objects on AWS cloud."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -115,24 +115,35 @@ 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)
|
|
123
127
|
params.update(additional_params)
|
|
124
|
-
|
|
128
|
+
sorted_params = dict(sorted(params.items()))
|
|
129
|
+
return sorted_params
|
|
125
130
|
|
|
126
131
|
|
|
127
132
|
@property
|
|
128
133
|
def base_url(self) -> str:
|
|
129
|
-
"""Return dictionary's URL
|
|
134
|
+
"""Return dictionary's URL.
|
|
135
|
+
|
|
136
|
+
This property is absent in the original dict API.
|
|
137
|
+
"""
|
|
130
138
|
return f"file://{self._base_dir}"
|
|
131
139
|
|
|
132
140
|
|
|
133
141
|
@property
|
|
134
142
|
def base_dir(self) -> str:
|
|
135
|
-
"""Return dictionary's base directory
|
|
143
|
+
"""Return dictionary's base directory.
|
|
144
|
+
|
|
145
|
+
This property is absent in the original dict API.
|
|
146
|
+
"""
|
|
136
147
|
return self._base_dir
|
|
137
148
|
|
|
138
149
|
|
|
@@ -212,6 +223,7 @@ class FileDirDict(PersiDict):
|
|
|
212
223
|
, digest_len=self.digest_len
|
|
213
224
|
, base_class_for_values=self.base_class_for_values)
|
|
214
225
|
|
|
226
|
+
|
|
215
227
|
def _read_from_file_impl(self, file_name:str) -> Any:
|
|
216
228
|
"""Read a value from a file. """
|
|
217
229
|
|
|
@@ -226,6 +238,7 @@ class FileDirDict(PersiDict):
|
|
|
226
238
|
result = f.read()
|
|
227
239
|
return result
|
|
228
240
|
|
|
241
|
+
|
|
229
242
|
def _read_from_file(self,file_name:str) -> Any:
|
|
230
243
|
"""Read a value from a file. """
|
|
231
244
|
|
|
@@ -244,6 +257,7 @@ class FileDirDict(PersiDict):
|
|
|
244
257
|
|
|
245
258
|
return self._read_from_file_impl(file_name)
|
|
246
259
|
|
|
260
|
+
|
|
247
261
|
def _save_to_file_impl(self, file_name:str, value:Any) -> None:
|
|
248
262
|
"""Save a value to a file. """
|
|
249
263
|
|
|
@@ -257,6 +271,7 @@ class FileDirDict(PersiDict):
|
|
|
257
271
|
with open(file_name, 'w') as f:
|
|
258
272
|
f.write(value)
|
|
259
273
|
|
|
274
|
+
|
|
260
275
|
def _save_to_file(self, file_name:str, value:Any) -> None:
|
|
261
276
|
"""Save a value to a file. """
|
|
262
277
|
|
|
@@ -276,12 +291,14 @@ class FileDirDict(PersiDict):
|
|
|
276
291
|
|
|
277
292
|
self._save_to_file_impl(file_name, value)
|
|
278
293
|
|
|
294
|
+
|
|
279
295
|
def __contains__(self, key:PersiDictKey) -> bool:
|
|
280
296
|
"""True if the dictionary has the specified key, else False. """
|
|
281
297
|
key = SafeStrTuple(key)
|
|
282
298
|
filename = self._build_full_path(key)
|
|
283
299
|
return os.path.isfile(filename)
|
|
284
300
|
|
|
301
|
+
|
|
285
302
|
def __getitem__(self, key:PersiDictKey) -> Any:
|
|
286
303
|
""" Implementation for x[y] syntax. """
|
|
287
304
|
key = SafeStrTuple(key)
|
|
@@ -296,6 +313,7 @@ class FileDirDict(PersiDict):
|
|
|
296
313
|
+ f" but it is {type(result)} instead.")
|
|
297
314
|
return result
|
|
298
315
|
|
|
316
|
+
|
|
299
317
|
def __setitem__(self, key:PersiDictKey, value:Any):
|
|
300
318
|
"""Set self[key] to value."""
|
|
301
319
|
|
|
@@ -319,6 +337,7 @@ class FileDirDict(PersiDict):
|
|
|
319
337
|
raise KeyError("Can't modify an immutable item")
|
|
320
338
|
self._save_to_file(filename, value)
|
|
321
339
|
|
|
340
|
+
|
|
322
341
|
def __delitem__(self, key:PersiDictKey) -> None:
|
|
323
342
|
"""Delete self[key]."""
|
|
324
343
|
key = SafeStrTuple(key)
|
|
@@ -328,6 +347,7 @@ class FileDirDict(PersiDict):
|
|
|
328
347
|
raise KeyError(f"File {filename} does not exist")
|
|
329
348
|
os.remove(filename)
|
|
330
349
|
|
|
350
|
+
|
|
331
351
|
def _generic_iter(self, iter_type: str):
|
|
332
352
|
"""Underlying implementation for .items()/.keys()/.values() iterators"""
|
|
333
353
|
assert iter_type in {"keys", "values", "items"}
|
|
@@ -93,29 +93,41 @@ 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
|
|
103
108
|
, base_class_for_values=self.base_class_for_values
|
|
104
109
|
)
|
|
105
|
-
|
|
110
|
+
sorted_params = dict(sorted(params.items()))
|
|
111
|
+
return sorted_params
|
|
106
112
|
|
|
107
113
|
|
|
108
114
|
@property
|
|
109
115
|
@abstractmethod
|
|
110
116
|
def base_url(self):
|
|
111
|
-
"""Return dictionary's URL
|
|
117
|
+
"""Return dictionary's URL
|
|
118
|
+
|
|
119
|
+
This property is absent in the original dict API.
|
|
120
|
+
"""
|
|
112
121
|
raise NotImplementedError
|
|
113
122
|
|
|
114
123
|
|
|
115
124
|
@property
|
|
116
125
|
@abstractmethod
|
|
117
126
|
def base_dir(self):
|
|
118
|
-
"""Return dictionary's base directory in the local filesystem
|
|
127
|
+
"""Return dictionary's base directory in the local filesystem.
|
|
128
|
+
|
|
129
|
+
This property is absent in the original dict API.
|
|
130
|
+
"""
|
|
119
131
|
raise NotImplementedError
|
|
120
132
|
|
|
121
133
|
|
|
@@ -224,9 +236,11 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
224
236
|
except:
|
|
225
237
|
return False
|
|
226
238
|
|
|
239
|
+
|
|
227
240
|
def __getstate__(self):
|
|
228
241
|
raise TypeError("PersiDict is not picklable.")
|
|
229
242
|
|
|
243
|
+
|
|
230
244
|
def __setstate__(self, state):
|
|
231
245
|
raise TypeError("PersiDict is not picklable.")
|
|
232
246
|
|
|
@@ -275,6 +289,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
275
289
|
"""
|
|
276
290
|
raise NotImplementedError
|
|
277
291
|
|
|
292
|
+
|
|
278
293
|
def subdicts(self) -> dict[str, PersiDict]:
|
|
279
294
|
"""Get a dictionary of sub-dictionaries.
|
|
280
295
|
|
|
@@ -337,6 +352,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
337
352
|
result = all_keys[:max_n]
|
|
338
353
|
return result
|
|
339
354
|
|
|
355
|
+
|
|
340
356
|
def oldest_values(self, max_n=None):
|
|
341
357
|
"""Return max_n the oldest values in the dictionary.
|
|
342
358
|
|
|
@@ -346,6 +362,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
346
362
|
"""
|
|
347
363
|
return [self[k] for k in self.oldest_keys(max_n)]
|
|
348
364
|
|
|
365
|
+
|
|
349
366
|
def newest_values(self, max_n=None):
|
|
350
367
|
"""Return max_n the newest values in the dictionary.
|
|
351
368
|
|
|
@@ -111,23 +111,34 @@ 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
|
|
118
122
|
params["root_prefix"] = self.root_prefix
|
|
119
|
-
|
|
123
|
+
sorted_params = dict(sorted(params.items()))
|
|
124
|
+
return sorted_params
|
|
120
125
|
|
|
121
126
|
|
|
122
127
|
@property
|
|
123
128
|
def base_url(self):
|
|
124
|
-
"""Return dictionary's URl
|
|
129
|
+
"""Return dictionary's URl.
|
|
130
|
+
|
|
131
|
+
This property is absent in the original dict API.
|
|
132
|
+
"""
|
|
125
133
|
return f"s3://{self.bucket_name}/{self.root_prefix}"
|
|
126
134
|
|
|
127
135
|
|
|
128
136
|
@property
|
|
129
137
|
def base_dir(self) -> str:
|
|
130
|
-
"""Return dictionary's base directory in the local filesystem
|
|
138
|
+
"""Return dictionary's base directory in the local filesystem.
|
|
139
|
+
|
|
140
|
+
This property is absent in the original dict API.
|
|
141
|
+
"""
|
|
131
142
|
return self.local_cache.base_dir
|
|
132
143
|
|
|
133
144
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|