persidict 0.19.0__tar.gz → 0.21.0__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: persidict
3
- Version: 0.19.0
3
+ Version: 0.21.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 can not assign initial key-value pairs to a dictionary in its constructor.
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
 
@@ -122,12 +122,13 @@ that simultaneously work with the same instance of a dictionary.
122
122
  * Values must be pickleable Python objects.
123
123
  * You can constrain values to be an instance of a specific class.
124
124
  * Insertion order is not preserved.
125
- * You can not assign initial key-value pairs to a dictionary in its constructor.
125
+ * You cannot assign initial key-value pairs to a dictionary in its constructor.
126
126
  * `PersiDict` API has additional methods `delete_if_exists()`, `timestamp()`,
127
127
  `get_subdict()`, `subdicts()`, `random_keys()`, `newest_keys()`,
128
128
  `oldest_keys()`, `newest_values()`, `oldest_values()`,
129
129
  `get_params()`, `get_metaparams()`, and `get_default_metaparams()`,
130
130
  which are not available in native Python dicts.
131
+ * You can use NO_CHANGE constant to avoid actually setting/updating a value.
131
132
 
132
133
  ## Fine Tuning
133
134
 
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "persidict"
7
- version = "0.19.0"
7
+ version = "0.21.0"
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"
@@ -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 *
@@ -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 NoChangeFlag:
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 = NoChangeFlag()
17
+ NO_CHANGE = NoChangeFlag()
@@ -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:
@@ -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 "