persidict 0.2.0__tar.gz → 0.2.2__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.1
2
2
  Name: persidict
3
- Version: 0.2.0
3
+ Version: 0.2.2
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
  Home-page: https://github.com/vladlpavlov/persidict
6
6
  Author: Vlad (Volodymyr) Pavlov
@@ -143,7 +143,7 @@ that simultaneously work with the same instance of a dictionary.
143
143
  * Values must be pickleable Python objects.
144
144
  * Insertion order is not preserved.
145
145
  * You can not assign initial key-value pairs to a dictionary in its constructor.
146
- * Methods `quiet_delete()`, `mtimestamp()`, `get_subdict()` and `subdicts()`
146
+ * Methods `delete_if_exists()`, `mtimestamp()`, `get_subdict()` and `subdicts()`
147
147
  are available
148
148
 
149
149
  ## Fine Tuning
@@ -122,7 +122,7 @@ that simultaneously work with the same instance of a dictionary.
122
122
  * Values must be pickleable Python objects.
123
123
  * Insertion order is not preserved.
124
124
  * You can not assign initial key-value pairs to a dictionary in its constructor.
125
- * Methods `quiet_delete()`, `mtimestamp()`, `get_subdict()` and `subdicts()`
125
+ * Methods `delete_if_exists()`, `mtimestamp()`, `get_subdict()` and `subdicts()`
126
126
  are available
127
127
 
128
128
  ## Fine Tuning
@@ -17,6 +17,9 @@ S3_Dict (inherited from PersiDict): a dictionary that
17
17
  stores key-value pairs as S3 objects on AWS.
18
18
  A key is used to compose an objectname, while a value is stored
19
19
  as a pickle or a json S3 object.
20
+
21
+ The package also offers a helper function get_safe_chars(),
22
+ which returns a set of URL/filename-safe characters permitted in keys.
20
23
  """
21
24
 
22
25
  from .safe_str_tuple import SafeStrTuple, get_safe_chars
@@ -6,10 +6,14 @@ Python's built-in Dict, with a few variations
6
6
  (e.g. insertion order is not preserved) and additional methods.
7
7
 
8
8
  PersiDict persistently stores key-value pairs.
9
+
9
10
  A key is a sequence of strings in a form of SafeStrTuple.
11
+ Regular strings and their sequences can also be passed to PersiDict as keys,
12
+ in this case they will be automatically converted to SafeStrTuple.
13
+
10
14
  A value can be any Python object.
11
15
 
12
- 'Persstently' means that key-value pairs are saved in a durable storage,
16
+ 'Persistently' means that key-value pairs are saved in a durable storage,
13
17
  such as a local hard-drive or AWS S3 cloud, and can be retrieved
14
18
  even after the Python process that created the dictionary has terminated.
15
19
  """
@@ -22,11 +26,14 @@ from collections.abc import MutableMapping
22
26
 
23
27
  from .safe_str_tuple import SafeStrTuple
24
28
 
25
- PersiDictKey = Union[SafeStrTuple, str, Sequence[str]]
29
+ PersiDictKey = Union[SafeStrTuple, Sequence[str], str]
26
30
  """ A value which can be used as a key for PersiDict.
27
31
 
28
- PersiDictKey must be a string or a sequence of strings.
29
- The characters within strings must be to URL/filename-safe.
32
+ PersiDict-s accept keys on a form of SafeStrTuple,
33
+ or a string, or a sequence of strings.
34
+ The characters within strings must be URL/filename-safe.
35
+ If a string (or a sequence of strings) is passed to a PersiDict as a key,
36
+ it will be automatically converted into SafeStrTuple.
30
37
  """
31
38
 
32
39
  class PersiDict(MutableMapping):
@@ -195,11 +202,12 @@ class PersiDict(MutableMapping):
195
202
  del self[k]
196
203
 
197
204
 
198
- def quiet_delete(self, key:PersiDictKey):
205
+ def delete_if_exists(self, key:PersiDictKey) -> bool:
199
206
  """ Delete an item without raising an exception if it doesn't exist.
200
207
 
201
- This method is absent in the original dict API, it is added here
202
- to minimize network calls for (remote) persistent dictionaries.
208
+ Returns True if the item existed and was deleted, False otherwise.
209
+
210
+ This method is absent in the original dict API.
203
211
  """
204
212
 
205
213
  if self.immutable_items: # TODO: change to exceptions
@@ -207,21 +215,22 @@ class PersiDict(MutableMapping):
207
215
 
208
216
  key = SafeStrTuple(key)
209
217
 
210
- try:
211
- self.__delitem__(key)
212
- except:
213
- pass
218
+ if key in self:
219
+ del self[key]
220
+ return True
221
+ else:
222
+ return False
214
223
 
215
224
 
216
225
  def get_subdict(self, prefix_key:PersiDictKey) -> PersiDict:
217
- """Get a subdictionary containing items with the same prefix_key.
226
+ """Get a sub-dictionary containing items with the same prefix_key.
218
227
 
219
228
  This method is absent in the original dict API.
220
229
  """
221
230
  raise NotImplementedError
222
231
 
223
232
  def subdicts(self) -> Dict[str, PersiDict]:
224
- """Get a dictionary of subdictionaries.
233
+ """Get a dictionary of sub-dictionaries.
225
234
 
226
235
  This method is absent in the original dict API.
227
236
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: persidict
3
- Version: 0.2.0
3
+ Version: 0.2.2
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
  Home-page: https://github.com/vladlpavlov/persidict
6
6
  Author: Vlad (Volodymyr) Pavlov
@@ -143,7 +143,7 @@ that simultaneously work with the same instance of a dictionary.
143
143
  * Values must be pickleable Python objects.
144
144
  * Insertion order is not preserved.
145
145
  * You can not assign initial key-value pairs to a dictionary in its constructor.
146
- * Methods `quiet_delete()`, `mtimestamp()`, `get_subdict()` and `subdicts()`
146
+ * Methods `delete_if_exists()`, `mtimestamp()`, `get_subdict()` and `subdicts()`
147
147
  are available
148
148
 
149
149
  ## Fine Tuning
@@ -5,7 +5,7 @@ with open("README.md", "r") as f:
5
5
 
6
6
  setuptools.setup(
7
7
  name="persidict"
8
- ,version="0.2.0"
8
+ ,version="0.2.2"
9
9
  ,author="Vlad (Volodymyr) Pavlov"
10
10
  ,author_email="vlpavlov@ieee.org"
11
11
  ,description= "Simple persistent key-value store for Python. "
File without changes
File without changes