scruby 0.6.1__py3-none-any.whl → 0.6.3__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
@@ -16,10 +16,6 @@ In the future, to search by value of key, the use of a quantum loop is supposed.
16
16
 
17
17
  from __future__ import annotations
18
18
 
19
- __all__ = (
20
- "Scruby",
21
- "constants",
22
- )
19
+ __all__ = ("Scruby",)
23
20
 
24
- from scruby import constants
25
21
  from scruby.db import Scruby
scruby/constants.py CHANGED
@@ -2,10 +2,31 @@
2
2
 
3
3
  The module contains the following variables:
4
4
 
5
- - `DB_ROOT` - Path to root directory of database. By default = "ScrubyDB" (in root of project).
5
+ - `DB_ROOT` - Path to root directory of database. `By default = "ScrubyDB"` (*in root of project*).
6
+ - `LENGTH_SEPARATED_HASH` - Length of separated hash for create path inside collection.
7
+ - `2` - 256 branches (main purpose is tests).
8
+ - `4` - 65536 branches.
9
+ - `6` - 16777216 branches.
10
+ - `8` - 4294967296 branches (by default).
6
11
  """
7
12
 
8
13
  from __future__ import annotations
9
14
 
10
- # Path to root directory of database. By default = "ScrubyDB" (in root of project).
15
+ __all__ = (
16
+ "DB_ROOT",
17
+ "LENGTH_SEPARATED_HASH",
18
+ )
19
+
20
+ from typing import Literal
21
+
22
+ # Path to root directory of database
23
+ # By default = "ScrubyDB" (in root of project).
11
24
  DB_ROOT: str = "ScrubyDB"
25
+
26
+ # Length of separated hash for create path inside collection.
27
+ # By default = 8
28
+ # 2 = 256 branches (main purpose is tests).
29
+ # 4 = 65536 branches.
30
+ # 6 = 16777216 branches.
31
+ # 8 = 4294967296 branches (by default).
32
+ LENGTH_SEPARATED_HASH: Literal[2, 4, 6, 8] = 8
scruby/db.py CHANGED
@@ -18,7 +18,7 @@ T = TypeVar("T")
18
18
 
19
19
 
20
20
  class Scruby[T]:
21
- """Creation and management of the database.
21
+ """Creation and management of database.
22
22
 
23
23
  Args:
24
24
  class_model: Class of Model (Pydantic).
@@ -31,7 +31,7 @@ class Scruby[T]:
31
31
  self.__class_model = class_model
32
32
 
33
33
  async def get_leaf_path(self, key: str) -> Path:
34
- """Get the path to the database cell by key.
34
+ """Asynchronous method for getting path to collection cell by key.
35
35
 
36
36
  Args:
37
37
  key: Key name.
@@ -40,16 +40,18 @@ class Scruby[T]:
40
40
  raise KeyError("The key is not a type of `str`.")
41
41
  if len(key) == 0:
42
42
  raise KeyError("The key should not be empty.")
43
- # Key to adler32 sum.
44
- key_adler32: str = f"{zlib.adler32(key.encode('utf-8')):08x}"
45
- # Convert adler32 sum in the segment of path.
46
- separated_adler32: str = "/".join(list(key_adler32))
43
+ # Get length of hash.
44
+ length_hash = constants.LENGTH_SEPARATED_HASH
45
+ # Key to crc32 sum.
46
+ key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[0:length_hash]
47
+ # Convert crc32 sum in the segment of path.
48
+ separated_hash: str = "/".join(list(key_as_hash))
47
49
  # The path of the branch to the database.
48
50
  branch_path: Path = Path(
49
51
  *(
50
52
  constants.DB_ROOT,
51
53
  self.__class_model.__name__,
52
- separated_adler32,
54
+ separated_hash,
53
55
  ),
54
56
  )
55
57
  # If the branch does not exist, need to create it.
@@ -64,7 +66,7 @@ class Scruby[T]:
64
66
  key: str,
65
67
  value: T,
66
68
  ) -> None:
67
- """Asynchronous method for adding and updating keys to database.
69
+ """Asynchronous method for adding and updating keys to collection.
68
70
 
69
71
  Args:
70
72
  key: Key name.
@@ -85,7 +87,7 @@ class Scruby[T]:
85
87
  await leaf_path.write_bytes(orjson.dumps({key: value_json}))
86
88
 
87
89
  async def get_key(self, key: str) -> T:
88
- """Asynchronous method for getting key from database.
90
+ """Asynchronous method for getting value of key from collection.
89
91
 
90
92
  Args:
91
93
  key: Key name.
@@ -101,7 +103,7 @@ class Scruby[T]:
101
103
  raise KeyError()
102
104
 
103
105
  async def has_key(self, key: str) -> bool:
104
- """Asynchronous method for checking presence of key in database.
106
+ """Asynchronous method for checking presence of key in collection.
105
107
 
106
108
  Args:
107
109
  key: Key name.
@@ -120,7 +122,7 @@ class Scruby[T]:
120
122
  return False
121
123
 
122
124
  async def delete_key(self, key: str) -> None:
123
- """Asynchronous method for deleting key from database.
125
+ """Asynchronous method for deleting key from collection.
124
126
 
125
127
  Args:
126
128
  key: Key name.
@@ -138,7 +140,7 @@ class Scruby[T]:
138
140
 
139
141
  @classmethod
140
142
  async def napalm(cls) -> None:
141
- """Asynchronous method for full database deletion (Arg: db_name).
143
+ """Asynchronous method for full database deletion.
142
144
 
143
145
  The main purpose is tests.
144
146
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 0.6.1
3
+ Version: 0.6.3
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
@@ -36,7 +36,7 @@ Description-Content-Type: text/markdown
36
36
  <p align="center">
37
37
  <a href="https://github.com/kebasyaty/scruby">
38
38
  <img
39
- height="90"
39
+ height="80"
40
40
  alt="Logo"
41
41
  src="https://raw.githubusercontent.com/kebasyaty/scruby/main/assets/logo.svg">
42
42
  </a>
@@ -65,7 +65,9 @@ Description-Content-Type: text/markdown
65
65
  <a href="https://github.com/kebasyaty/scruby/releases/" alt="GitHub release"><img src="https://img.shields.io/github/release/kebasyaty/scruby" alt="GitHub release"></a>
66
66
  </p>
67
67
  <p align="center">
68
- Scruby is a fast key-value storage asynchronous library that provides an ordered mapping from string keys to string values.
68
+ Scruby is a fast key-value storage asynchronous library that provides an
69
+ <br>
70
+ ordered mapping from string keys to string values.
69
71
  <br>
70
72
  The library uses fractal-tree addressing.
71
73
  <br>
@@ -81,6 +83,10 @@ Description-Content-Type: text/markdown
81
83
  </p>
82
84
  </div>
83
85
 
86
+ ##
87
+
88
+ <br>
89
+
84
90
  ## Documentation
85
91
 
86
92
  Online browsable documentation is available at [https://kebasyaty.github.io/scruby/](https://kebasyaty.github.io/scruby/ "Documentation").
@@ -0,0 +1,8 @@
1
+ scruby/__init__.py,sha256=myX7sG-7oAQZGdgfZtTGXYCCraTeuwi7SjBoltftpnM,648
2
+ scruby/constants.py,sha256=7Px7BDQozlvfSKSAN4Rme4uJHLY_OsT3H0Wq6A_810k,942
3
+ scruby/db.py,sha256=Rt9YDe0lSJwtREHFiqdQ6CQ664FL6YRyczbgKFhpsa4,4871
4
+ scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ scruby-0.6.3.dist-info/METADATA,sha256=8TTKyS4FsDr9PEvL7U5DKtAuRSxUR-s_cMiJ9F7Wwzw,6813
6
+ scruby-0.6.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ scruby-0.6.3.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
+ scruby-0.6.3.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- scruby/__init__.py,sha256=Bhg7pIV6u0YM7Dipr7vH7ka931bVuBoJugiYNd73HQ4,704
2
- scruby/constants.py,sha256=kwF0FIbeChBxsNxOCQhMsDEn1lakD7MIQKJ-PHYeSAo,328
3
- scruby/db.py,sha256=qhVoSMu-MDiIdPK4M3ruEZDXxcvKBPu-AS-J_xSNZE4,4763
4
- scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- scruby-0.6.1.dist-info/METADATA,sha256=qzdPamjqOufrJ7hibG37MaiUV27RAIcPikn9idMIYzg,6786
6
- scruby-0.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- scruby-0.6.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
8
- scruby-0.6.1.dist-info/RECORD,,
File without changes