scruby 0.4.0__py3-none-any.whl → 0.5.1__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 -1
- scruby/constants.py +11 -0
- scruby/db.py +9 -12
- {scruby-0.4.0.dist-info → scruby-0.5.1.dist-info}/METADATA +20 -20
- scruby-0.5.1.dist-info/RECORD +8 -0
- scruby-0.4.0.dist-info/RECORD +0 -7
- {scruby-0.4.0.dist-info → scruby-0.5.1.dist-info}/WHEEL +0 -0
- {scruby-0.4.0.dist-info → scruby-0.5.1.dist-info}/licenses/LICENSE +0 -0
scruby/__init__.py
CHANGED
|
@@ -12,6 +12,10 @@ There is no need to iterate through all the keys in search of the desired value.
|
|
|
12
12
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
|
-
__all__ = (
|
|
15
|
+
__all__ = (
|
|
16
|
+
"Scruby",
|
|
17
|
+
"constants",
|
|
18
|
+
)
|
|
16
19
|
|
|
20
|
+
from scruby import constants
|
|
17
21
|
from scruby.db import Scruby
|
scruby/constants.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Constant variables.
|
|
2
|
+
|
|
3
|
+
The module contains the following variables:
|
|
4
|
+
|
|
5
|
+
- `DB_ROOT` - Path to root directory of database. By default = "ScrubyDB" (in root of project).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
# Path to root directory of database. By default = "ScrubyDB" (in root of project).
|
|
11
|
+
DB_ROOT: str = "ScrubyDB"
|
scruby/db.py
CHANGED
|
@@ -6,33 +6,28 @@ __all__ = ("Scruby",)
|
|
|
6
6
|
|
|
7
7
|
import hashlib
|
|
8
8
|
from shutil import rmtree
|
|
9
|
-
from typing import
|
|
9
|
+
from typing import TypeVar
|
|
10
10
|
|
|
11
11
|
import orjson
|
|
12
12
|
from anyio import Path, to_thread
|
|
13
13
|
|
|
14
|
+
from scruby import constants
|
|
15
|
+
|
|
14
16
|
T = TypeVar("T")
|
|
15
17
|
|
|
16
18
|
|
|
17
|
-
class Scruby
|
|
19
|
+
class Scruby[T]:
|
|
18
20
|
"""Creation and management of the database.
|
|
19
21
|
|
|
20
22
|
Args:
|
|
21
|
-
|
|
23
|
+
class_model: Class of Model (Pydantic).
|
|
22
24
|
"""
|
|
23
25
|
|
|
24
26
|
def __init__( # noqa: D107
|
|
25
27
|
self,
|
|
26
28
|
class_model: T,
|
|
27
|
-
db_name: str = "ScrubyDB",
|
|
28
29
|
) -> None:
|
|
29
30
|
self.__class_model = class_model
|
|
30
|
-
self.__db_name = db_name
|
|
31
|
-
|
|
32
|
-
@property
|
|
33
|
-
def db_name(self) -> str:
|
|
34
|
-
"""Get database name."""
|
|
35
|
-
return self.__db_name
|
|
36
31
|
|
|
37
32
|
async def get_leaf_path(self, key: str) -> Path:
|
|
38
33
|
"""Get the path to the database cell by key.
|
|
@@ -46,7 +41,7 @@ class Scruby(Generic[T]): # noqa: UP046
|
|
|
46
41
|
separated_md5: str = "/".join(list(key_md5))
|
|
47
42
|
# The path of the branch to the database.
|
|
48
43
|
branch_path: Path = Path(
|
|
49
|
-
*(
|
|
44
|
+
*(constants.DB_ROOT, self.__class_model.__name__, separated_md5),
|
|
50
45
|
)
|
|
51
46
|
# If the branch does not exist, need to create it.
|
|
52
47
|
if not await branch_path.exists():
|
|
@@ -135,8 +130,10 @@ class Scruby(Generic[T]): # noqa: UP046
|
|
|
135
130
|
async def napalm(self) -> None:
|
|
136
131
|
"""Asynchronous method for full database deletion (Arg: db_name).
|
|
137
132
|
|
|
133
|
+
The main purpose is tests.
|
|
134
|
+
|
|
138
135
|
Warning:
|
|
139
136
|
- `Be careful, this will remove all keys.`
|
|
140
137
|
"""
|
|
141
|
-
await to_thread.run_sync(rmtree,
|
|
138
|
+
await to_thread.run_sync(rmtree, constants.DB_ROOT)
|
|
142
139
|
return
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.1
|
|
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
|
|
@@ -27,7 +27,9 @@ Classifier: Typing :: Typed
|
|
|
27
27
|
Requires-Python: <4.0,>=3.12
|
|
28
28
|
Requires-Dist: anyio>=4.10.0
|
|
29
29
|
Requires-Dist: orjson>=3.11.3
|
|
30
|
-
Requires-Dist:
|
|
30
|
+
Requires-Dist: phonenumbers>=9.0.13
|
|
31
|
+
Requires-Dist: pydantic-extra-types>=2.10.5
|
|
32
|
+
Requires-Dist: pydantic[email]>=2.11.7
|
|
31
33
|
Description-Content-Type: text/markdown
|
|
32
34
|
|
|
33
35
|
<div align="center">
|
|
@@ -96,32 +98,29 @@ uv add scruby
|
|
|
96
98
|
```python
|
|
97
99
|
import anyio
|
|
98
100
|
import datetime
|
|
99
|
-
from pydantic import BaseModel
|
|
100
|
-
from
|
|
101
|
+
from pydantic import BaseModel, EmailStr
|
|
102
|
+
from pydantic_extra_types.phone_numbers import PhoneNumber
|
|
103
|
+
from scruby import Scruby, constants
|
|
101
104
|
|
|
105
|
+
constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
|
|
102
106
|
|
|
103
|
-
|
|
104
|
-
"""
|
|
105
|
-
|
|
106
|
-
class User(BaseModel):
|
|
107
|
-
"""User model."""
|
|
108
|
-
|
|
109
|
-
first_name: str
|
|
110
|
-
last_name: str
|
|
111
|
-
birthday: datetime.datetime
|
|
112
|
-
email: str
|
|
113
|
-
phone: str
|
|
107
|
+
class User(BaseModel):
|
|
108
|
+
"""Model of User."""
|
|
114
109
|
|
|
110
|
+
first_name: str
|
|
111
|
+
last_name: str
|
|
112
|
+
birthday: datetime.datetime
|
|
113
|
+
email: EmailStr
|
|
114
|
+
phone: PhoneNumber
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
)
|
|
116
|
+
async def main() -> None:
|
|
117
|
+
"""Example."""
|
|
118
|
+
db = Scruby(User)
|
|
120
119
|
|
|
121
120
|
user = User(
|
|
122
121
|
first_name="John",
|
|
123
122
|
last_name="Smith",
|
|
124
|
-
birthday=datetime.datetime(1970, 1, 1),
|
|
123
|
+
birthday=datetime.datetime(1970, 1, 1),
|
|
125
124
|
email="John_Smith@gmail.com",
|
|
126
125
|
phone="+447986123456",
|
|
127
126
|
)
|
|
@@ -139,6 +138,7 @@ async def main() -> None:
|
|
|
139
138
|
await db.delete_key("key missing") # => KeyError
|
|
140
139
|
|
|
141
140
|
# Full database deletion.
|
|
141
|
+
# Hint: The main purpose is tests.
|
|
142
142
|
await db.napalm()
|
|
143
143
|
await db.napalm() # => FileNotFoundError
|
|
144
144
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
scruby/__init__.py,sha256=LnHBN1pIOtT89baSQoknQwYI1cy-hmN1Lo0k8o1Ms48,659
|
|
2
|
+
scruby/constants.py,sha256=kwF0FIbeChBxsNxOCQhMsDEn1lakD7MIQKJ-PHYeSAo,328
|
|
3
|
+
scruby/db.py,sha256=iG1D4-ncVrVysp7OXH-eZksnNacjNna4_8nUbMkWnSE,4409
|
|
4
|
+
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
scruby-0.5.1.dist-info/METADATA,sha256=47mNNYczCbwwTVMyJRoNIn03fQ2bnVNh8ynuVCm-P00,6678
|
|
6
|
+
scruby-0.5.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
scruby-0.5.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
scruby-0.5.1.dist-info/RECORD,,
|
scruby-0.4.0.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
scruby/__init__.py,sha256=TCxUjBI5A0KZcwvfmgaBVl8ScuzzOVvALl_T4iqSR9c,603
|
|
2
|
-
scruby/db.py,sha256=86e-U3IvNADoYhHv4PHGikqnH4KWVJEpu3d7oGuUc3s,4600
|
|
3
|
-
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
scruby-0.4.0.dist-info/METADATA,sha256=Oi3khca39iX9qdOuF-SEMtT6rkbESwDS8Wy3Zhjo8-o,6512
|
|
5
|
-
scruby-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
-
scruby-0.4.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
7
|
-
scruby-0.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|