danielutils 1.1.28__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.
Files changed (287) hide show
  1. danielutils/__init__.py +50 -0
  2. danielutils/abstractions/__init__.py +3 -0
  3. danielutils/abstractions/db/__init__.py +10 -0
  4. danielutils/abstractions/db/database.py +206 -0
  5. danielutils/abstractions/db/database_definitions.py +219 -0
  6. danielutils/abstractions/db/database_exceptions.py +34 -0
  7. danielutils/abstractions/db/database_factory.py +70 -0
  8. danielutils/abstractions/db/database_initializer.py +261 -0
  9. danielutils/abstractions/db/database_models.py +213 -0
  10. danielutils/abstractions/db/dependencies.py +6 -0
  11. danielutils/abstractions/db/implementations/__init__.py +4 -0
  12. danielutils/abstractions/db/implementations/in_memory_database.py +365 -0
  13. danielutils/abstractions/db/implementations/persistent_in_memory_database.py +174 -0
  14. danielutils/abstractions/db/implementations/redis_database.py +403 -0
  15. danielutils/abstractions/db/implementations/sqlite_database.py +491 -0
  16. danielutils/abstractions/multiprogramming/__init__.py +3 -0
  17. danielutils/abstractions/multiprogramming/multi_id.py +26 -0
  18. danielutils/abstractions/multiprogramming/worker.py +104 -0
  19. danielutils/abstractions/multiprogramming/worker_pool.py +98 -0
  20. danielutils/abstractions/repl.py +125 -0
  21. danielutils/aliases.py +174 -0
  22. danielutils/async_/__init__.py +7 -0
  23. danielutils/async_/async_cmd.py +28 -0
  24. danielutils/async_/async_command.py +879 -0
  25. danielutils/async_/async_layered_command.py +125 -0
  26. danielutils/async_/async_retry_executor.py +86 -0
  27. danielutils/async_/async_worker_pool.py +110 -0
  28. danielutils/async_/time_strategy.py +73 -0
  29. danielutils/async_/utils.py +57 -0
  30. danielutils/better_builtins/__init__.py +3 -0
  31. danielutils/better_builtins/counter.py +48 -0
  32. danielutils/better_builtins/frange.py +266 -0
  33. danielutils/better_builtins/typed_builtins/__init__.py +4 -0
  34. danielutils/better_builtins/typed_builtins/factory.py +126 -0
  35. danielutils/better_builtins/typed_builtins/tdict.py +36 -0
  36. danielutils/better_builtins/typed_builtins/tlist.py +223 -0
  37. danielutils/better_builtins/typed_builtins/tset.py +67 -0
  38. danielutils/better_builtins/typed_builtins/ttuple.py +15 -0
  39. danielutils/colors.py +203 -0
  40. danielutils/context_managers/__init__.py +5 -0
  41. danielutils/context_managers/attr_context.py +40 -0
  42. danielutils/context_managers/multi_context.py +34 -0
  43. danielutils/context_managers/optional_context.py +33 -0
  44. danielutils/context_managers/state_context.py +25 -0
  45. danielutils/context_managers/temporary_file.py +108 -0
  46. danielutils/convenience.py +12 -0
  47. danielutils/conversions/__init__.py +2 -0
  48. danielutils/conversions/main_conversions.py +131 -0
  49. danielutils/conversions/specialized_conversions/__init__.py +2 -0
  50. danielutils/conversions/specialized_conversions/to_hex.py +25 -0
  51. danielutils/conversions/specialized_conversions/to_int.py +19 -0
  52. danielutils/custom_types.py +18 -0
  53. danielutils/data_structures/__init__.py +8 -0
  54. danielutils/data_structures/algorithms.py +52 -0
  55. danielutils/data_structures/comparer.py +47 -0
  56. danielutils/data_structures/default_dict.py +23 -0
  57. danielutils/data_structures/functions.py +35 -0
  58. danielutils/data_structures/graph/__init__.py +4 -0
  59. danielutils/data_structures/graph/binary_node.py +71 -0
  60. danielutils/data_structures/graph/graph.py +208 -0
  61. danielutils/data_structures/graph/multinode.py +101 -0
  62. danielutils/data_structures/graph/node.py +60 -0
  63. danielutils/data_structures/heap/__init__.py +3 -0
  64. danielutils/data_structures/heap/heap.py +119 -0
  65. danielutils/data_structures/heap/max_heap.py +18 -0
  66. danielutils/data_structures/heap/min_heap.py +18 -0
  67. danielutils/data_structures/queue/__init__.py +3 -0
  68. danielutils/data_structures/queue/atomic_queue.py +15 -0
  69. danielutils/data_structures/queue/priority_queue.py +110 -0
  70. danielutils/data_structures/queue/queue.py +92 -0
  71. danielutils/data_structures/stack.py +102 -0
  72. danielutils/data_structures/trees/__init__.py +2 -0
  73. danielutils/data_structures/trees/binary_syntax_tree.py +84 -0
  74. danielutils/data_structures/trees/binary_tree.py +63 -0
  75. danielutils/date.py +43 -0
  76. danielutils/date_time.py +23 -0
  77. danielutils/decorators/__init__.py +18 -0
  78. danielutils/decorators/atomic.py +45 -0
  79. danielutils/decorators/attach.py +61 -0
  80. danielutils/decorators/chain_decorators.py +39 -0
  81. danielutils/decorators/decorate_conditionally.py +32 -0
  82. danielutils/decorators/delay_call.py +47 -0
  83. danielutils/decorators/deprecate.py +46 -0
  84. danielutils/decorators/final.py +39 -0
  85. danielutils/decorators/limit_recursion.py +63 -0
  86. danielutils/decorators/memo.py +68 -0
  87. danielutils/decorators/normalize_decorator.py +55 -0
  88. danielutils/decorators/overload.py +204 -0
  89. danielutils/decorators/partially_implemented.py +32 -0
  90. danielutils/decorators/processify.py +74 -0
  91. danielutils/decorators/property.py +42 -0
  92. danielutils/decorators/singleton.py +59 -0
  93. danielutils/decorators/threadify.py +40 -0
  94. danielutils/decorators/timeout.py +82 -0
  95. danielutils/decorators/total_ordering.py +82 -0
  96. danielutils/decorators/validate.py +227 -0
  97. danielutils/exceptions.py +90 -0
  98. danielutils/functions/__init__.py +13 -0
  99. danielutils/functions/areoneof.py +47 -0
  100. danielutils/functions/check_foreach.py +39 -0
  101. danielutils/functions/factorial.py +24 -0
  102. danielutils/functions/flatten.py +33 -0
  103. danielutils/functions/foreach.py +20 -0
  104. danielutils/functions/isoftype.py +475 -0
  105. danielutils/functions/isoneof.py +71 -0
  106. danielutils/functions/multiloop.py +51 -0
  107. danielutils/functions/parallel_for.py +47 -0
  108. danielutils/functions/partition.py +45 -0
  109. danielutils/functions/powerset.py +31 -0
  110. danielutils/functions/subseteq.py +25 -0
  111. danielutils/functions/types_subseteq.py +51 -0
  112. danielutils/generators/__init__.py +3 -0
  113. danielutils/generators/conditional_generator.py +59 -0
  114. danielutils/generators/generator_from_stream.py +31 -0
  115. danielutils/generators/join_generators.py +109 -0
  116. danielutils/internet.py +92 -0
  117. danielutils/io_.py +451 -0
  118. danielutils/java/__init__.py +18 -0
  119. danielutils/java/interfaces/__init__.py +1 -0
  120. danielutils/java/interfaces/comparable.py +31 -0
  121. danielutils/java/java_interface.py +59 -0
  122. danielutils/logging_/__init__.py +2 -0
  123. danielutils/logging_/_impl/__init__.py +4 -0
  124. danielutils/logging_/_impl/builtin_impls/__init__.py +2 -0
  125. danielutils/logging_/_impl/builtin_impls/file_logger.py +35 -0
  126. danielutils/logging_/_impl/builtin_impls/print_logger.py +21 -0
  127. danielutils/logging_/_impl/log_level.py +13 -0
  128. danielutils/logging_/_impl/logger.py +109 -0
  129. danielutils/logging_/_impl/logger_strategy_impl_base.py +37 -0
  130. danielutils/logging_/utils.py +199 -0
  131. danielutils/lombok/__init__.py +1 -0
  132. danielutils/lombok/builder.py +68 -0
  133. danielutils/math_/__init__.py +2 -0
  134. danielutils/math_/constants.py +103 -0
  135. danielutils/math_/functions.py +34 -0
  136. danielutils/math_/math_print.py +52 -0
  137. danielutils/math_/math_symbols.py +125 -0
  138. danielutils/metaclasses/__init__.py +5 -0
  139. danielutils/metaclasses/atomic_class_meta.py +36 -0
  140. danielutils/metaclasses/implicit_data_deleter_meta.py +87 -0
  141. danielutils/metaclasses/instance_cache_meta.py +66 -0
  142. danielutils/metaclasses/interface.py +328 -0
  143. danielutils/metaclasses/overload_meta.py +48 -0
  144. danielutils/mock_/__init__.py +1 -0
  145. danielutils/mock_/mock_module.py +27 -0
  146. danielutils/path.py +55 -0
  147. danielutils/print_.py +123 -0
  148. danielutils/progress_bar/__init__.py +3 -0
  149. danielutils/progress_bar/ascii_progress_bar.py +161 -0
  150. danielutils/progress_bar/progress_bar.py +75 -0
  151. danielutils/progress_bar/progress_bar_pool.py +72 -0
  152. danielutils/protocols/__init__.py +3 -0
  153. danielutils/protocols/dictable.py +38 -0
  154. danielutils/protocols/evaluable.py +26 -0
  155. danielutils/protocols/serializable.py +51 -0
  156. danielutils/py.typed +0 -0
  157. danielutils/random_.py +47 -0
  158. danielutils/reflection/__init__.py +6 -0
  159. danielutils/reflection/declarations.py +288 -0
  160. danielutils/reflection/file/__init__.py +1 -0
  161. danielutils/reflection/file/file_reflection.py +85 -0
  162. danielutils/reflection/function/__init__.py +1 -0
  163. danielutils/reflection/function/function_reflections.py +152 -0
  164. danielutils/reflection/info_classes/__init__.py +6 -0
  165. danielutils/reflection/info_classes/argument_info.py +278 -0
  166. danielutils/reflection/info_classes/class_info.py +204 -0
  167. danielutils/reflection/info_classes/decorator_info.py +54 -0
  168. danielutils/reflection/info_classes/file_info.py +1180 -0
  169. danielutils/reflection/info_classes/folder_info.py +592 -0
  170. danielutils/reflection/info_classes/function_info.py +551 -0
  171. danielutils/reflection/info_classes/import_info.py +207 -0
  172. danielutils/reflection/interpreter/__init__.py +9 -0
  173. danielutils/reflection/interpreter/callstack.py +57 -0
  174. danielutils/reflection/interpreter/get_traceback.py +27 -0
  175. danielutils/reflection/interpreter/interpreter.py +41 -0
  176. danielutils/reflection/interpreter/is_debugging.py +13 -0
  177. danielutils/reflection/interpreter/os_.py +33 -0
  178. danielutils/reflection/interpreter/packages.py +33 -0
  179. danielutils/reflection/interpreter/python_version.py +33 -0
  180. danielutils/reflection/interpreter/signals.py +18 -0
  181. danielutils/reflection/interpreter/tracer.py +175 -0
  182. danielutils/reflection/module/__init__.py +3 -0
  183. danielutils/reflection/module/lazy_module.py +104 -0
  184. danielutils/reflection/module/module_reflections.py +34 -0
  185. danielutils/reflection/module/package_reflection.py +161 -0
  186. danielutils/retry_executor/__init__.py +3 -0
  187. danielutils/retry_executor/backoff_strategies/__init__.py +6 -0
  188. danielutils/retry_executor/backoff_strategies/constant_backoff.py +25 -0
  189. danielutils/retry_executor/backoff_strategies/exponential_backoff.py +26 -0
  190. danielutils/retry_executor/backoff_strategies/functional_backoff.py +29 -0
  191. danielutils/retry_executor/backoff_strategies/linear_backoff.py +23 -0
  192. danielutils/retry_executor/backoff_strategies/multiplicative_backoff.py +23 -0
  193. danielutils/retry_executor/backoff_strategies/no_backoff.py +17 -0
  194. danielutils/retry_executor/backoff_strategy.py +28 -0
  195. danielutils/retry_executor/retry_executor.py +55 -0
  196. danielutils/snippets/__init__.py +1 -0
  197. danielutils/snippets/try_get.py +28 -0
  198. danielutils/system/__init__.py +3 -0
  199. danielutils/system/independent.py +197 -0
  200. danielutils/system/layered_command.py +130 -0
  201. danielutils/system/windows/__init__.py +2 -0
  202. danielutils/system/windows/utils/__init__.py +1 -0
  203. danielutils/system/windows/utils/filetime.py +19 -0
  204. danielutils/system/windows/win32_ctime.py +183 -0
  205. danielutils/system/windows/windows.py +78 -0
  206. danielutils/testing/__init__.py +1 -0
  207. danielutils/testing/unittest_/__init__.py +2 -0
  208. danielutils/testing/unittest_/always_teardown_testcase.py +75 -0
  209. danielutils/testing/unittest_/auto_cwd_testcase.py +114 -0
  210. danielutils/text.py +169 -0
  211. danielutils/time.py +64 -0
  212. danielutils/tools/__init__.py +1 -0
  213. danielutils/tools/unittest_test_runner/__init__.py +9 -0
  214. danielutils/tools/unittest_test_runner/cli.py +70 -0
  215. danielutils/tools/unittest_test_runner/core/__init__.py +17 -0
  216. danielutils/tools/unittest_test_runner/core/discovery.py +322 -0
  217. danielutils/tools/unittest_test_runner/core/execution.py +244 -0
  218. danielutils/tools/unittest_test_runner/core/parser.py +163 -0
  219. danielutils/tools/unittest_test_runner/core/runner.py +561 -0
  220. danielutils/tools/unittest_test_runner/models.py +82 -0
  221. danielutils/university/__init__.py +7 -0
  222. danielutils/university/computability_and_complexity/__init__.py +2 -0
  223. danielutils/university/computability_and_complexity/discreate_finite_automaton.py +89 -0
  224. danielutils/university/computability_and_complexity/languages/__init__.py +0 -0
  225. danielutils/university/computability_and_complexity/languages/language.py +17 -0
  226. danielutils/university/computability_and_complexity/languages/sat.py +71 -0
  227. danielutils/university/computability_and_complexity/turing_machine.py +47 -0
  228. danielutils/university/databases/__init__.py +1 -0
  229. danielutils/university/databases/all.py +756 -0
  230. danielutils/university/image_proccesing/__init__.py +1 -0
  231. danielutils/university/image_proccesing/encoding/__init__.py +3 -0
  232. danielutils/university/image_proccesing/encoding/encoding.py +35 -0
  233. danielutils/university/image_proccesing/encoding/lossless/__init__.py +4 -0
  234. danielutils/university/image_proccesing/encoding/lossless/huffman.py +0 -0
  235. danielutils/university/image_proccesing/encoding/lossless/lossless_encoding.py +10 -0
  236. danielutils/university/image_proccesing/encoding/lossless/lzw.py +0 -0
  237. danielutils/university/image_proccesing/encoding/lossless/run_length.py +22 -0
  238. danielutils/university/image_proccesing/encoding/lossy/__init__.py +1 -0
  239. danielutils/university/image_proccesing/encoding/lossy/lossy_encoding.py +10 -0
  240. danielutils/university/image_proccesing/tansformations/__init__.py +0 -0
  241. danielutils/university/image_proccesing/tansformations/gaussian.py +0 -0
  242. danielutils/university/image_proccesing/tansformations/gradient.py +0 -0
  243. danielutils/university/image_proccesing/tansformations/hough.py +0 -0
  244. danielutils/university/image_proccesing/tansformations/laplacian.py +0 -0
  245. danielutils/university/image_proccesing/tansformations/transformation.py +11 -0
  246. danielutils/university/linear_algebra/__init__.py +1 -0
  247. danielutils/university/linear_algebra/matrix.py +404 -0
  248. danielutils/university/machine_learning/__init__.py +0 -0
  249. danielutils/university/machine_learning/activation_functions/__init__.py +2 -0
  250. danielutils/university/machine_learning/activation_functions/activation_function.py +11 -0
  251. danielutils/university/machine_learning/activation_functions/relu.py +11 -0
  252. danielutils/university/machine_learning/neuron.py +15 -0
  253. danielutils/university/oop/__init__.py +1 -0
  254. danielutils/university/oop/observer.py +31 -0
  255. danielutils/university/oop/strategy.py +9 -0
  256. danielutils/university/probability/__init__.py +7 -0
  257. danielutils/university/probability/conditional_variable/__init__.py +3 -0
  258. danielutils/university/probability/conditional_variable/conditional_variable.py +138 -0
  259. danielutils/university/probability/conditional_variable/continuous/__init__.py +0 -0
  260. danielutils/university/probability/conditional_variable/discrete/__init__.py +8 -0
  261. danielutils/university/probability/conditional_variable/discrete/bernoulli.py +38 -0
  262. danielutils/university/probability/conditional_variable/discrete/bernoulli_sum.py +31 -0
  263. danielutils/university/probability/conditional_variable/discrete/binomial.py +40 -0
  264. danielutils/university/probability/conditional_variable/discrete/conditional_from_discrete_probability_func.py +36 -0
  265. danielutils/university/probability/conditional_variable/discrete/discrete.py +42 -0
  266. danielutils/university/probability/conditional_variable/discrete/geometric.py +43 -0
  267. danielutils/university/probability/conditional_variable/discrete/poisson.py +32 -0
  268. danielutils/university/probability/conditional_variable/discrete/uniform.py +33 -0
  269. danielutils/university/probability/distributions.py +35 -0
  270. danielutils/university/probability/expressions/__init__.py +2 -0
  271. danielutils/university/probability/expressions/accumulation_expression.py +291 -0
  272. danielutils/university/probability/expressions/probability_expression.py +110 -0
  273. danielutils/university/probability/funcs/__init__.py +4 -0
  274. danielutils/university/probability/funcs/covariance.py +12 -0
  275. danielutils/university/probability/funcs/expected_value.py +41 -0
  276. danielutils/university/probability/funcs/probability_function.py +14 -0
  277. danielutils/university/probability/funcs/variance.py +17 -0
  278. danielutils/university/probability/operator.py +79 -0
  279. danielutils/university/probability/protocols.py +32 -0
  280. danielutils/university/probability/supp.py +101 -0
  281. danielutils/university/probability/transformation.py +44 -0
  282. danielutils/versioned_imports.py +31 -0
  283. danielutils-1.1.28.dist-info/METADATA +390 -0
  284. danielutils-1.1.28.dist-info/RECORD +287 -0
  285. danielutils-1.1.28.dist-info/WHEEL +5 -0
  286. danielutils-1.1.28.dist-info/licenses/LICENSE +21 -0
  287. danielutils-1.1.28.dist-info/top_level.txt +1 -0
@@ -0,0 +1,101 @@
1
+ from abc import abstractmethod, ABC
2
+ from typing import Iterator, TypeVar, Union
3
+ from ...better_builtins import frange
4
+ from ...decorators import memo
5
+
6
+ T = TypeVar('T')
7
+
8
+
9
+ class Supp(ABC, Iterator[T]):
10
+ @property
11
+ @abstractmethod
12
+ def is_finite(self) -> bool: ...
13
+
14
+ def is_infinite(self) -> bool:
15
+ return not self.is_finite
16
+
17
+ @abstractmethod
18
+ def __contains__(self, item) -> bool: ...
19
+
20
+ @property
21
+ @abstractmethod
22
+ def minimum(self) -> float: ...
23
+
24
+ @property
25
+ @abstractmethod
26
+ def maximum(self) -> float: ...
27
+
28
+
29
+ class DiscreteSupp(Supp[int]):
30
+ pass
31
+
32
+
33
+ class FrangeSupp(DiscreteSupp):
34
+ @property
35
+ def is_finite(self) -> bool:
36
+ if isinstance(self._r, frange): # type:ignore
37
+ return self._r.is_finite # type:ignore
38
+ return True
39
+
40
+ def __next__(self):
41
+ yield from self
42
+
43
+ def __init__(self, r: Union[range, frange]): # type:ignore
44
+ self._r: frange = r if isinstance(r, frange) else frange.from_range(r) # type:ignore
45
+
46
+ def __iter__(self) -> Iterator[int]:
47
+ return iter(self._r)
48
+
49
+ def __contains__(self, item) -> bool:
50
+ return item in self._r # type:ignore
51
+
52
+ @property
53
+ def minimum(self) -> float:
54
+ return self._r.start # type:ignore
55
+
56
+ @property
57
+ def maximum(self) -> float:
58
+ return self._r.stop # type:ignore
59
+
60
+ @property
61
+ def step(self) -> float:
62
+ return self._r.step # type:ignore
63
+
64
+
65
+ class SetSupp(DiscreteSupp):
66
+ @property
67
+ def is_finite(self) -> bool:
68
+ return True
69
+
70
+ @property
71
+ @memo # type:ignore
72
+ def minimum(self) -> float:
73
+ return min(self._s)
74
+
75
+ @property
76
+ @memo # type:ignore
77
+ def maximum(self) -> float:
78
+ return max(self._s)
79
+
80
+ def __init__(self, s: set) -> None:
81
+ self._s = s
82
+
83
+ def __iter__(self) -> Iterator:
84
+ return iter(self._s)
85
+
86
+ def __contains__(self, item) -> bool:
87
+ return item in self._s
88
+
89
+
90
+ class ContinuseSupp(Supp[float]):
91
+
92
+ @property
93
+ def is_finite(self) -> bool:
94
+ return False
95
+
96
+
97
+ __all__ = [
98
+ "Supp",
99
+ "FrangeSupp",
100
+ "ContinuseSupp",
101
+ ]
@@ -0,0 +1,44 @@
1
+ from fractions import Fraction
2
+ from typing import Union, Callable, Any, Dict
3
+
4
+ from .conditional_variable import ConditionalVariable
5
+ from .supp import Supp, FrangeSupp, ContinuseSupp
6
+ from .operator import Operator
7
+
8
+ _mapping: Callable[[Any], Dict[Operator, Callable]] = lambda self: {
9
+ Operator.ADD: lambda k: k + self.value,
10
+ Operator.SUB: lambda k: k - self.value,
11
+ Operator.MUL: lambda k: k * self.value,
12
+ Operator.POW: lambda k: k ** self.value,
13
+ Operator.DIV: lambda k: k / self.value,
14
+ }
15
+
16
+
17
+ class Transformation:
18
+ def __init__(self, var: Union[ConditionalVariable, 'Transformation'], op: Operator,
19
+ value: Union[int, float, Fraction]) -> None:
20
+ self.var = var
21
+ self.op = op
22
+ self.value = value
23
+
24
+ def supp(self) -> Supp:
25
+ if isinstance(self.var, ConditionalVariable):
26
+ return self.var.supp
27
+ return self.image()
28
+
29
+ def image(self) -> Supp:
30
+ # TODO
31
+ if isinstance(self.var, ConditionalVariable):
32
+ if self.var.supp.is_finite:
33
+ for s in self.var.supp:
34
+ pass
35
+ # TODO
36
+ return None # type:ignore
37
+
38
+ def _transform_one(self, n: Union[int, float, Fraction]) -> Union[int, float, Fraction]:
39
+ return _mapping(self)[self.op](n)
40
+
41
+
42
+ __all__ = [
43
+ "Transformation"
44
+ ]
@@ -0,0 +1,31 @@
1
+ from typing import Tuple
2
+
3
+ try:
4
+ from typing import ParamSpec
5
+ except ImportError:
6
+ from .reflection import get_python_version
7
+
8
+ if get_python_version() >= (3, 9):
9
+ ParamSpec = lambda name: [Any] # type: ignore
10
+ else:
11
+ from typing import Any
12
+
13
+ ParamSpec = lambda name: [Any] # type: ignore
14
+
15
+ try:
16
+ from typing import TypeAlias
17
+ except ImportError:
18
+ from typing import Any
19
+
20
+ TypeAlias = Any # type: ignore
21
+
22
+ try:
23
+ from typing import Annotated
24
+ except ImportError:
25
+ from typing_extensions import Annotated
26
+
27
+ __all__ = [
28
+ "ParamSpec",
29
+ "TypeAlias",
30
+ "Annotated",
31
+ ]
@@ -0,0 +1,390 @@
1
+ Metadata-Version: 2.4
2
+ Name: danielutils
3
+ Version: 1.1.28
4
+ Summary: A comprehensive Python utilities library providing type-safe collections, async programming tools, database abstractions, retry executors, data structures, and developer productivity enhancements to streamline Python development workflows
5
+ Author-email: danielnachumdev <danielnachumdev@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2022 danielnachumdev
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: Homepage, https://github.com/danielnachumdev/danielutils
28
+ Project-URL: Bug Tracker, https://github.com/danielnachumdev/danielutils/issues
29
+ Classifier: Development Status :: 3 - Alpha
30
+ Classifier: Intended Audience :: Developers
31
+ Classifier: Programming Language :: Python :: 3
32
+ Classifier: Operating System :: Microsoft :: Windows
33
+ Requires-Python: >=3.8.0
34
+ Description-Content-Type: text/markdown
35
+ License-File: LICENSE
36
+ Requires-Dist: pydantic>=2.10.6
37
+ Requires-Dist: redis>=6.1.1
38
+ Requires-Dist: sqlalchemy>=2.0.51
39
+ Requires-Dist: tqdm>=4.68.3
40
+ Dynamic: license-file
41
+
42
+ [![Python package](https://github.com/danielnachumdev/danielutils/actions/workflows/python-package.yml/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/python-package.yml)
43
+ [![Pylint](https://github.com/danielnachumdev/danielutils/actions/workflows/pylint.yml/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/pylint.yml)
44
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
45
+ [![gitleaks](https://github.com/danielnachumdev/danielutils/actions/workflows/gitleaks.yml/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/gitleaks.yml)
46
+ [![CodeQL](https://github.com/danielnachumdev/danielutils/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/danielnachumdev/danielutils/actions/workflows/github-code-scanning/codeql)
47
+
48
+ # danielutils v1.1.21
49
+
50
+ A comprehensive Python utilities library designed to enhance your development workflow with powerful tools for type safety, async programming, database operations, and much more.
51
+
52
+ **Features:**
53
+ - 🎯 **Type Safety**: Advanced type checking, validation, and typed collections
54
+ - ⚡ **Async Support**: Comprehensive async utilities and worker pools
55
+ - 🗄️ **Database Abstractions**: Multi-backend database support (SQLite, Redis, In-Memory)
56
+ - 🔄 **Retry Logic**: Configurable retry executors with multiple backoff strategies
57
+ - 📊 **Data Structures**: Enhanced collections, graphs, heaps, and algorithms
58
+ - 🎨 **Developer Experience**: Progress bars, logging, reflection, and debugging tools
59
+ - 🧮 **Academic Tools**: Probability theory and statistical functions
60
+
61
+ **Tested Python versions**: `3.8.0+`, `3.9.0`, `3.10.13`
62
+
63
+ > **Note**: This package is actively developed and subject to change. Use at your own risk!
64
+
65
+ ## 🚀 Quick Start
66
+
67
+ ```python
68
+ from danielutils import isoftype, validate, tlist
69
+ from danielutils.abstractions.db import DatabaseFactory
70
+ from danielutils.abstractions.db.database_definitions import TableSchema, TableColumn, ColumnType
71
+
72
+ # Type-safe list with runtime validation
73
+ numbers = tlist[int]([1, 2, 3, 4, 5])
74
+
75
+ # Function validation
76
+ @validate
77
+ def greet(name: str, age: int) -> str:
78
+ return f"Hello {name}, you are {age} years old"
79
+
80
+ # Database operations
81
+ db = DatabaseFactory.get_database("memory") # In-memory database
82
+ with db:
83
+ # Create a table
84
+ schema = TableSchema(
85
+ name="users",
86
+ columns=[
87
+ TableColumn(name="id", type=ColumnType.AUTOINCREMENT, primary_key=True),
88
+ TableColumn(name="name", type=ColumnType.TEXT, nullable=False),
89
+ TableColumn(name="age", type=ColumnType.INTEGER)
90
+ ]
91
+ )
92
+ db.create_table(schema)
93
+
94
+ # Insert data
95
+ user_id = db.insert("users", {"name": "Alice", "age": 30})
96
+
97
+ # Advanced type checking
98
+ if isoftype(numbers, list[int]):
99
+ print("Numbers is a list of integers!")
100
+ ```
101
+
102
+ ## 📚 Documentation
103
+
104
+ In the [`./READMES/`](./READMES/) folder you can find detailed documentation for key features:
105
+
106
+ ### Core Features
107
+
108
+ #### [`isoftype`](./READMES/isoftype.md)
109
+ **Advanced Type Checking System**
110
+ - Runtime type validation with support for complex types
111
+ - Parametrized generics and union types
112
+ - Protocol and interface checking
113
+ - Enhanced type safety for your applications
114
+
115
+ #### [`@overload`](./READMES/overload.md)
116
+ **Function Overloading Made Easy**
117
+ - Manage multiple function signatures
118
+ - Type-safe function overloading
119
+ - Simplified API design with clear type hints
120
+
121
+ #### [`@validate`](./READMES/validate.md)
122
+ **Runtime Type Validation**
123
+ - Protect your functions with automatic argument validation
124
+ - Catch type-related errors early
125
+ - Enhanced debugging and error messages
126
+
127
+ #### [`tlist`](./READMES/tlist.md)
128
+ **Type-Safe Collections**
129
+ - Runtime type validation for lists
130
+ - Enhanced list operations with type safety
131
+ - Seamless integration with existing code
132
+
133
+ #### [`Interface`](./READMES/Interface.md)
134
+ **Python Interface Implementation**
135
+ - Create interface-like behavior using metaclasses
136
+ - Abstract class patterns
137
+ - Enhanced object-oriented programming
138
+
139
+ ## 🛠️ Major Features
140
+
141
+ ### Database Abstractions (`@/db`)
142
+ ```python
143
+ from danielutils.abstractions.db import DatabaseFactory
144
+ from danielutils.abstractions.db.database_definitions import (
145
+ TableSchema, TableColumn, ColumnType, SelectQuery, WhereClause, Condition, Operator
146
+ )
147
+
148
+ # Get different database backends
149
+ sqlite_db = DatabaseFactory.get_database("sqlite", db_kwargs={"db_path": "test.db"})
150
+ memory_db = DatabaseFactory.get_database("memory")
151
+
152
+ # Create table schema
153
+ schema = TableSchema(
154
+ name="products",
155
+ columns=[
156
+ TableColumn(name="id", type=ColumnType.AUTOINCREMENT, primary_key=True),
157
+ TableColumn(name="name", type=ColumnType.TEXT, nullable=False),
158
+ TableColumn(name="price", type=ColumnType.FLOAT),
159
+ TableColumn(name="category", type=ColumnType.TEXT)
160
+ ]
161
+ )
162
+
163
+ # Use database with context manager
164
+ with memory_db:
165
+ memory_db.create_table(schema)
166
+
167
+ # Insert data
168
+ product_id = memory_db.insert("products", {
169
+ "name": "Laptop",
170
+ "price": 999.99,
171
+ "category": "Electronics"
172
+ })
173
+
174
+ # Query data
175
+ query = SelectQuery(
176
+ table="products",
177
+ where=WhereClause(
178
+ conditions=[
179
+ Condition(column="category", operator=Operator.EQ, value="Electronics")
180
+ ]
181
+ )
182
+ )
183
+ results = memory_db.get(query)
184
+ ```
185
+
186
+ ### Async Programming
187
+ ```python
188
+ import asyncio
189
+ from danielutils.async_ import AsyncWorkerPool, AsyncLayeredCommand
190
+
191
+ async def process_item(item: str) -> None:
192
+ """Async function to process items"""
193
+ await asyncio.sleep(0.1) # Simulate work
194
+ print(f"Processed: {item}")
195
+
196
+ async def main():
197
+ # Async worker pool
198
+ pool = AsyncWorkerPool("data_processor", num_workers=3, show_pbar=True)
199
+ await pool.start()
200
+
201
+ # Submit tasks
202
+ items = ["item1", "item2", "item3", "item4", "item5"]
203
+ for item in items:
204
+ await pool.submit(process_item, args=(item,), name=f"process_{item}")
205
+
206
+ # Wait for completion
207
+ await pool.join()
208
+
209
+ # Async command execution
210
+ async with AsyncLayeredCommand("echo") as cmd:
211
+ result = await cmd.execute("Hello from async command")
212
+ print(f"Command output: {result}")
213
+
214
+ # Run the async example
215
+ asyncio.run(main())
216
+ ```
217
+
218
+ ### Retry Executors
219
+ ```python
220
+ from danielutils.retry_executor import RetryExecutor
221
+ from danielutils.retry_executor.backoff_strategies import ExponentialBackOffStrategy
222
+
223
+ def unreliable_function() -> str:
224
+ """Function that might fail"""
225
+ import random
226
+ if random.random() < 0.7: # 70% chance of failure
227
+ raise ValueError("Random failure")
228
+ return "Success!"
229
+
230
+ # Create retry executor with exponential backoff
231
+ backoff = ExponentialBackOffStrategy(initial=1000) # 1 second initial delay
232
+ executor = RetryExecutor(backoff_strategy=backoff)
233
+
234
+ # Execute with retry logic
235
+ result = executor.execute(unreliable_function, max_retries=3)
236
+ if result:
237
+ print(f"Function succeeded: {result}")
238
+ else:
239
+ print("Function failed after all retries")
240
+ ```
241
+
242
+ ### Data Structures
243
+ ```python
244
+ from danielutils.data_structures import Graph, MinHeap, PriorityQueue
245
+ from danielutils.better_builtins import tlist, tdict
246
+ from typing import Any
247
+ from danielutils.data_structures.graph import MultiNode
248
+
249
+ # Type-safe collections
250
+ users = tlist[str](["alice", "bob", "charlie"])
251
+ config = tdict[str, Any]({"debug": True, "port": 8080})
252
+
253
+ # Advanced data structures
254
+ graph = Graph()
255
+ node_a = MultiNode("A")
256
+ node_b = MultiNode("B")
257
+ node_a.add_child(node_b)
258
+ graph.add_node(node_a)
259
+
260
+ # Priority queue with custom objects
261
+ class Task:
262
+ def __init__(self, name: str, priority: int):
263
+ self.name = name
264
+ self.priority = priority
265
+
266
+ def __lt__(self, other):
267
+ return self.priority < other.priority
268
+
269
+ queue = PriorityQueue[Task]()
270
+ queue.push(Task("high_priority", 1))
271
+ queue.push(Task("low_priority", 3))
272
+ queue.push(Task("medium_priority", 2))
273
+
274
+ # Min heap
275
+ heap = MinHeap[int]()
276
+ heap.push(5)
277
+ heap.push(2)
278
+ heap.push(8)
279
+ heap.push(1)
280
+
281
+ print(f"Min value: {heap.peek()}") # 1
282
+ ```
283
+
284
+ ### Progress Tracking
285
+ ```python
286
+ from danielutils.progress_bar import ProgressBarPool, AsciiProgressBar
287
+
288
+ # Single progress bar
289
+ with AsciiProgressBar(range(100), position=0, desc="Processing") as pbar:
290
+ for i in pbar:
291
+ # Do some work
292
+ import time
293
+ time.sleep(0.01)
294
+
295
+ # Multiple progress bars
296
+ with ProgressBarPool(AsciiProgressBar, num_of_bars=2) as pool:
297
+ # Configure individual bars
298
+ pool[0].update(50) # Update first bar
299
+ pool[1].update(25) # Update second bar
300
+
301
+ # Write messages
302
+ pool.write("Processing complete!")
303
+ ```
304
+
305
+ ### Reflection & Debugging
306
+ ```python
307
+ from danielutils.reflection import FunctionInfo, ClassInfo
308
+ from danielutils.reflection.interpreter import is_debugging
309
+
310
+ def example_function(name: str, age: int = 25) -> str:
311
+ """Example function for reflection"""
312
+ return f"Hello {name}, age {age}"
313
+
314
+ # Function introspection
315
+ info = FunctionInfo(example_function, type)
316
+ print(f"Function name: {info.name}")
317
+ print(f"Parameters: {info.arguments}")
318
+ print(f"Return type: {info.return_type}")
319
+
320
+ # Class introspection
321
+ class ExampleClass:
322
+ def __init__(self, value: int):
323
+ self.value = value
324
+
325
+ def get_value(self) -> int:
326
+ return self.value
327
+
328
+ class_info = ClassInfo(ExampleClass)
329
+ print(f"Class methods: {[f.name for f in class_info.instance_methods]}")
330
+
331
+ # Runtime debugging detection
332
+ if is_debugging():
333
+ print("Running in debug mode")
334
+ ```
335
+
336
+ ## 🎓 Academic & Research Tools
337
+
338
+ ### Probability Theory
339
+ ```python
340
+ from danielutils.university.probability import Distribution
341
+ from danielutils.university.probability.funcs import expected_value
342
+ from danielutils.university.probability.operator import Operator
343
+
344
+ # Create probability distributions
345
+ bernoulli = Distribution.Discrete.Ber(p=0.5) # Bernoulli with p=0.5
346
+ binomial = Distribution.Discrete.Bin(n=10, p=0.3) # Binomial with n=10, p=0.3
347
+
348
+ # Calculate probabilities
349
+ prob_1 = bernoulli.evaluate(1, Operator.EQ) # P(X=1)
350
+ prob_0 = bernoulli.evaluate(0, Operator.EQ) # P(X=0)
351
+
352
+ # Calculate expected values
353
+ expected_bernoulli = expected_value(bernoulli)
354
+ expected_binomial = expected_value(binomial)
355
+
356
+ print(f"Bernoulli P(X=1): {prob_1}")
357
+ print(f"Bernoulli E[X]: {expected_bernoulli}")
358
+ ```
359
+
360
+ ## 🔧 Installation
361
+
362
+ ```bash
363
+ pip install danielutils
364
+ ```
365
+
366
+ ## 📈 Project Status
367
+
368
+ This library has evolved significantly since its initial release in September 2022:
369
+
370
+ - **2022**: Basic utilities and foundational features (v0.5.x - v0.7.x)
371
+ - **2023**: Major development with typed builtins and code quality (v0.8.x - v0.9.x)
372
+ - **2024**: Mature library with async support and advanced features (v0.9.x - v1.0.x)
373
+ - **2025**: Production-ready with database abstractions and enterprise features (v1.0.x+)
374
+
375
+ ## 🤝 Contributing
376
+
377
+ Feel free to use, contribute, and improve this code! The project welcomes:
378
+
379
+ - Bug reports and feature requests
380
+ - Code contributions and improvements
381
+ - Documentation enhancements
382
+ - Test coverage improvements
383
+
384
+ ## 📄 License
385
+
386
+ This project is licensed under the terms specified in the [LICENSE](./LICENSE) file.
387
+
388
+ ---
389
+
390
+ **Built with ❤️ for the Python community**