scruby 0.6.0__py3-none-any.whl → 0.6.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 +5 -7
- scruby/constants.py +13 -1
- scruby/db.py +16 -18
- {scruby-0.6.0.dist-info → scruby-0.6.2.dist-info}/METADATA +6 -2
- scruby-0.6.2.dist-info/RECORD +8 -0
- scruby-0.6.0.dist-info/RECORD +0 -8
- {scruby-0.6.0.dist-info → scruby-0.6.2.dist-info}/WHEEL +0 -0
- {scruby-0.6.0.dist-info → scruby-0.6.2.dist-info}/licenses/LICENSE +0 -0
scruby/__init__.py
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
"""A fast key-value storage library.
|
|
2
2
|
|
|
3
|
-
Scruby is a fast key-value storage library that provides an
|
|
3
|
+
Scruby is a fast key-value storage asynchronous library that provides an
|
|
4
|
+
ordered mapping from string keys to string values.
|
|
4
5
|
The library uses fractal-tree addressing.
|
|
5
6
|
|
|
6
7
|
The database consists of collections.
|
|
7
8
|
The maximum size of the one collection is 16**8=4294967296 branches,
|
|
8
9
|
each branch can store one or more keys.
|
|
9
10
|
|
|
10
|
-
The value of any key in collection can be obtained in 8 steps,
|
|
11
|
+
The value of any key in collection can be obtained in 8 steps,
|
|
12
|
+
thereby achieving high performance.
|
|
11
13
|
|
|
12
14
|
In the future, to search by value of key, the use of a quantum loop is supposed.
|
|
13
15
|
"""
|
|
14
16
|
|
|
15
17
|
from __future__ import annotations
|
|
16
18
|
|
|
17
|
-
__all__ = (
|
|
18
|
-
"Scruby",
|
|
19
|
-
"constants",
|
|
20
|
-
)
|
|
19
|
+
__all__ = ("Scruby",)
|
|
21
20
|
|
|
22
|
-
from scruby import constants
|
|
23
21
|
from scruby.db import Scruby
|
scruby/constants.py
CHANGED
|
@@ -3,9 +3,21 @@
|
|
|
3
3
|
The module contains the following variables:
|
|
4
4
|
|
|
5
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.
|
|
6
7
|
"""
|
|
7
8
|
|
|
8
9
|
from __future__ import annotations
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
from typing import Literal
|
|
12
|
+
|
|
13
|
+
# Path to root directory of database
|
|
14
|
+
# By default = "ScrubyDB" (in root of project).
|
|
11
15
|
DB_ROOT: str = "ScrubyDB"
|
|
16
|
+
|
|
17
|
+
# Length of separated hash for create path inside collection.
|
|
18
|
+
# By default = 8
|
|
19
|
+
# 2 = 256 branche (main purpose is tests).
|
|
20
|
+
# 4 = 65536 branche.
|
|
21
|
+
# 6 = 16777216 branche.
|
|
22
|
+
# 8 = 4294967296 branche (by default).
|
|
23
|
+
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
|
|
21
|
+
"""Creation and management of database.
|
|
22
22
|
|
|
23
23
|
Args:
|
|
24
24
|
class_model: Class of Model (Pydantic).
|
|
@@ -30,30 +30,28 @@ class Scruby[T]:
|
|
|
30
30
|
) -> None:
|
|
31
31
|
self.__class_model = class_model
|
|
32
32
|
|
|
33
|
-
def check_key(self, key: str) -> None:
|
|
34
|
-
"""Check the key."""
|
|
35
|
-
if not isinstance(key, str):
|
|
36
|
-
raise KeyError("The key is not a type of `str`.")
|
|
37
|
-
if len(key) == 0:
|
|
38
|
-
raise KeyError("The key should not be empty.")
|
|
39
|
-
|
|
40
33
|
async def get_leaf_path(self, key: str) -> Path:
|
|
41
|
-
"""
|
|
34
|
+
"""Asynchronous method for getting path to collection cell by key.
|
|
42
35
|
|
|
43
36
|
Args:
|
|
44
37
|
key: Key name.
|
|
45
38
|
"""
|
|
46
|
-
|
|
39
|
+
if not isinstance(key, str):
|
|
40
|
+
raise KeyError("The key is not a type of `str`.")
|
|
41
|
+
if len(key) == 0:
|
|
42
|
+
raise KeyError("The key should not be empty.")
|
|
43
|
+
# Get length of hash.
|
|
44
|
+
length_hash = constants.LENGTH_SEPARATED_HASH
|
|
47
45
|
# Key to crc32 sum.
|
|
48
|
-
|
|
46
|
+
key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[0:length_hash]
|
|
49
47
|
# Convert crc32 sum in the segment of path.
|
|
50
|
-
|
|
48
|
+
separated_hash: str = "/".join(list(key_as_hash))
|
|
51
49
|
# The path of the branch to the database.
|
|
52
50
|
branch_path: Path = Path(
|
|
53
51
|
*(
|
|
54
52
|
constants.DB_ROOT,
|
|
55
53
|
self.__class_model.__name__,
|
|
56
|
-
|
|
54
|
+
separated_hash,
|
|
57
55
|
),
|
|
58
56
|
)
|
|
59
57
|
# If the branch does not exist, need to create it.
|
|
@@ -68,7 +66,7 @@ class Scruby[T]:
|
|
|
68
66
|
key: str,
|
|
69
67
|
value: T,
|
|
70
68
|
) -> None:
|
|
71
|
-
"""Asynchronous method for adding and updating keys to
|
|
69
|
+
"""Asynchronous method for adding and updating keys to collection.
|
|
72
70
|
|
|
73
71
|
Args:
|
|
74
72
|
key: Key name.
|
|
@@ -89,7 +87,7 @@ class Scruby[T]:
|
|
|
89
87
|
await leaf_path.write_bytes(orjson.dumps({key: value_json}))
|
|
90
88
|
|
|
91
89
|
async def get_key(self, key: str) -> T:
|
|
92
|
-
"""Asynchronous method for getting key from
|
|
90
|
+
"""Asynchronous method for getting value of key from collection.
|
|
93
91
|
|
|
94
92
|
Args:
|
|
95
93
|
key: Key name.
|
|
@@ -105,7 +103,7 @@ class Scruby[T]:
|
|
|
105
103
|
raise KeyError()
|
|
106
104
|
|
|
107
105
|
async def has_key(self, key: str) -> bool:
|
|
108
|
-
"""Asynchronous method for checking presence of
|
|
106
|
+
"""Asynchronous method for checking presence of key in collection.
|
|
109
107
|
|
|
110
108
|
Args:
|
|
111
109
|
key: Key name.
|
|
@@ -124,7 +122,7 @@ class Scruby[T]:
|
|
|
124
122
|
return False
|
|
125
123
|
|
|
126
124
|
async def delete_key(self, key: str) -> None:
|
|
127
|
-
"""Asynchronous method for deleting key from
|
|
125
|
+
"""Asynchronous method for deleting key from collection.
|
|
128
126
|
|
|
129
127
|
Args:
|
|
130
128
|
key: Key name.
|
|
@@ -142,7 +140,7 @@ class Scruby[T]:
|
|
|
142
140
|
|
|
143
141
|
@classmethod
|
|
144
142
|
async def napalm(cls) -> None:
|
|
145
|
-
"""Asynchronous method for full database deletion
|
|
143
|
+
"""Asynchronous method for full database deletion.
|
|
146
144
|
|
|
147
145
|
The main purpose is tests.
|
|
148
146
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.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
|
|
@@ -65,10 +65,14 @@ 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 library that provides an
|
|
68
|
+
Scruby is a fast key-value storage asynchronous library that provides an
|
|
69
|
+
<br>
|
|
70
|
+
ordered mapping from string keys to string values.
|
|
71
|
+
<br>
|
|
69
72
|
The library uses fractal-tree addressing.
|
|
70
73
|
<br>
|
|
71
74
|
The database consists of collections.
|
|
75
|
+
<br>
|
|
72
76
|
The maximum size of the one collection is 16**8=4294967296 branches,
|
|
73
77
|
each branch can store one or more keys.
|
|
74
78
|
<br>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
scruby/__init__.py,sha256=myX7sG-7oAQZGdgfZtTGXYCCraTeuwi7SjBoltftpnM,648
|
|
2
|
+
scruby/constants.py,sha256=fQ9fHGkx1GwYWOdTCdwopYIVtwYWDi8evLOJtQcTtWg,711
|
|
3
|
+
scruby/db.py,sha256=Rt9YDe0lSJwtREHFiqdQ6CQ664FL6YRyczbgKFhpsa4,4871
|
|
4
|
+
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
scruby-0.6.2.dist-info/METADATA,sha256=Xql1qXX22lzjh67vvN63EoTOxdaUzn4sz99lTGalSy0,6803
|
|
6
|
+
scruby-0.6.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
scruby-0.6.2.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
scruby-0.6.2.dist-info/RECORD,,
|
scruby-0.6.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
scruby/__init__.py,sha256=Mvy-90k-kNUAlYA7xuCEIT1uC8u5pepuDxGy6DglCxU,689
|
|
2
|
-
scruby/constants.py,sha256=kwF0FIbeChBxsNxOCQhMsDEn1lakD7MIQKJ-PHYeSAo,328
|
|
3
|
-
scruby/db.py,sha256=Xn7AWXly8nubvWqsRrJYpvozUHB1CXNineizVK6GNEw,4854
|
|
4
|
-
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
scruby-0.6.0.dist-info/METADATA,sha256=2mxPkFwKcU2V-Mw6nz_fru7xo-TVdugS5XUPNYoJONg,6751
|
|
6
|
-
scruby-0.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
scruby-0.6.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
-
scruby-0.6.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|