scruby 0.9.0__py3-none-any.whl → 0.9.2__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 scruby might be problematic. Click here for more details.

scruby/__init__.py CHANGED
@@ -18,4 +18,12 @@ from __future__ import annotations
18
18
 
19
19
  __all__ = ("Scruby",)
20
20
 
21
+ import logging
22
+
21
23
  from scruby.db import Scruby
24
+
25
+ logging.basicConfig(
26
+ level=logging.INFO,
27
+ datefmt="%Y-%m-%d %H:%M:%S",
28
+ format="[%(asctime)s.%(msecs)03d] %(module)10s:%(lineno)-3d %(levelname)-7s - %(message)s",
29
+ )
scruby/db.py CHANGED
@@ -6,6 +6,7 @@ __all__ = ("Scruby",)
6
6
 
7
7
  import concurrent.futures
8
8
  import contextlib
9
+ import logging
9
10
  import zlib
10
11
  from collections.abc import Callable
11
12
  from pathlib import Path as SyncPath
@@ -17,6 +18,8 @@ from anyio import Path, to_thread
17
18
 
18
19
  from scruby import constants
19
20
 
21
+ logger = logging.getLogger(__name__)
22
+
20
23
  T = TypeVar("T")
21
24
 
22
25
 
@@ -45,6 +48,8 @@ class Scruby[T]:
45
48
  case 6:
46
49
  self.__max_num_keys = 256
47
50
  case _ as unreachable:
51
+ msg: str = f"{unreachable} - Unacceptable value for LENGTH_REDUCTION_HASH."
52
+ logger.critical(msg)
48
53
  assert_never(Never(unreachable))
49
54
 
50
55
  async def get_leaf_path(self, key: str) -> Path:
@@ -54,8 +59,10 @@ class Scruby[T]:
54
59
  key: Key name.
55
60
  """
56
61
  if not isinstance(key, str):
62
+ logger.error("The key is not a type of `str`.")
57
63
  raise KeyError("The key is not a type of `str`.")
58
64
  if len(key) == 0:
65
+ logger.error("The key should not be empty.")
59
66
  raise KeyError("The key should not be empty.")
60
67
  # Key to crc32 sum.
61
68
  key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[self.__length_reduction_hash :]
@@ -115,6 +122,8 @@ class Scruby[T]:
115
122
  data: dict = orjson.loads(data_json) or {}
116
123
  obj: T = self.__class_model.model_validate_json(data[key])
117
124
  return obj
125
+ msg: str = "`get_key` - The unacceptable key value."
126
+ logger.error(msg)
118
127
  raise KeyError()
119
128
 
120
129
  async def has_key(self, key: str) -> bool:
@@ -151,6 +160,8 @@ class Scruby[T]:
151
160
  del data[key]
152
161
  await leaf_path.write_bytes(orjson.dumps(data))
153
162
  return
163
+ msg: str = "`delete_key` - The unacceptable key value."
164
+ logger.error(msg)
154
165
  raise KeyError()
155
166
 
156
167
  @staticmethod
@@ -200,7 +211,7 @@ class Scruby[T]:
200
211
  max_workers: int | None = None,
201
212
  timeout: float | None = None,
202
213
  ) -> T | None:
203
- """Find a single document.
214
+ """Find a single document matching the filter.
204
215
 
205
216
  The search is based on the effect of a quantum loop.
206
217
  The search effectiveness depends on the number of processor threads.
@@ -241,7 +252,7 @@ class Scruby[T]:
241
252
  max_workers: int | None = None,
242
253
  timeout: float | None = None,
243
254
  ) -> list[T] | None:
244
- """Find documents.
255
+ """Find one or more documents matching the filter.
245
256
 
246
257
  The search is based on the effect of a quantum loop.
247
258
  The search effectiveness depends on the number of processor threads.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 0.9.0
3
+ Version: 0.9.2
4
4
  Summary: A fast key-value storage library.
5
5
  Project-URL: Homepage, https://github.com/kebasyaty/scruby
6
6
  Project-URL: Repository, https://github.com/kebasyaty/scruby
@@ -103,6 +103,8 @@ uv add scruby
103
103
 
104
104
  ## Usage
105
105
 
106
+ See more examples here [https://kebasyaty.github.io/scruby/latest/pages/usage/](https://kebasyaty.github.io/scruby/latest/pages/usage/ "Examples").
107
+
106
108
  ```python
107
109
  """Working with keys."""
108
110
 
@@ -157,7 +159,7 @@ if __name__ == "__main__":
157
159
  ```
158
160
 
159
161
  ```python
160
- """Find a single document.
162
+ """Find a single document matching the filter.
161
163
 
162
164
  The search is based on the effect of a quantum loop.
163
165
  The search effectiveness depends on the number of processor threads.
@@ -228,7 +230,7 @@ if __name__ == "__main__":
228
230
  ```
229
231
 
230
232
  ```python
231
- """Find documents.
233
+ """Find one or more documents matching the filter.
232
234
 
233
235
  The search is based on the effect of a quantum loop.
234
236
  The search effectiveness depends on the number of processor threads.
@@ -288,42 +290,6 @@ if __name__ == "__main__":
288
290
  anyio.run(main)
289
291
  ```
290
292
 
291
- ```python
292
- """Get collection name."""
293
-
294
- import anyio
295
- import datetime
296
- from typing import Annotated
297
- from pydantic import BaseModel, EmailStr
298
- from pydantic_extra_types.phone_numbers import PhoneNumber, PhoneNumberValidator
299
- from scruby import Scruby, constants
300
-
301
- constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
302
-
303
- class User(BaseModel):
304
- """Model of User."""
305
- first_name: str
306
- last_name: str
307
- birthday: datetime.datetime
308
- email: EmailStr
309
- phone: Annotated[PhoneNumber, PhoneNumberValidator(number_format="E164")]
310
-
311
- async def main() -> None:
312
- """Example."""
313
- # Get collection of `User`.
314
- user_coll = Scruby(User)
315
-
316
- print(user_coll.collection_name()) # "User"
317
- print(user_coll.collection_full_name()) # "ScrubyDB/User"
318
-
319
- # Full database deletion.
320
- # Hint: The main purpose is tests.
321
- await Scruby.napalm()
322
-
323
- if __name__ == "__main__":
324
- anyio.run(main)
325
- ```
326
-
327
293
  ## Changelog
328
294
 
329
295
  [View the change history](https://github.com/kebasyaty/scruby/blob/v0/CHANGELOG.md "Changelog").
@@ -0,0 +1,8 @@
1
+ scruby/__init__.py,sha256=wFwUS1KcLxfIopXOVS8gPue9fNzIIU2cVj_RgK5drz4,849
2
+ scruby/constants.py,sha256=GbB-O0qaVdi5EHUp-zRAppFXLR-oHxpXUFVAOCpS0C8,1022
3
+ scruby/db.py,sha256=W3VvC3ss1NXonQnFI6Yw2MobBARMgus5Acw-k5uL3TE,10946
4
+ scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ scruby-0.9.2.dist-info/METADATA,sha256=vZab1ietT1of_GXLHEISYhIkXZJuBIp3vk_rAFGeNPA,10833
6
+ scruby-0.9.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ scruby-0.9.2.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
+ scruby-0.9.2.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- scruby/__init__.py,sha256=myX7sG-7oAQZGdgfZtTGXYCCraTeuwi7SjBoltftpnM,648
2
- scruby/constants.py,sha256=GbB-O0qaVdi5EHUp-zRAppFXLR-oHxpXUFVAOCpS0C8,1022
3
- scruby/db.py,sha256=1tfDCwoKwUx0a6DfEOpPAV8NYuifmmrX8Q9gU3K6l58,10407
4
- scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- scruby-0.9.0.dist-info/METADATA,sha256=7Durmb2_VtJ4plz-OM-vhzfLAM8QGYkmVTRX1KFfOYY,11533
6
- scruby-0.9.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- scruby-0.9.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
- scruby-0.9.0.dist-info/RECORD,,
File without changes