scruby 0.9.3__py3-none-any.whl → 0.27.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.
scruby/__init__.py CHANGED
@@ -1,29 +1,37 @@
1
- """A fast key-value storage library.
2
-
3
- Scruby is a fast key-value storage asynchronous library that provides an
4
- ordered mapping from string keys to string values.
5
- The library uses fractal-tree addressing.
6
-
7
- The database consists of collections.
8
- The maximum size of the one collection is 16**8=4294967296 branches,
9
- each branch can store one or more keys.
10
-
11
- The value of any key in collection can be obtained in 8 steps,
12
- thereby achieving high performance.
13
-
14
- In the future, to search by value of key, the use of a quantum loop is supposed.
15
- """
16
-
17
- from __future__ import annotations
18
-
19
- __all__ = ("Scruby",)
20
-
21
- import logging
22
-
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
- )
1
+ #
2
+ # .|'''|                        '||
3
+ # ||                             ||
4
+ # `|'''|, .|'', '||''| '||  ||`  ||''|, '||  ||`
5
+ #  .   || ||     ||     ||  ||   ||  ||  `|..||
6
+ #  |...|' `|..' .||.    `|..'|. .||..|'      ||
7
+ #                                         ,  |'
8
+ #                                          ''
9
+ #
10
+ # Copyright (c) 2025 Gennady Kostyunin
11
+ # SPDX-License-Identifier: MIT
12
+ #
13
+ """Asynchronous library for building and managing a hybrid database, by scheme of key-value.
14
+
15
+ The library uses fractal-tree addressing and
16
+ the search for documents based on the effect of a quantum loop.
17
+
18
+ The database consists of collections.
19
+ The maximum size of the one collection is 16**8=4294967296 branches,
20
+ each branch can store one or more keys.
21
+
22
+ The value of any key in collection can be obtained in 8 steps,
23
+ thereby achieving high performance.
24
+
25
+ The effectiveness of the search for documents based on a quantum loop,
26
+ requires a large number of processor threads.
27
+ """
28
+
29
+ from __future__ import annotations
30
+
31
+ __all__ = (
32
+ "settings",
33
+ "Scruby",
34
+ )
35
+
36
+ from scruby import settings
37
+ from scruby.db import Scruby
scruby/aggregation.py ADDED
@@ -0,0 +1,152 @@
1
+ # Scruby - Asynchronous library for building and managing a hybrid database, by scheme of key-value.
2
+ # Copyright (c) 2025 Gennady Kostyunin
3
+ # SPDX-License-Identifier: MIT
4
+ #
5
+ """Aggregation classes."""
6
+
7
+ from __future__ import annotations
8
+
9
+ __all__ = (
10
+ "Average",
11
+ "Counter",
12
+ "Max",
13
+ "Min",
14
+ "Sum",
15
+ )
16
+
17
+ from decimal import ROUND_HALF_EVEN, Decimal
18
+ from typing import Any
19
+
20
+
21
+ class Average:
22
+ """Aggregation class for calculating the average value.
23
+
24
+ Args:
25
+ precision: The accuracy of rounding. `By default = .00`
26
+ rounding: Rounding mode. `By default = ROUND_HALF_EVEN`
27
+ """
28
+
29
+ def __init__( # noqa: D107
30
+ self,
31
+ precision: str = ".00",
32
+ rounding: str = ROUND_HALF_EVEN,
33
+ ) -> None:
34
+ self.value = Decimal()
35
+ self.counter = 0
36
+ self.precision = precision
37
+ self.rounding = rounding
38
+
39
+ def set(self, number: int | float) -> None:
40
+ """Add value.
41
+
42
+ Args:
43
+ number: Current value (int | float).
44
+ """
45
+ self.value += Decimal(str(number))
46
+ self.counter += 1
47
+
48
+ def get(self) -> Decimal:
49
+ """Get arithmetic average value.
50
+
51
+ Returns:
52
+ Number (Decimal) - Average value.
53
+ """
54
+ return (self.value / Decimal(str(self.counter))).quantize(
55
+ exp=Decimal(self.precision),
56
+ rounding=self.rounding,
57
+ )
58
+
59
+
60
+ class Counter:
61
+ """Aggregation class for calculating the number of documents.
62
+
63
+ Args:
64
+ limit: The maximum counter value.
65
+ """
66
+
67
+ def __init__(self, limit: int = 1000) -> None: # noqa: D107
68
+ self.limit = limit
69
+ self.counter = 0
70
+
71
+ def check(self) -> bool:
72
+ """Check the condition of the counter.
73
+
74
+ Returns:
75
+ Boolean value. If `True`, the maximum value is achieved.
76
+ """
77
+ return self.counter >= self.limit
78
+
79
+ def next(self) -> None:
80
+ """Increment the counter on one."""
81
+ self.counter += 1
82
+
83
+
84
+ class Max:
85
+ """Aggregation class for calculating the maximum value."""
86
+
87
+ def __init__(self) -> None: # noqa: D107
88
+ self.value: Any = 0
89
+
90
+ def set(self, number: int | float) -> None:
91
+ """Add value.
92
+
93
+ Args:
94
+ number: Current value.
95
+ """
96
+ if number > self.value:
97
+ self.value = number
98
+
99
+ def get(self) -> Any:
100
+ """Get maximum value.
101
+
102
+ Returns:
103
+ Number (int|float) - Maximum value.
104
+ """
105
+ return self.value
106
+
107
+
108
+ class Min:
109
+ """Aggregation class for calculating the minimum value."""
110
+
111
+ def __init__(self) -> None: # noqa: D107
112
+ self.value: Any = 0
113
+
114
+ def set(self, number: int | float) -> None:
115
+ """Add value.
116
+
117
+ Args:
118
+ number: Current value.
119
+ """
120
+ if self.value == 0 or number < self.value:
121
+ self.value = number
122
+
123
+ def get(self) -> Any:
124
+ """Get minimum value.
125
+
126
+ Returns:
127
+ Number (int|float) - Minimum value.
128
+ """
129
+ return self.value
130
+
131
+
132
+ class Sum:
133
+ """Aggregation class for calculating sum of values."""
134
+
135
+ def __init__(self) -> None: # noqa: D107
136
+ self.value = Decimal()
137
+
138
+ def set(self, number: int | float) -> None:
139
+ """Add value.
140
+
141
+ Args:
142
+ number: Current value.
143
+ """
144
+ self.value += Decimal(str(number))
145
+
146
+ def get(self) -> Decimal:
147
+ """Get sum of values.
148
+
149
+ Returns:
150
+ Number (int|float) - Sum of values.
151
+ """
152
+ return self.value