data-sitter 0.1.2__tar.gz → 0.1.3__tar.gz

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 (32) hide show
  1. {data_sitter-0.1.2 → data_sitter-0.1.3}/PKG-INFO +1 -1
  2. {data_sitter-0.1.2 → data_sitter-0.1.3}/README.md +1 -1
  3. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/Contract.py +7 -3
  4. data_sitter-0.1.3/data_sitter/Validation.py +30 -0
  5. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/cli.py +1 -1
  6. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter.egg-info/PKG-INFO +1 -1
  7. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter.egg-info/SOURCES.txt +1 -0
  8. {data_sitter-0.1.2 → data_sitter-0.1.3}/pyproject.toml +1 -1
  9. {data_sitter-0.1.2 → data_sitter-0.1.3}/setup.py +1 -1
  10. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/FieldResolver.py +0 -0
  11. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/__init__.py +0 -0
  12. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/field_types/BaseField.py +0 -0
  13. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/field_types/FloatField.py +0 -0
  14. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/field_types/IntegerField.py +0 -0
  15. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/field_types/NumericField.py +0 -0
  16. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/field_types/StringField.py +0 -0
  17. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/field_types/__init__.py +0 -0
  18. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/rules/MatchedRule.py +0 -0
  19. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/rules/Parser/RuleParser.py +0 -0
  20. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/rules/Parser/__init__.py +0 -0
  21. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/rules/Parser/alias_parameters_parser.py +0 -0
  22. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/rules/Parser/parser_utils.py +0 -0
  23. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/rules/Rule.py +0 -0
  24. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/rules/RuleRegistry.py +0 -0
  25. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/rules/__init__.py +0 -0
  26. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/utils/__init__.py +0 -0
  27. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter/utils/logger_config.py +0 -0
  28. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter.egg-info/dependency_links.txt +0 -0
  29. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter.egg-info/entry_points.txt +0 -0
  30. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter.egg-info/requires.txt +0 -0
  31. {data_sitter-0.1.2 → data_sitter-0.1.3}/data_sitter.egg-info/top_level.txt +0 -0
  32. {data_sitter-0.1.2 → data_sitter-0.1.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: data-sitter
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A Python library that reads data contracts and generates Pydantic models for seamless data validation.
5
5
  Author-email: Lázaro Pereira Candea <lazaro@candea.es>
6
6
  Requires-Dist: python-dotenv==1.0.1
@@ -48,7 +48,7 @@ contract_dict = {
48
48
  }
49
49
 
50
50
  contract = Contract.from_dict(contract_dict)
51
- pydantic_contract = contract.get_pydantic_model()
51
+ pydantic_contract = contract.pydantic_model
52
52
  ```
53
53
 
54
54
  ### Using Rule References
@@ -3,6 +3,7 @@ from functools import cached_property
3
3
 
4
4
  from pydantic import BaseModel
5
5
 
6
+ from .Validation import Validation
6
7
  from .field_types import BaseField
7
8
  from .FieldResolver import FieldResolver
8
9
  from .rules import MatchedRule, RuleRegistry, RuleParser
@@ -68,10 +69,13 @@ class Contract:
68
69
  return rules
69
70
 
70
71
  def model_validate(self, item: dict):
71
- pydantic_model = self.get_pydantic_model()
72
- return pydantic_model.model_validate(item).model_dump()
72
+ return self.pydantic_model.model_validate(item).model_dump()
73
73
 
74
- def get_pydantic_model(self) -> BaseModel:
74
+ def validate(self, item: dict) -> Validation:
75
+ return Validation.validate(self.pydantic_model, item)
76
+
77
+ @cached_property
78
+ def pydantic_model(self) -> BaseModel:
75
79
  return type(self.name, (BaseModel,), {
76
80
  "__annotations__": {
77
81
  field_name: field_validator.get_annotation()
@@ -0,0 +1,30 @@
1
+
2
+ from collections import defaultdict
3
+ from typing import Any, Dict, List, Type
4
+
5
+ from pydantic import BaseModel, ValidationError
6
+
7
+
8
+ class Validation():
9
+ row: Dict[str, Any]
10
+ errors: Dict[str, List[str]]
11
+
12
+ def __init__(self, row: dict, errors: dict = None):
13
+ self.row = row
14
+ self.errors = errors or {}
15
+
16
+ def to_dict(self) -> dict:
17
+ return {"row": self.row, "errors": self.errors}
18
+
19
+ @classmethod
20
+ def validate(cls, model: Type[BaseModel], item: dict) -> "Validation":
21
+ try:
22
+ row = model(**item) # Validate the row
23
+ return Validation(row=row.model_dump())
24
+ except ValidationError as e:
25
+ errors = defaultdict(list)
26
+ for error in e.errors():
27
+ field = error['loc'][0] # Extract the field name
28
+ msg = error['msg']
29
+ errors[field].append(msg)
30
+ return Validation(row=item, errors=dict(errors))
@@ -23,7 +23,7 @@ def main():
23
23
  contract_path = Path(args.contract)
24
24
  contract_dict = json.loads(contract_path.read_text(encoding))
25
25
  contract = Contract.from_dict(contract_dict)
26
- pydantic_contract = contract.get_pydantic_model()
26
+ pydantic_contract = contract.pydantic_model
27
27
 
28
28
  if file_path.suffix == '.csv':
29
29
  with open(file_path, encoding=encoding) as f:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: data-sitter
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: A Python library that reads data contracts and generates Pydantic models for seamless data validation.
5
5
  Author-email: Lázaro Pereira Candea <lazaro@candea.es>
6
6
  Requires-Dist: python-dotenv==1.0.1
@@ -3,6 +3,7 @@ pyproject.toml
3
3
  setup.py
4
4
  data_sitter/Contract.py
5
5
  data_sitter/FieldResolver.py
6
+ data_sitter/Validation.py
6
7
  data_sitter/__init__.py
7
8
  data_sitter/cli.py
8
9
  data_sitter.egg-info/PKG-INFO
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = 'data-sitter'
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
  description = "A Python library that reads data contracts and generates Pydantic models for seamless data validation."
9
9
  authors = [
10
10
  {name = 'Lázaro Pereira Candea', email = 'lazaro@candea.es'},
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
3
3
 
4
4
  setup(
5
5
  name='data-sitter',
6
- version='0.1.2',
6
+ version='0.1.3',
7
7
  packages=find_packages(),
8
8
  install_requires=[
9
9
  # Keep this in sync with pyproject.toml
File without changes