python-base-toolkit 1.0.0__py3-none-any.whl → 1.0.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.
@@ -21,6 +21,10 @@ class EnumMixin:
21
21
  def to_dict(cls: type[E]) -> dict:
22
22
  return {member.name: member.value for member in cls}
23
23
 
24
+ @classmethod
25
+ def to_json(cls) -> str:
26
+ return json.dumps(cls.to_dict())
27
+
24
28
  @classmethod
25
29
  def names(cls: type[E]) -> list[str]:
26
30
  return [c.name for c in cls]
@@ -41,10 +45,6 @@ class EnumMixin:
41
45
  def has_value(cls: type[E], value: Any) -> bool:
42
46
  return any(member.value == value for member in cls)
43
47
 
44
- @classmethod
45
- def to_json(cls) -> str:
46
- return json.dumps(cls.to_dict())
47
-
48
48
 
49
49
  class BaseEnum(EnumMixin, Enum):
50
50
  pass
@@ -0,0 +1,38 @@
1
+ from typing import Any, TypeVar
2
+ from pydantic import BaseModel
3
+
4
+ T = TypeVar("T", bound="PydanticMixin")
5
+
6
+
7
+ class BasePydanticModel(BaseModel):
8
+ """Mixin to add Enum-like utility methods to Pydantic BaseModels."""
9
+
10
+ def __str__(self) -> str:
11
+ return f"{self.__class__.__name__}({self.model_dump()})"
12
+
13
+ def to_dict(self, **kwargs) -> dict[str, Any]:
14
+ """Wrapper for model_dump."""
15
+ return self.model_dump(**kwargs)
16
+
17
+ def to_json(self, **kwargs) -> str:
18
+ """Wrapper for model_dump_json."""
19
+ return self.model_dump_json(**kwargs)
20
+
21
+ def values(self) -> list[Any]:
22
+ """Returns a list of the current instance's field values."""
23
+ return list(self.model_dump().values())
24
+
25
+ @classmethod
26
+ def field_names(cls) -> list[str]:
27
+ """Returns a list of all field names defined in the model."""
28
+ return list(cls.model_fields.keys())
29
+
30
+ @classmethod
31
+ def has_field(cls, name: str) -> bool:
32
+ """Checks if a field name exists in the model definition."""
33
+ return name in cls.model_fields
34
+
35
+ @classmethod
36
+ def to_schema_dict(cls) -> dict[str, Any]:
37
+ """Returns the JSON schema of the model as a dictionary."""
38
+ return cls.model_json_schema()
@@ -8,11 +8,14 @@ from typing import Any
8
8
 
9
9
  import pandas as pd
10
10
  from custom_python_logger import get_logger
11
+ from pydantic import BaseModel
11
12
 
12
13
  logger = get_logger(__name__)
13
14
 
14
15
 
15
16
  def default_serialize(obj: object) -> object:
17
+ if isinstance(obj, BaseModel):
18
+ return obj.model_dump()
16
19
  if isinstance(obj, type):
17
20
  return obj.__name__
18
21
  if is_dataclass(obj) and not isinstance(obj, type):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-base-toolkit
3
- Version: 1.0.0
3
+ Version: 1.0.2
4
4
  Summary: A Python package for managing pytest plugins.
5
5
  Author: Avi Zaguri
6
6
  License: MIT
@@ -22,6 +22,7 @@ Requires-Dist: custom-python-logger>=2.0.11
22
22
  Requires-Dist: pandas>=2.3.3
23
23
  Requires-Dist: pathlib>=1.0.1
24
24
  Requires-Dist: pre-commit>=4.5.0
25
+ Requires-Dist: pydantic>=2.12.5
25
26
  Requires-Dist: pyfiglet>=1.0.4
26
27
  Requires-Dist: python-dotenv>=1.2.1
27
28
  Requires-Dist: pyyaml>=6.0.3
@@ -1,6 +1,7 @@
1
1
  python_base_toolkit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  python_base_toolkit/base_structures/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- python_base_toolkit/base_structures/base_enum.py,sha256=AzVRP8X6W1M2GoYQD3Cm9hpZE-uGnu9YoY9wX9WuFI8,1324
3
+ python_base_toolkit/base_structures/base_enum.py,sha256=pnKIBvGGudkwAbbE7C2dITVdZGclXWOvvVuat3erLMo,1324
4
+ python_base_toolkit/base_structures/base_pydantic_model.py,sha256=kS_cXzlXFxJUbMnxANqSvxiRo0hfp0575KHTw1RP2t0,1239
4
5
  python_base_toolkit/ci/task_files/default.yml,sha256=7NKbXXZP366t-K34MfRj1XJqhhm19YaRpraV1Na4c90,145
5
6
  python_base_toolkit/ci/task_files/dependencies.yml,sha256=jqdNAugfDWoiH7YDBD-5QWMX9z4tZkSGGV9PNp6wpFA,891
6
7
  python_base_toolkit/ci/task_files/deploy.yml,sha256=uKvRJjNImWGPk_xqKV08HlIhDoPepEvf5M54l7Bk_6I,537
@@ -22,7 +23,7 @@ python_base_toolkit/instances/instance_manager.py,sha256=iq72kcPlbc7-AQTuKcBOeqK
22
23
  python_base_toolkit/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
24
  python_base_toolkit/scripts/remove_build_files.py,sha256=461h7BkuwhaCBK17fbxDc3n_nQhL5aCXm3VP52s8sW8,694
24
25
  python_base_toolkit/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- python_base_toolkit/utils/data_serialization.py,sha256=Xf_JTMQPAQfCDM4b0CJxHK7CjmbmVassYViDa65B97A,1197
26
+ python_base_toolkit/utils/data_serialization.py,sha256=Wwi9DQfymNgPj3_fJDUpKoA6U-BE8cJyf1-3qLD7ngE,1295
26
27
  python_base_toolkit/utils/date_time.py,sha256=U1P_8qPnEQzI4DguHVEofYLzlyuWfK7L6VsOKPbMa7c,429
27
28
  python_base_toolkit/utils/execute.py,sha256=6QYQWd1Z15Ofb4gcAtXCx90l1D-REwTWDZNybU6OibM,1560
28
29
  python_base_toolkit/utils/file_utils.py,sha256=XGiFocSNpb77GeX_hEuR_7juNsSwA-RikpH1CvEG4TM,8793
@@ -35,8 +36,8 @@ python_base_toolkit/utils/pycache.py,sha256=X-pWRjAd2xcBtMkcyCuKz34SbHWc2leBHBIj
35
36
  python_base_toolkit/utils/random_utils.py,sha256=gTH6k1MKKGNZvBTLc5H-eSmtEGvXEdLqtzXN9aHuu-A,2730
36
37
  python_base_toolkit/utils/shorten_url.py,sha256=zsyW3wloFJdVb9s3fhR-olL6ekT03FDlFm2xbFY4viw,359
37
38
  python_base_toolkit/utils/venv_details.py,sha256=d1WlZr1LuWz2SXdFP0Hqh6VHXXXSIuXB0oTmWXJrGqM,210
38
- python_base_toolkit-1.0.0.dist-info/licenses/LICENSE,sha256=cSikHY6SZFsPZSBizCDAJ0-Bjjzxt-JtX6TVbKxwimo,1067
39
- python_base_toolkit-1.0.0.dist-info/METADATA,sha256=hTpBVqTsaFCPiy520S95ZOfGD-3IACgGqPrApuJAkfI,2963
40
- python_base_toolkit-1.0.0.dist-info/WHEEL,sha256=YLJXdYXQ2FQ0Uqn2J-6iEIC-3iOey8lH3xCtvFLkd8Q,91
41
- python_base_toolkit-1.0.0.dist-info/top_level.txt,sha256=I9kK6FGKq_6z3aGySoWamY68GRgg0xsL6sS-uyaxJ2k,20
42
- python_base_toolkit-1.0.0.dist-info/RECORD,,
39
+ python_base_toolkit-1.0.2.dist-info/licenses/LICENSE,sha256=cSikHY6SZFsPZSBizCDAJ0-Bjjzxt-JtX6TVbKxwimo,1067
40
+ python_base_toolkit-1.0.2.dist-info/METADATA,sha256=Xbb2WDCzDa-FGH6tRZA9kDm6uXEgGmMVSB3Mss1G6CU,2995
41
+ python_base_toolkit-1.0.2.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
42
+ python_base_toolkit-1.0.2.dist-info/top_level.txt,sha256=I9kK6FGKq_6z3aGySoWamY68GRgg0xsL6sS-uyaxJ2k,20
43
+ python_base_toolkit-1.0.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (81.0.0)
2
+ Generator: setuptools (82.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5