persidict 0.36.3__tar.gz → 0.36.5__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.36.3
3
+ Version: 0.36.5
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
@@ -38,15 +38,14 @@ Simple persistent dictionaries for distributed applications in Python.
38
38
 
39
39
  ## 1. What Is It?
40
40
 
41
- `persidict` offers a simple persistent key-value store for Python.
42
- It saves the content of the dictionary in a folder on a disk
43
- or in an S3 bucket on AWS. Each value is stored as a separate file / S3 object.
44
- Only text strings or sequences of strings are allowed as keys.
41
+ `persidict` is a lightweight persistent key-value store for Python.
42
+ It saves a dictionary to either a local directory or an AWS S3 bucket,
43
+ storing each value as its own file or S3 object. Keys are limited to
44
+ text strings or sequences of strings.
45
45
 
46
- Unlike other persistent dictionaries (e.g. Python's native `shelve`),
47
- `persidict` is designed for use in highly **distributed environments**,
48
- where multiple instances of a program run concurrently across many machines,
49
- accessing the same dictionary via a shared storage.
46
+ In contrast to traditional persistent dictionaries (e.g., Pythons `shelve)`,
47
+ `persidict` is designed for distributed environments where multiple processes
48
+ on different machines concurrently work with the same store.
50
49
 
51
50
  ## 2. Features
52
51
  * **Persistent Storage**: Save dictionaries to the local filesystem
@@ -120,21 +119,49 @@ print(f"API Key: {cloud_config['api_key']}")
120
119
  # >>> API Key: ABC-123-XYZ
121
120
  ```
122
121
 
123
- ## 4. Glossary
122
+ ## 4. Comparison With Python Built-in Dictionaries
124
123
 
125
- ### 4.1 Core Concepts
124
+ ### 4.1 Similarities
125
+
126
+ `PersiDict` subclasses can be used like regular Python dictionaries, supporting:
127
+
128
+ * Get, set, and delete operations with square brackets (`[]`).
129
+ * Iteration over keys, values, and items.
130
+ * Membership testing with `in`.
131
+ * Length checking with `len()`.
132
+ * Standard methods like `keys()`, `values()`, `items()`, `get()`, `clear()`
133
+ , `setdefault()`, and `update()`.
134
+
135
+ ### 4.2 Differences
136
+
137
+ * **Persistence**: Data is saved between program executions.
138
+ * **Keys**: Keys must be strings or sequences of URL/filename-safe strings.
139
+ * **Values**: Values must be pickleable.
140
+ You can also constrain values to a specific class.
141
+ * **Order**: Insertion order is not preserved.
142
+ * **Additional Methods**: `PersiDict` provides extra methods not in the standard
143
+ dict API, such as `timestamp()`, `random_key()`, `newest_keys()`, `subdicts()`
144
+ , `delete_if_exists()`, `get_params()` and more.
145
+ * **Special Values**: Use `KEEP_CURRENT` to avoid updating a value
146
+ and `DELETE_CURRENT` to delete a value during an assignment.
147
+
148
+ ## 5. Glossary
149
+
150
+ ### 5.1 Core Concepts
126
151
 
127
152
  * **`PersiDict`**: The abstract base class that defines the common interface
128
153
  for all persistent dictionaries in the package. It's the foundation
129
154
  upon which everything else is built.
130
155
  * **`PersiDictKey`**: A type hint that specifies what can be used
131
- as a key in any `PersiDict`. It can be a `SafeStrTuple`,
132
- a single string, or a sequence of strings.
156
+ as a key in any `PersiDict`. It can be a `SafeStrTuple`, a single string,
157
+ * or a sequence of strings. When a `PesiDict` method requires a key as an input,
158
+ it will accept any of these types and convert them to a `SafeStrTuple` internally.
133
159
  * **`SafeStrTuple`**: The core data structure for keys. It's an immutable,
134
160
  flat tuple of non-empty, URL/filename-safe strings, ensuring that
135
- keys are consistent and safe for various storage backends.
161
+ keys are consistent and safe for various storage backends.
162
+ When a `PersiDict` method returns a key, it will always be in this format.
136
163
 
137
- ### 4.2 Main Implementations
164
+ ### 5.2 Main Implementations
138
165
 
139
166
  * **`FileDirDict`**: A primary, concrete implementation of `PersiDict`
140
167
  that stores each key-value pair as a separate file in a local directory.
@@ -142,7 +169,7 @@ that stores each key-value pair as a separate file in a local directory.
142
169
  which stores each key-value pair as an object in an AWS S3 bucket,
143
170
  suitable for distributed environments.
144
171
 
145
- ### 4.3 Key Parameters
172
+ ### 5.3 Key Parameters
146
173
 
147
174
  * **`file_type`**: A key parameter for `FileDirDict` and `S3Dict` that
148
175
  determines the serialization format for values.
@@ -161,7 +188,7 @@ stores its files. For `S3Dict`, this directory is used to cache files locally.
161
188
  an `S3Dict` stores its objects.
162
189
  * **`region`**: An optional string specifying the AWS region for the S3 bucket.
163
190
 
164
- ### 4.4 Advanced Classes
191
+ ### 5.4 Advanced Classes
165
192
 
166
193
  * **`WriteOnceDict`**: A wrapper that enforces write-once behavior
167
194
  on any `PersiDict`, ignoring subsequent writes to the same key.
@@ -171,7 +198,7 @@ writes to the same key always match the original value.
171
198
  multiple `PersiDict` instances sharing the same storage
172
199
  but with different `file_type`s.
173
200
 
174
- ### 4.5 Special "Joker" Values
201
+ ### 5.5 Special "Joker" Values
175
202
 
176
203
  * **`Joker`**: The base class for special command-like values that
177
204
  can be assigned to a key to trigger an action instead of storing a value.
@@ -180,33 +207,24 @@ ensures the existing value is not changed.
180
207
  * **`DELETE_CURRENT`**: A "joker" value that deletes the key-value pair
181
208
  from the dictionary when assigned to a key.
182
209
 
183
- ## 5. Comparison With Python Built-in Dictionaries
184
-
185
- ### 5.1 Similarities
186
-
187
- `PersiDict` subclasses can be used like regular Python dictionaries, supporting:
188
-
189
- * Get, set, and delete operations with square brackets (`[]`).
190
- * Iteration over keys, values, and items.
191
- * Membership testing with `in`.
192
- * Length checking with `len()`.
193
- * Standard methods like `keys()`, `values()`, `items()`, `get()`, `clear()`
194
- , `setdefault()`, and `update()`.
210
+ ## 6. API Highlights
195
211
 
196
- ### 5.2 Differences
212
+ `PersiDict` subclasses support the standard Python dictionary API, plus these additional methods for advanced functionality:
197
213
 
198
- * **Persistence**: Data is saved between program executions.
199
- * **Keys**: Keys must be strings or sequences of URL/filename-safe strings.
200
- * **Values**: Values must be pickleable.
201
- You can also constrain values to a specific class.
202
- * **Order**: Insertion order is not preserved.
203
- * **Additional Methods**: `PersiDict` provides extra methods not in the standard
204
- dict API, such as `timestamp()`, `random_key()`, `newest_keys()`, `subdicts()`
205
- , `delete_if_exists()`, `get_params()` and more.
206
- * **Special Values**: Use `KEEP_CURRENT` to avoid updating a value
207
- and `DELETE_CURRENT` to delete a value during an assignment.
214
+ | Method | Return Type | Description |
215
+ | :--- | :--- | :--- |
216
+ | `timestamp(key)` | `float` | Returns the POSIX timestamp (seconds since epoch) of a key's last modification. |
217
+ | `random_key()` | `SafeStrTuple \| None` | Selects and returns a single random key, useful for sampling from the dataset. |
218
+ | `oldest_keys(max_n=None)` | `list[SafeStrTuple]` | Returns a list of keys sorted by their modification time, from oldest to newest. |
219
+ | `newest_keys(max_n=None)` | `list[SafeStrTuple]` | Returns a list of keys sorted by their modification time, from newest to oldest. |
220
+ | `oldest_values(max_n=None)` | `list[Any]` | Returns a list of values corresponding to the oldest keys. |
221
+ | `newest_values(max_n=None)` | `list[Any]` | Returns a list of values corresponding to the newest keys. |
222
+ | `get_subdict(prefix_key)` | `PersiDict` | Returns a new `PersiDict` instance that provides a view into a subset of keys sharing a common prefix. |
223
+ | `subdicts()` | `dict[str, PersiDict]` | Returns a dictionary mapping all first-level key prefixes to their corresponding sub-dictionary views. |
224
+ | `delete_if_exists(key)` | `bool` | Deletes a key-value pair if it exists and returns `True`; otherwise, returns `False`. |
225
+ | `get_params()` | `dict` | Returns a dictionary of the instance's configuration parameters, supporting the `parameterizable` API. |
208
226
 
209
- ## 6. Installation
227
+ ## 7. Installation
210
228
 
211
229
  The source code is hosted on GitHub at:
212
230
  [https://github.com/pythagoras-dev/persidict](https://github.com/pythagoras-dev/persidict)
@@ -232,7 +250,7 @@ For development, including test dependencies:
232
250
  pip install persidict[dev]
233
251
  ```
234
252
 
235
- ## 7. Dependencies
253
+ ## 8. Dependencies
236
254
 
237
255
  `persidict` has the following core dependencies:
238
256
 
@@ -251,13 +269,13 @@ For development and testing, the following packages are used:
251
269
  * [pytest](https://pytest.org)
252
270
  * [moto](http://getmoto.org)
253
271
 
254
- ## 8. Contributing
272
+ ## 9. Contributing
255
273
  Contributions are welcome! Please see the contributing [guide](https://github.com/pythagoras-dev/persidict?tab=contributing-ov-file) for more details
256
274
  on how to get started, run tests, and submit pull requests.
257
275
 
258
- ## 9. License
276
+ ## 10. License
259
277
  `persidict` is licensed under the MIT License. See the [LICENSE](https://github.com/pythagoras-dev/persidict?tab=MIT-1-ov-file) file for more details.
260
278
 
261
- ## 10. Key Contacts
279
+ ## 11. Key Contacts
262
280
 
263
281
  * [Vlad (Volodymyr) Pavlov](https://www.linkedin.com/in/vlpavlov/)
@@ -4,15 +4,14 @@ Simple persistent dictionaries for distributed applications in Python.
4
4
 
5
5
  ## 1. What Is It?
6
6
 
7
- `persidict` offers a simple persistent key-value store for Python.
8
- It saves the content of the dictionary in a folder on a disk
9
- or in an S3 bucket on AWS. Each value is stored as a separate file / S3 object.
10
- Only text strings or sequences of strings are allowed as keys.
7
+ `persidict` is a lightweight persistent key-value store for Python.
8
+ It saves a dictionary to either a local directory or an AWS S3 bucket,
9
+ storing each value as its own file or S3 object. Keys are limited to
10
+ text strings or sequences of strings.
11
11
 
12
- Unlike other persistent dictionaries (e.g. Python's native `shelve`),
13
- `persidict` is designed for use in highly **distributed environments**,
14
- where multiple instances of a program run concurrently across many machines,
15
- accessing the same dictionary via a shared storage.
12
+ In contrast to traditional persistent dictionaries (e.g., Pythons `shelve)`,
13
+ `persidict` is designed for distributed environments where multiple processes
14
+ on different machines concurrently work with the same store.
16
15
 
17
16
  ## 2. Features
18
17
  * **Persistent Storage**: Save dictionaries to the local filesystem
@@ -86,21 +85,49 @@ print(f"API Key: {cloud_config['api_key']}")
86
85
  # >>> API Key: ABC-123-XYZ
87
86
  ```
88
87
 
89
- ## 4. Glossary
88
+ ## 4. Comparison With Python Built-in Dictionaries
90
89
 
91
- ### 4.1 Core Concepts
90
+ ### 4.1 Similarities
91
+
92
+ `PersiDict` subclasses can be used like regular Python dictionaries, supporting:
93
+
94
+ * Get, set, and delete operations with square brackets (`[]`).
95
+ * Iteration over keys, values, and items.
96
+ * Membership testing with `in`.
97
+ * Length checking with `len()`.
98
+ * Standard methods like `keys()`, `values()`, `items()`, `get()`, `clear()`
99
+ , `setdefault()`, and `update()`.
100
+
101
+ ### 4.2 Differences
102
+
103
+ * **Persistence**: Data is saved between program executions.
104
+ * **Keys**: Keys must be strings or sequences of URL/filename-safe strings.
105
+ * **Values**: Values must be pickleable.
106
+ You can also constrain values to a specific class.
107
+ * **Order**: Insertion order is not preserved.
108
+ * **Additional Methods**: `PersiDict` provides extra methods not in the standard
109
+ dict API, such as `timestamp()`, `random_key()`, `newest_keys()`, `subdicts()`
110
+ , `delete_if_exists()`, `get_params()` and more.
111
+ * **Special Values**: Use `KEEP_CURRENT` to avoid updating a value
112
+ and `DELETE_CURRENT` to delete a value during an assignment.
113
+
114
+ ## 5. Glossary
115
+
116
+ ### 5.1 Core Concepts
92
117
 
93
118
  * **`PersiDict`**: The abstract base class that defines the common interface
94
119
  for all persistent dictionaries in the package. It's the foundation
95
120
  upon which everything else is built.
96
121
  * **`PersiDictKey`**: A type hint that specifies what can be used
97
- as a key in any `PersiDict`. It can be a `SafeStrTuple`,
98
- a single string, or a sequence of strings.
122
+ as a key in any `PersiDict`. It can be a `SafeStrTuple`, a single string,
123
+ * or a sequence of strings. When a `PesiDict` method requires a key as an input,
124
+ it will accept any of these types and convert them to a `SafeStrTuple` internally.
99
125
  * **`SafeStrTuple`**: The core data structure for keys. It's an immutable,
100
126
  flat tuple of non-empty, URL/filename-safe strings, ensuring that
101
- keys are consistent and safe for various storage backends.
127
+ keys are consistent and safe for various storage backends.
128
+ When a `PersiDict` method returns a key, it will always be in this format.
102
129
 
103
- ### 4.2 Main Implementations
130
+ ### 5.2 Main Implementations
104
131
 
105
132
  * **`FileDirDict`**: A primary, concrete implementation of `PersiDict`
106
133
  that stores each key-value pair as a separate file in a local directory.
@@ -108,7 +135,7 @@ that stores each key-value pair as a separate file in a local directory.
108
135
  which stores each key-value pair as an object in an AWS S3 bucket,
109
136
  suitable for distributed environments.
110
137
 
111
- ### 4.3 Key Parameters
138
+ ### 5.3 Key Parameters
112
139
 
113
140
  * **`file_type`**: A key parameter for `FileDirDict` and `S3Dict` that
114
141
  determines the serialization format for values.
@@ -127,7 +154,7 @@ stores its files. For `S3Dict`, this directory is used to cache files locally.
127
154
  an `S3Dict` stores its objects.
128
155
  * **`region`**: An optional string specifying the AWS region for the S3 bucket.
129
156
 
130
- ### 4.4 Advanced Classes
157
+ ### 5.4 Advanced Classes
131
158
 
132
159
  * **`WriteOnceDict`**: A wrapper that enforces write-once behavior
133
160
  on any `PersiDict`, ignoring subsequent writes to the same key.
@@ -137,7 +164,7 @@ writes to the same key always match the original value.
137
164
  multiple `PersiDict` instances sharing the same storage
138
165
  but with different `file_type`s.
139
166
 
140
- ### 4.5 Special "Joker" Values
167
+ ### 5.5 Special "Joker" Values
141
168
 
142
169
  * **`Joker`**: The base class for special command-like values that
143
170
  can be assigned to a key to trigger an action instead of storing a value.
@@ -146,33 +173,24 @@ ensures the existing value is not changed.
146
173
  * **`DELETE_CURRENT`**: A "joker" value that deletes the key-value pair
147
174
  from the dictionary when assigned to a key.
148
175
 
149
- ## 5. Comparison With Python Built-in Dictionaries
150
-
151
- ### 5.1 Similarities
152
-
153
- `PersiDict` subclasses can be used like regular Python dictionaries, supporting:
154
-
155
- * Get, set, and delete operations with square brackets (`[]`).
156
- * Iteration over keys, values, and items.
157
- * Membership testing with `in`.
158
- * Length checking with `len()`.
159
- * Standard methods like `keys()`, `values()`, `items()`, `get()`, `clear()`
160
- , `setdefault()`, and `update()`.
176
+ ## 6. API Highlights
161
177
 
162
- ### 5.2 Differences
178
+ `PersiDict` subclasses support the standard Python dictionary API, plus these additional methods for advanced functionality:
163
179
 
164
- * **Persistence**: Data is saved between program executions.
165
- * **Keys**: Keys must be strings or sequences of URL/filename-safe strings.
166
- * **Values**: Values must be pickleable.
167
- You can also constrain values to a specific class.
168
- * **Order**: Insertion order is not preserved.
169
- * **Additional Methods**: `PersiDict` provides extra methods not in the standard
170
- dict API, such as `timestamp()`, `random_key()`, `newest_keys()`, `subdicts()`
171
- , `delete_if_exists()`, `get_params()` and more.
172
- * **Special Values**: Use `KEEP_CURRENT` to avoid updating a value
173
- and `DELETE_CURRENT` to delete a value during an assignment.
180
+ | Method | Return Type | Description |
181
+ | :--- | :--- | :--- |
182
+ | `timestamp(key)` | `float` | Returns the POSIX timestamp (seconds since epoch) of a key's last modification. |
183
+ | `random_key()` | `SafeStrTuple \| None` | Selects and returns a single random key, useful for sampling from the dataset. |
184
+ | `oldest_keys(max_n=None)` | `list[SafeStrTuple]` | Returns a list of keys sorted by their modification time, from oldest to newest. |
185
+ | `newest_keys(max_n=None)` | `list[SafeStrTuple]` | Returns a list of keys sorted by their modification time, from newest to oldest. |
186
+ | `oldest_values(max_n=None)` | `list[Any]` | Returns a list of values corresponding to the oldest keys. |
187
+ | `newest_values(max_n=None)` | `list[Any]` | Returns a list of values corresponding to the newest keys. |
188
+ | `get_subdict(prefix_key)` | `PersiDict` | Returns a new `PersiDict` instance that provides a view into a subset of keys sharing a common prefix. |
189
+ | `subdicts()` | `dict[str, PersiDict]` | Returns a dictionary mapping all first-level key prefixes to their corresponding sub-dictionary views. |
190
+ | `delete_if_exists(key)` | `bool` | Deletes a key-value pair if it exists and returns `True`; otherwise, returns `False`. |
191
+ | `get_params()` | `dict` | Returns a dictionary of the instance's configuration parameters, supporting the `parameterizable` API. |
174
192
 
175
- ## 6. Installation
193
+ ## 7. Installation
176
194
 
177
195
  The source code is hosted on GitHub at:
178
196
  [https://github.com/pythagoras-dev/persidict](https://github.com/pythagoras-dev/persidict)
@@ -198,7 +216,7 @@ For development, including test dependencies:
198
216
  pip install persidict[dev]
199
217
  ```
200
218
 
201
- ## 7. Dependencies
219
+ ## 8. Dependencies
202
220
 
203
221
  `persidict` has the following core dependencies:
204
222
 
@@ -217,13 +235,13 @@ For development and testing, the following packages are used:
217
235
  * [pytest](https://pytest.org)
218
236
  * [moto](http://getmoto.org)
219
237
 
220
- ## 8. Contributing
238
+ ## 9. Contributing
221
239
  Contributions are welcome! Please see the contributing [guide](https://github.com/pythagoras-dev/persidict?tab=contributing-ov-file) for more details
222
240
  on how to get started, run tests, and submit pull requests.
223
241
 
224
- ## 9. License
242
+ ## 10. License
225
243
  `persidict` is licensed under the MIT License. See the [LICENSE](https://github.com/pythagoras-dev/persidict?tab=MIT-1-ov-file) file for more details.
226
244
 
227
- ## 10. Key Contacts
245
+ ## 11. Key Contacts
228
246
 
229
247
  * [Vlad (Volodymyr) Pavlov](https://www.linkedin.com/in/vlpavlov/)
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "persidict"
7
- version = "0.36.3"
7
+ version = "0.36.5"
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"