HowdenParser 5.1.0__tar.gz → 5.2.0__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.
@@ -3,6 +3,9 @@ import logging
3
3
  import dotenv
4
4
  from typing import overload, Literal
5
5
  from inspect import signature, Signature
6
+ from typing import Any
7
+ import json
8
+ import hashlib
6
9
 
7
10
  dotenv.load_dotenv()
8
11
  logger = logging.getLogger(__name__)
@@ -26,6 +29,30 @@ class BaseParser(ABC):
26
29
  def parse(self, text: str, include_pagenumbers: bool = False):
27
30
  pass
28
31
 
32
+ def make_serializable(self, obj: Any) -> Any:
33
+ if obj is None or isinstance(obj, (str, int, float, bool)):
34
+ return obj
35
+ if isinstance(obj, (list, tuple, set)):
36
+ return [self.make_serializable(v) for v in obj]
37
+ if isinstance(obj, dict):
38
+ return {k: self.make_serializable(v) for k, v in sorted(obj.items())}
39
+ if hasattr(obj, "__dict__"):
40
+ return self.make_serializable(vars(obj))
41
+ return f"{type(obj).__name__}:{repr(obj)}"
42
+
43
+ def compute_hash(self, parameter:dict) -> str:
44
+
45
+ attrs = {
46
+ k: v
47
+ for k, v in parameter.items()
48
+ if k != "hash"
49
+ and not k.startswith("_")
50
+ and k not in ("client", "provider")
51
+ }
52
+ serializable = self.make_serializable(attrs)
53
+ attrs_str = json.dumps(serializable, sort_keys=True, ensure_ascii=True)
54
+ hashed = hashlib.sha256(attrs_str.encode()).hexdigest()[:8]
55
+ return hashed
29
56
 
30
57
  class Parser(BaseParser):
31
58
  """Factory + registry interface for all parsers."""
@@ -9,6 +9,13 @@ class LlamaParser(BaseParser, name="llamaparser"):
9
9
  hide_footers: bool, hide_headers: bool) -> None:
10
10
 
11
11
  super().__init__()
12
+ # Capture only input parameters
13
+ self._input_params = {
14
+ k: v
15
+ for k, v in locals().items()
16
+ if k not in ("self", "__class__", "__len__")
17
+ }
18
+
12
19
  logging.info("Configuring LlamaParser (lazy init enabled)...")
13
20
 
14
21
  # Store configuration only
@@ -20,7 +27,7 @@ class LlamaParser(BaseParser, name="llamaparser"):
20
27
  self.preserve_layout_alignment_across_pages = preserve_layout_alignment_across_pages
21
28
  self.hide_footers = hide_footers
22
29
  self.hide_headers = hide_headers
23
-
30
+ self.hashed = self.compute_hash(self._input_params)
24
31
  # DO NOT CREATE LlamaParse HERE
25
32
  # It creates asyncio objects bound to the wrong loop
26
33
  self._parser = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HowdenParser
3
- Version: 5.1.0
3
+ Version: 5.2.0
4
4
  Summary: A simple configuration manager with Pydantic and JSON export.
5
5
  License: MIT
6
6
  Keywords: config,configuration,pydantic,json
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "HowdenParser"
3
- version = "5.1.0"
3
+ version = "5.2.0"
4
4
  description = "A simple configuration manager with Pydantic and JSON export."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12,<3.14"
File without changes