persidict 0.19.0__py3-none-any.whl → 0.20.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/__init__.py +2 -1
- persidict/file_dir_dict.py +4 -0
- persidict/nochange_const.py +17 -0
- persidict/persi_dict.py +4 -0
- persidict/s3_dict.py +5 -1
- {persidict-0.19.0.dist-info → persidict-0.20.0.dist-info}/METADATA +3 -2
- persidict-0.20.0.dist-info/RECORD +12 -0
- persidict-0.19.0.dist-info/RECORD +0 -11
- {persidict-0.19.0.dist-info → persidict-0.20.0.dist-info}/WHEEL +0 -0
persidict/__init__.py
CHANGED
|
@@ -26,4 +26,5 @@ from .safe_chars import get_safe_chars, replace_unsafe_chars
|
|
|
26
26
|
from .safe_str_tuple import SafeStrTuple
|
|
27
27
|
from .persi_dict import PersiDict
|
|
28
28
|
from .file_dir_dict import FileDirDict
|
|
29
|
-
from .s3_dict import S3Dict
|
|
29
|
+
from .s3_dict import S3Dict
|
|
30
|
+
from .nochange_const import *
|
persidict/file_dir_dict.py
CHANGED
|
@@ -21,6 +21,7 @@ import jsonpickle.ext.numpy as jsonpickle_numpy
|
|
|
21
21
|
import jsonpickle.ext.pandas as jsonpickle_pandas
|
|
22
22
|
import parameterizable
|
|
23
23
|
|
|
24
|
+
from .nochange_const import NO_CHANGE
|
|
24
25
|
from .safe_chars import replace_unsafe_chars
|
|
25
26
|
from .safe_str_tuple import SafeStrTuple
|
|
26
27
|
from .safe_str_tuple_signing import sign_safe_str_tuple, unsign_safe_str_tuple
|
|
@@ -298,6 +299,9 @@ class FileDirDict(PersiDict):
|
|
|
298
299
|
def __setitem__(self, key:PersiDictKey, value:Any):
|
|
299
300
|
"""Set self[key] to value."""
|
|
300
301
|
|
|
302
|
+
if value is NO_CHANGE:
|
|
303
|
+
return
|
|
304
|
+
|
|
301
305
|
if isinstance(value, PersiDict):
|
|
302
306
|
raise TypeError(
|
|
303
307
|
f"You are not allowed to store a PersiDict "
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""A singleton constant to indicate no change in a value.
|
|
2
|
+
|
|
3
|
+
When updating a val ue in a persistent dictionary,
|
|
4
|
+
use NO_CHANGE as the new value to indicate that
|
|
5
|
+
the existing value should remain unchanged.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
class NoChange_Class:
|
|
9
|
+
_instance = None
|
|
10
|
+
|
|
11
|
+
def __new__(cls):
|
|
12
|
+
if cls._instance is None:
|
|
13
|
+
cls._instance = super().__new__(cls)
|
|
14
|
+
return cls._instance
|
|
15
|
+
|
|
16
|
+
NoChange = NoChange_Class()
|
|
17
|
+
NO_CHANGE = NoChange_Class()
|
persidict/persi_dict.py
CHANGED
|
@@ -26,6 +26,7 @@ from parameterizable import ParameterizableClass
|
|
|
26
26
|
from typing import Any, Sequence, Optional
|
|
27
27
|
from collections.abc import MutableMapping
|
|
28
28
|
|
|
29
|
+
from .nochange_const import NO_CHANGE
|
|
29
30
|
from .safe_str_tuple import SafeStrTuple
|
|
30
31
|
|
|
31
32
|
PersiDictKey = SafeStrTuple | Sequence[str] | str
|
|
@@ -148,6 +149,8 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
148
149
|
|
|
149
150
|
def __setitem__(self, key:PersiDictKey, value:Any):
|
|
150
151
|
"""Set self[key] to value."""
|
|
152
|
+
if value is NO_CHANGE:
|
|
153
|
+
return
|
|
151
154
|
if self.immutable_items:
|
|
152
155
|
if key in self:
|
|
153
156
|
raise KeyError("Can't modify an immutable key-value pair")
|
|
@@ -201,6 +204,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
|
|
|
201
204
|
"""
|
|
202
205
|
# TODO: check edge cases to ensure the same semantics as standard dicts
|
|
203
206
|
key = SafeStrTuple(key)
|
|
207
|
+
assert not default is NO_CHANGE
|
|
204
208
|
if key in self:
|
|
205
209
|
return self[key]
|
|
206
210
|
else:
|
persidict/s3_dict.py
CHANGED
|
@@ -10,6 +10,7 @@ import parameterizable
|
|
|
10
10
|
from .safe_str_tuple import SafeStrTuple
|
|
11
11
|
from .safe_str_tuple_signing import sign_safe_str_tuple, unsign_safe_str_tuple
|
|
12
12
|
from .persi_dict import PersiDict
|
|
13
|
+
from .nochange_const import NO_CHANGE
|
|
13
14
|
from .file_dir_dict import FileDirDict, PersiDictKey
|
|
14
15
|
|
|
15
16
|
S3DICT_DEFAULT_BASE_DIR = "__s3_dict__"
|
|
@@ -123,13 +124,13 @@ class S3Dict(PersiDict):
|
|
|
123
124
|
"""Return dictionary's URl"""
|
|
124
125
|
return f"s3://{self.bucket_name}/{self.root_prefix}"
|
|
125
126
|
|
|
127
|
+
|
|
126
128
|
@property
|
|
127
129
|
def base_dir(self) -> str:
|
|
128
130
|
"""Return dictionary's base directory in the local filesystem"""
|
|
129
131
|
return self.local_cache.base_dir
|
|
130
132
|
|
|
131
133
|
|
|
132
|
-
|
|
133
134
|
def _build_full_objectname(self, key:PersiDictKey) -> str:
|
|
134
135
|
""" Convert PersiDictKey into an S3 objectname. """
|
|
135
136
|
key = SafeStrTuple(key)
|
|
@@ -179,6 +180,9 @@ class S3Dict(PersiDict):
|
|
|
179
180
|
def __setitem__(self, key:PersiDictKey, value:Any):
|
|
180
181
|
"""Set self[key] to value. """
|
|
181
182
|
|
|
183
|
+
if value is NO_CHANGE:
|
|
184
|
+
return
|
|
185
|
+
|
|
182
186
|
if isinstance(value, PersiDict):
|
|
183
187
|
raise TypeError(
|
|
184
188
|
f"You are not allowed to store a PersiDict "
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: persidict
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.20.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
|
|
@@ -155,12 +155,13 @@ that simultaneously work with the same instance of a dictionary.
|
|
|
155
155
|
* Values must be pickleable Python objects.
|
|
156
156
|
* You can constrain values to be an instance of a specific class.
|
|
157
157
|
* Insertion order is not preserved.
|
|
158
|
-
* You
|
|
158
|
+
* You cannot assign initial key-value pairs to a dictionary in its constructor.
|
|
159
159
|
* `PersiDict` API has additional methods `delete_if_exists()`, `timestamp()`,
|
|
160
160
|
`get_subdict()`, `subdicts()`, `random_keys()`, `newest_keys()`,
|
|
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 to avoid actually setting/updating a value.
|
|
164
165
|
|
|
165
166
|
## Fine Tuning
|
|
166
167
|
|
|
@@ -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=438558ea1f06a8e280609a4aaa94a6fea05d82ce2ef79bd401af94b014da82a6,14132
|
|
4
|
+
persidict/nochange_const.py,sha256=d569d9283a684150e380b08ebdeb232783dd0e51938bfbbadf27327952027f3e,443
|
|
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.20.0.dist-info/WHEEL,sha256=c133ef911c90b05f7e14d8679ba99146f9154fcd271b7398cf8f672283b94e05,79
|
|
11
|
+
persidict-0.20.0.dist-info/METADATA,sha256=f8d494dd74e77144e57c8db653c0b7da471c3d71e313804caee9ad6ae78f3855,9172
|
|
12
|
+
persidict-0.20.0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
persidict/.DS_Store,sha256=d65165279105ca6773180500688df4bdc69a2c7b771752f0a46ef120b7fd8ec3,6148
|
|
2
|
-
persidict/__init__.py,sha256=f589b6292bef0ee7c6f6ef087dacbecc5943a64deed8839b02f8342db3032b25,1155
|
|
3
|
-
persidict/file_dir_dict.py,sha256=441c311572b61be643f6536dfd0c157c03faebe4a01c26fa22d77386cbdd5a5d,14043
|
|
4
|
-
persidict/persi_dict.py,sha256=040fb1ed1358fa36a4d445d9fd3b899087a1030c7e76fb39da7e15c766aec41a,11600
|
|
5
|
-
persidict/s3_dict.py,sha256=fb84d32ff0aa0d873d7d0742a374fab12d9aae272dbcde82ddee7f7af7487eba,11745
|
|
6
|
-
persidict/safe_chars.py,sha256=59a20e96205d2e5675d827a911ad42ddbd553f1bd7e2cda1be765a9c2c4ce814,565
|
|
7
|
-
persidict/safe_str_tuple.py,sha256=71393904bdebfb213ad8429fed59e04da52964076c01324f2238821aa4339325,3717
|
|
8
|
-
persidict/safe_str_tuple_signing.py,sha256=e6e0a3015651a8ea2ef8aa43670f84c5ba1cdfedefb9ac8932aaebb7c699d1c9,3742
|
|
9
|
-
persidict-0.19.0.dist-info/WHEEL,sha256=c133ef911c90b05f7e14d8679ba99146f9154fcd271b7398cf8f672283b94e05,79
|
|
10
|
-
persidict-0.19.0.dist-info/METADATA,sha256=f28075650e95b00558605e23225933e6e1a4fb0ba8e2fb5705c4acc86373edab,9096
|
|
11
|
-
persidict-0.19.0.dist-info/RECORD,,
|
|
File without changes
|