HowdenParser 5.2.2__tar.gz → 5.2.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.
@@ -1,7 +1,9 @@
1
1
  import os
2
+ import json
2
3
  import logging
3
4
  from pathlib import Path
4
5
  from ..parser import BaseParser
6
+ from typing import Any
5
7
 
6
8
  class LlamaParser(BaseParser, name="llamaparser"):
7
9
  def __init__(self, result_type: str, model: str, parse_mode: str, provider_and_model: str,
@@ -44,8 +46,12 @@ class LlamaParser(BaseParser, name="llamaparser"):
44
46
  raise EnvironmentError("Missing LLAMA-PARSER-API-TOKEN in .env file.")
45
47
 
46
48
  rt = self.result_type
47
- if rt.lower() in ("md", "markdown"):
49
+
50
+ rt_lower = str(rt).lower()
51
+ if rt_lower in ("md", "markdown"):
48
52
  rt = ResultType.MD
53
+ elif rt_lower in ("json", "layout_json", "jsonl"):
54
+ rt = ResultType.JSON
49
55
 
50
56
  # Construct the parser INSIDE the worker thread
51
57
  self._parser = LlamaParse(
@@ -61,7 +67,7 @@ class LlamaParser(BaseParser, name="llamaparser"):
61
67
 
62
68
  logging.info("LlamaParser initialized inside worker thread")
63
69
 
64
- def parse(self, file_path: Path, include_pagenumbers: bool = False) -> str:
70
+ def parse(self, file_path: Path, include_pagenumbers: bool = False) -> Any:
65
71
  # Ensure parser is created inside the thread event loop
66
72
  self._lazy_init()
67
73
 
@@ -79,6 +85,9 @@ class LlamaParser(BaseParser, name="llamaparser"):
79
85
  for idx, page in enumerate(documents.pages, start=1)
80
86
  )
81
87
 
88
+ if self.result_type.lower() in ("json", "layout_json", "jsonl"):
89
+ return documents.model_dump() if hasattr(documents, "model_dump") else documents
90
+
82
91
  return "\n".join(
83
92
  f"<PAGE_NUMBER {idx}>{page.text}</PAGE_NUMBER {idx}>"
84
93
  for idx, page in enumerate(documents.pages, start=1)
@@ -88,4 +97,4 @@ class LlamaParser(BaseParser, name="llamaparser"):
88
97
  return self.parse(file_path)
89
98
 
90
99
  def write_json_hyperparameter(self, folder_file_path: Path) -> None:
91
- self.write_parameters(self._input_params, folder_file_path)
100
+ self.write_parameters(self._input_params, folder_file_path)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HowdenParser
3
- Version: 5.2.2
3
+ Version: 5.2.3
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.2.2"
3
+ version = "5.2.3"
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