HowdenParser 5.2.6__tar.gz → 6.0.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.
@@ -96,13 +96,11 @@ class Parser(BaseParser):
96
96
  cls,
97
97
  *,
98
98
  provider_and_model: Literal["llamaparser:"],
99
+ tier: str,
100
+ version: str,
99
101
  result_type: str,
100
- model: str,
101
- parse_mode: str,
102
102
  preserve_layout_alignment_across_pages: bool,
103
- merge_tables_across_pages_in_markdown: bool,
104
- hide_footers: bool,
105
- hide_headers: bool,
103
+ merge_continued_tables: bool,
106
104
  ) -> "LlamaParser": ...
107
105
 
108
106
  @overload
@@ -1,21 +1,17 @@
1
1
  import os
2
- import json
3
2
  import logging
4
3
  from pathlib import Path
5
4
  from ..parser import BaseParser
6
- from typing import Any, Optional
7
- from llama_parse import ResultType
5
+ from typing import Any
8
6
 
9
7
  class LlamaParser(BaseParser, name="llamaparser"):
10
- def __init__(self, result_type: str,
11
- model: str, parse_mode: str,
8
+ def __init__(self,
9
+ result_type: str,
10
+ tier: str, # One of: ["fast", "cost_effective", "agentic", "agentic_plus"]
11
+ version: str, # one of: ["latest","2026-03-12","2026-03-11"...] (many not listed)
12
12
  provider_and_model: str,
13
- merge_tables_across_pages_in_markdown: bool,
13
+ merge_continued_tables: bool,
14
14
  preserve_layout_alignment_across_pages: bool,
15
- hide_footers: bool,
16
- hide_headers: bool,
17
- precise_bounding_box: Optional[bool] = None,
18
- line_level_bounding_box: Optional[bool] = None,
19
15
  ) -> None:
20
16
 
21
17
  super().__init__()
@@ -30,54 +26,39 @@ class LlamaParser(BaseParser, name="llamaparser"):
30
26
 
31
27
  # Store configuration only
32
28
  self.result_type = result_type
33
- self.model = model
34
- self.parse_mode = parse_mode
29
+ self.tier = tier
30
+ self.version = version
35
31
  self.provider_and_model = provider_and_model
36
- self.merge_tables_across_pages_in_markdown = merge_tables_across_pages_in_markdown
32
+ self.merge_continued_tables = merge_continued_tables
37
33
  self.preserve_layout_alignment_across_pages = preserve_layout_alignment_across_pages
38
- self.hide_footers = hide_footers
39
- self.hide_headers = hide_headers
40
- self.precise_bounding_box = precise_bounding_box
41
- self.line_level_bounding_box = line_level_bounding_box
42
34
  self.hashed = self.compute_hash(self._input_params)
43
35
  # DO NOT CREATE LlamaParse HERE
44
36
  # It creates asyncio objects bound to the wrong loop
45
37
  self._parser = None
38
+ self.rt = None
46
39
 
47
40
  def _lazy_init(self):
48
41
  """Initialize LlamaParse inside the worker thread event loop."""
49
42
  if self._parser is not None:
50
43
  return
51
44
 
52
- from llama_parse import LlamaParse, ResultType
45
+ from llama_cloud import LlamaCloud
53
46
 
54
47
  api_key = os.getenv("LLAMA-PARSER-API-TOKEN")
55
48
  if not api_key:
56
49
  raise EnvironmentError("Missing LLAMA-PARSER-API-TOKEN in .env file.")
57
50
 
58
- rt_lower = str(self.result_type).lower()
51
+ rt_lower = str(self.result_type).lower() # Possible values for LlamaCloud expand: ["markdown", "text", "metadata", "items"]
59
52
  if rt_lower in ("md","markdown"):
60
- rt = ResultType.MD
53
+ self.rt = 'markdown'
61
54
  elif rt_lower in ("txt","text"):
62
- rt = ResultType.TXT
55
+ self.rt = 'text'
63
56
  elif rt_lower in ("json"):
64
- rt = ResultType.JSON
57
+ self.rt = 'items'
65
58
  else:
66
59
  raise NotImplementedError(f"Result type {self.result_type} is not supported.")
67
60
 
68
- # Construct the parser INSIDE the worker thread
69
- self._parser = LlamaParse(
70
- api_key=api_key,
71
- result_type=rt,
72
- model=self.model,
73
- parse_mode=self.parse_mode,
74
- merge_tables_across_pages_in_markdown=self.merge_tables_across_pages_in_markdown,
75
- preserve_layout_alignment_across_pages=self.preserve_layout_alignment_across_pages,
76
- hide_footers=self.hide_footers,
77
- hide_headers=self.hide_headers,
78
- precise_bounding_box=self.precise_bounding_box,
79
- line_level_bounding_box=self.line_level_bounding_box,
80
- )
61
+ self._parser = LlamaCloud(api_key=os.getenv("LLAMA-PARSER-API-TOKEN"))
81
62
 
82
63
  logging.info("LlamaParser initialized inside worker thread")
83
64
 
@@ -87,14 +68,31 @@ class LlamaParser(BaseParser, name="llamaparser"):
87
68
  def page_break(text: str, idx: int) -> str:
88
69
  return f"<PAGE_NUMBER {idx}>{text}</PAGE_NUMBER {idx}>"
89
70
 
90
- documents = self._parser.parse(file_path)
91
- if self.result_type in ['md','markdown']:
92
- if include_pagenumbers: return "\n".join(page_break(page.md, idx) for idx, page in enumerate(documents.pages, start=1))
93
- else: return "\n".join(page.md for page in documents.pages)
94
- elif self.result_type in ['txt','text']:
95
- if include_pagenumbers: return "\n".join(page_break(page.text, idx) for idx, page in enumerate(documents.pages, start=1))
96
- else: return "\n".join(page.text for page in documents.pages)
97
- elif self.result_type.lower() == 'json':
71
+ documents = self._parser.parsing.parse(
72
+ upload_file=file_path,
73
+ tier=self.tier,
74
+ version=self.version,
75
+ output_options={
76
+ "markdown": {
77
+ "tables": {
78
+ "output_tables_as_markdown": True,
79
+ "merge_continued_tables": self.merge_continued_tables,
80
+ }
81
+ },
82
+ "spatial_text": {
83
+ "preserve_layout_alignment_across_pages": self.preserve_layout_alignment_across_pages,
84
+ }
85
+ },
86
+ expand=[self.rt],
87
+ )
88
+
89
+ if self.rt == 'markdown':
90
+ if include_pagenumbers: return "\n".join(page_break(page.markdown, idx) for idx, page in enumerate(documents.markdown.pages, start=1))
91
+ else: return "\n".join(page.markdown for page in documents.markdown.pages)
92
+ elif self.rt == 'text':
93
+ if include_pagenumbers: return "\n".join(page_break(page.text, idx) for idx, page in enumerate(documents.text.pages, start=1))
94
+ else: return "\n".join(page.text for page in documents.text.pages)
95
+ elif self.rt == 'items':
98
96
  return documents.model_dump()
99
97
  else:
100
98
  raise NotImplementedError(f"Result type {self.result_type} is not supported.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: HowdenParser
3
- Version: 5.2.6
3
+ Version: 6.0.0
4
4
  Summary: A simple configuration manager with Pydantic and JSON export.
5
5
  License: MIT
6
6
  Keywords: config,configuration,pydantic,json
@@ -11,8 +11,9 @@ Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.12
13
13
  Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: dotenv (>=0.9.9,<0.10.0)
14
15
  Requires-Dist: langchain (>=1.1.3,<2.0.0)
15
- Requires-Dist: llama-parse (>=0.6.58,<0.7.0)
16
+ Requires-Dist: llama-cloud (>=1.0)
16
17
  Requires-Dist: mistralai (>=1.9.3,<2.0.0)
17
18
  Requires-Dist: pdf2image (>=1.17.0,<2.0.0)
18
19
  Requires-Dist: pypdf2 (>=3.0.1,<4.0.0)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "HowdenParser"
3
- version = "5.2.6"
3
+ version = "6.0.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"
@@ -18,12 +18,13 @@ repository = "https://github.com/yourusername/config"
18
18
  documentation = "https://github.com/yourusername/config"
19
19
  dependencies = [
20
20
  "mistralai (>=1.9.3,<2.0.0)",
21
- "llama-parse (>=0.6.58,<0.7.0)",
21
+ "llama-cloud (>=1.0)",
22
22
  "pypdf2 (>=3.0.1,<4.0.0)",
23
23
  "pdf2image (>=1.17.0,<2.0.0)",
24
24
  "langchain (>=1.1.3,<2.0.0)",
25
25
  "pytest (>=9.0.2,<10.0.0)",
26
26
  "tomli-w (>=1.2.0,<2.0.0)",
27
+ "dotenv (>=0.9.9,<0.10.0)",
27
28
  ]
28
29
 
29
30
  [project.license]
File without changes