persidict 0.30.0__tar.gz → 0.31.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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: persidict
3
- Version: 0.30.0
3
+ Version: 0.31.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.30.0"
7
+ version = "0.31.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"
@@ -29,4 +29,5 @@ from .file_dir_dict import FileDirDict
29
29
  from .s3_dict import S3Dict
30
30
  from .write_once_dict import WriteOnceDict
31
31
  from .jokers import Joker, KeepCurrentFlag, DeleteCurrentFlag
32
- from .jokers import KEEP_CURRENT, DELETE_CURRENT
32
+ from .jokers import KEEP_CURRENT, DELETE_CURRENT
33
+ from .overlapping_multi_dict import OverlappingMultiDict
@@ -19,6 +19,7 @@ import jsonpickle
19
19
  import jsonpickle.ext.numpy as jsonpickle_numpy
20
20
  import jsonpickle.ext.pandas as jsonpickle_pandas
21
21
  import parameterizable
22
+ from parameterizable import sort_dict_by_keys
22
23
 
23
24
  from .jokers import KEEP_CURRENT, DELETE_CURRENT, Joker
24
25
  from .safe_chars import replace_unsafe_chars
@@ -124,7 +125,7 @@ class FileDirDict(PersiDict):
124
125
  base_dir=self.base_dir
125
126
  , file_type=self.file_type)
126
127
  params.update(additional_params)
127
- sorted_params = dict(sorted(params.items()))
128
+ sorted_params = sort_dict_by_keys(params)
128
129
  return sorted_params
129
130
 
130
131
 
@@ -0,0 +1,57 @@
1
+ from .persi_dict import PersiDict
2
+
3
+ class OverlappingMultiDict:
4
+ """A class that holds several PersiDict objects with different fyle_type-s.
5
+
6
+ The class is designed to be used as a container for several PersiDict objects
7
+ that have different file_type-s. All inner PersiDict objects
8
+ have the same dir_name attribute. Each inner PersiDict object is accessible
9
+ as an attribute of the OverlappingMultiDict object.
10
+ The attribute name is the same as the file_type
11
+ of the inner PersiDict object.
12
+
13
+ OverlappingMultiDict allows to store several PersiDict objects
14
+ in a single object, which can be useful for managing multiple types of data
15
+ in a single file directory or in an s3 bucket.
16
+
17
+ """
18
+ def __init__(self
19
+ , dict_type:type
20
+ , shared_subdicts_params:dict
21
+ , **individual_subdicts_params):
22
+ assert issubclass(dict_type, PersiDict)
23
+ assert isinstance(shared_subdicts_params, dict)
24
+ self.dict_type = dict_type
25
+ self.shared_subdicts_params = shared_subdicts_params
26
+ self.individual_subdicts_params = individual_subdicts_params
27
+ self.subdicts_names = list(individual_subdicts_params.keys())
28
+ for subdict_name in individual_subdicts_params:
29
+ assert isinstance(individual_subdicts_params[subdict_name], dict)
30
+ self.__dict__[subdict_name] = dict_type(
31
+ **{**shared_subdicts_params
32
+ ,**individual_subdicts_params[subdict_name]
33
+ ,"file_type":subdict_name})
34
+
35
+ def __getstate__(self):
36
+ raise TypeError("OverlappingMultiDict cannot be pickled.")
37
+
38
+ def __setstate__(self, state):
39
+ raise TypeError("OverlappingMultiDict cannot be pickled.")
40
+
41
+ def __getitem__(self, key):
42
+ raise TypeError(
43
+ "OverlappingMultiDict does not support item access by key. "
44
+ "Individual items should be accessed through nested dicts, "
45
+ f"which are available via attributes {self.subdicts_names}")
46
+
47
+ def __setitem__(self, key, value):
48
+ raise TypeError(
49
+ "OverlappingMultiDict does not support item assignment by key. "
50
+ "Individual items should be accessed through nested dicts, "
51
+ f"which are available via attributes {self.subdicts_names}")
52
+
53
+ def __delitem__(self, key):
54
+ raise TypeError(
55
+ "OverlappingMultiDict does not support item deletion by key. "
56
+ "Individual items can be deletedthrough nested dicts, "
57
+ f"which are available via attributes {self.subdicts_names}")
@@ -22,7 +22,7 @@ from __future__ import annotations
22
22
 
23
23
  from abc import abstractmethod
24
24
  import random
25
- from parameterizable import ParameterizableClass
25
+ from parameterizable import ParameterizableClass, sort_dict_by_keys
26
26
  from typing import Any, Sequence, Optional
27
27
  from collections.abc import MutableMapping
28
28
 
@@ -107,7 +107,7 @@ class PersiDict(MutableMapping, ParameterizableClass):
107
107
  , digest_len=self.digest_len
108
108
  , base_class_for_values=self.base_class_for_values
109
109
  )
110
- sorted_params = dict(sorted(params.items()))
110
+ sorted_params = sort_dict_by_keys(params)
111
111
  return sorted_params
112
112
 
113
113
 
@@ -5,6 +5,7 @@ from typing import Any, Optional
5
5
 
6
6
  import boto3
7
7
  import parameterizable
8
+ from parameterizable.dict_sorter import sort_dict_by_keys
8
9
 
9
10
  from .safe_str_tuple import SafeStrTuple
10
11
  from .safe_str_tuple_signing import sign_safe_str_tuple, unsign_safe_str_tuple
@@ -119,7 +120,7 @@ class S3Dict(PersiDict):
119
120
  params["region"] = self.region
120
121
  params["bucket_name"] = self.bucket_name
121
122
  params["root_prefix"] = self.root_prefix
122
- sorted_params = dict(sorted(params.items()))
123
+ sorted_params = sort_dict_by_keys(params)
123
124
  return sorted_params
124
125
 
125
126
 
@@ -3,7 +3,8 @@ from __future__ import annotations
3
3
  import time
4
4
 
5
5
  from deepdiff import DeepDiff
6
- from parameterizable import register_parameterizable_class
6
+ from parameterizable import register_parameterizable_class, sort_dict_by_keys
7
+
7
8
  from .jokers import KEEP_CURRENT, KeepCurrentFlag
8
9
  from .persi_dict import PersiDict
9
10
  from .file_dir_dict import FileDirDict
@@ -103,7 +104,7 @@ class WriteOnceDict(PersiDict):
103
104
  params = dict(
104
105
  wrapped_dict = self._wrapped_dict,
105
106
  p_consistency_checks = self.p_consistency_checks)
106
- sorted_params = dict(sorted(params.items()))
107
+ sorted_params = sort_dict_by_keys(params)
107
108
  return sorted_params
108
109
 
109
110
  def __setitem__(self, key, value):
File without changes