Skill Tracer
Skills › Scientific Agent Skills › liteparse › api_reference.md

api_reference.md

229 lines · skills/liteparse/references/api_reference.md at 5f2bc03

Open on GitHub
1# LiteParse API Reference
2
3Targets **liteparse 2.15.0** (Python), **@llamaindex/liteparse 2.15.0** (Node 18+), and Rust crate `liteparse = "2.15.0"`. Reviewed 2026-10-01. Python examples were exercised with synthetic PDF/PNG fixtures; Node/Rust snippets are illustrative and source-checked, not executed.
4

LiteParse API Reference

Targets liteparse 2.15.0 (Python), @llamaindex/liteparse 2.15.0 (Node 18+), and Rust crate liteparse = "2.15.0". Reviewed 2026-10-01. Python examples were exercised with synthetic PDF/PNG fixtures; Node/Rust snippets are illustrative and source-checked, not executed.

Raw lines 1 to 4
5## Python: `LiteParse`
6
7```python
8from liteparse import LiteParse, ParseResult, ParsedPage, TextItem, ScreenshotResult, search_items
9```

Python: LiteParse

from liteparse import LiteParse, ParseResult, ParsedPage, TextItem, ScreenshotResult, search_items
Raw lines 5 to 10
11### Constructor options
13| Python parameter | Type | Default | Description |
14|------------------|------|---------|-------------|
15| `ocr_enabled` | bool | `True` | Run OCR on regions needing it |
16| `ocr_language` | str | `"eng"` | Tesseract language code |
17| `ocr_server_url` | str \| None | `None` | Complete HTTP OCR endpoint; no suffix appended |
18| `ocr_server_headers` | dict[str, str] \| None | `None` | Server-specific headers, including authentication |
19| `tessdata_path` | str \| None | `None` | Path to tessdata directory |
20| `max_pages` | int | `1000` | Maximum pages to parse |
21| `target_pages` | str \| None | `None` | e.g. `"1-5,10,15-20"` |
22| `dpi` | float | `150` | Render DPI (OCR / screenshots) |
23| `output_format` | str | `"json"` | `"json"`, `"text"` or `"markdown"`; Markdown is returned in `result.text` |
24| `preserve_very_small_text` | bool | `False` | Keep very small text runs |
25| `password` | str \| None | `None` | Encrypted PDF password |
26| `quiet` | bool | `False` | Suppress progress output |
27| `num_workers` | int | CPU−1 | Concurrent OCR workers |
29Other useful constructor options:
31| Parameter | Default | Meaning |
32|---|---|---|
33| `image_mode` | `"placeholder"` | Markdown image presentation: `placeholder`, `off`, `embed` |
34| `extract_images` | `False` | Extract embedded image bytes/metadata |
35| `image_output_dir` | `None` | Save extracted images; requires `extract_images=True` |
36| `extract_links` | `True` | Markdown hyperlink syntax |
37| `keep_headers_footers` | `False` | Retain repeated headers/footers in Markdown |
38| `extract_screenshots` | `False` | Return PNG bytes for parsed pages |
39| `continue_on_page_error` | `False` | Return partial pages and `page_errors` after page-level errors |
40| `extract_blocks` | `False` | Reading-order layout blocks with boxes |
41| `emit_word_boxes` | `False` | Populate `TextItem.words` with word boxes |
42| `ocr_failure_fatal` | `True` | Fail when all OCR fails and a sparse page depends on it |
43| `pool_size` | `None` | Persistent subprocess count for whole-document parsing |
44| `parse_timeout` | `None` | Hard deadline in seconds; requires `pool_size` |
46`extract_annotations`, `extract_form_fields`, `extract_structure_tree`,
47`extract_vector_graphics`, `extract_text_metadata`, and `include_complexity`
48are opt-in booleans, all false by default. Use the
49[released constructor](https://github.com/run-llama/liteparse/blob/d3a79177b9e9e570f8c2d9878ace601445fdaf76/packages/python/liteparse/parser.py)
50for advanced crop/orientation/document metadata options; do not assume every
51API option has a CLI flag.

Constructor options

Python parameterTypeDefaultDescription
ocr_enabledboolTrueRun OCR on regions needing it
ocr_languagestr"eng"Tesseract language code
ocr_server_urlstr \NoneNoneComplete HTTP OCR endpoint; no suffix appended
ocr_server_headersdict[str, str] \NoneNoneServer-specific headers, including authentication
tessdata_pathstr \NoneNonePath to tessdata directory
max_pagesint1000Maximum pages to parse
target_pagesstr \NoneNonee.g. "1-5,10,15-20"
dpifloat150Render DPI (OCR / screenshots)
output_formatstr"json""json", "text" or "markdown"; Markdown is returned in result.text
preserve_very_small_textboolFalseKeep very small text runs
passwordstr \NoneNoneEncrypted PDF password
quietboolFalseSuppress progress output
num_workersintCPU−1Concurrent OCR workers

Other useful constructor options:

ParameterDefaultMeaning
image_mode"placeholder"Markdown image presentation: placeholder, off, embed
extract_imagesFalseExtract embedded image bytes/metadata
image_output_dirNoneSave extracted images; requires extract_images=True
extract_linksTrueMarkdown hyperlink syntax
keep_headers_footersFalseRetain repeated headers/footers in Markdown
extract_screenshotsFalseReturn PNG bytes for parsed pages
continue_on_page_errorFalseReturn partial pages and page_errors after page-level errors
extract_blocksFalseReading-order layout blocks with boxes
emit_word_boxesFalsePopulate TextItem.words with word boxes
ocr_failure_fatalTrueFail when all OCR fails and a sparse page depends on it
pool_sizeNonePersistent subprocess count for whole-document parsing
parse_timeoutNoneHard deadline in seconds; requires pool_size

extract_annotations, extract_form_fields, extract_structure_tree, extract_vector_graphics, extract_text_metadata, and include_complexity are opt-in booleans, all false by default. Use the released constructor for advanced crop/orientation/document metadata options; do not assume every API option has a CLI flag.

Raw lines 11 to 52
53### `parse(file_data)`
55**Input:** file path (`str` / `Path`) or raw document bytes (`bytes`). PDF bytes are the simplest path; supported binary formats are detected for conversion. Named files are preferable when a format is ambiguous.
57**Returns:** `ParseResult`
59```python
60@dataclass
61class ParseResult:
62 pages: List[ParsedPage]
63 text: str # document text, or Markdown in markdown mode
64 total_pages: int # source count before page selection/cap
65 page_errors: List[PageError] # page_number, message; inspect for partial output
67 @property
68 def num_pages(self) -> int: ... # len(pages), not source total
70 def get_page(self, page_num: int) -> Optional[ParsedPage]: ... # 1-indexed
71```
73```python
74@dataclass
75class ParsedPage:
76 page_num: int
77 width: float
78 height: float
79 text: str
80 text_items: List[TextItem]
81 markdown: str
82 page_label: Optional[str]
83```
85```python
86@dataclass
87class TextItem:
88 text: str
89 x: float
90 y: float
91 width: float
92 height: float
93 font_name: Optional[str]
94 font_size: Optional[float]
95 confidence: Optional[float] # 0.0–1.0 when from OCR
96```
98The type sketches show commonly used fields, not complete constructors.
100**Raises:** `FileNotFoundError`, `ParseError`, and `ParseTimeoutError` in pool mode.

parse(file_data)

Input: file path (str / Path) or raw document bytes (bytes). PDF bytes are the simplest path; supported binary formats are detected for conversion. Named files are preferable when a format is ambiguous.

Returns: ParseResult

@dataclass
class ParseResult:
    pages: List[ParsedPage]
    text: str              # document text, or Markdown in markdown mode
    total_pages: int       # source count before page selection/cap
    page_errors: List[PageError]  # page_number, message; inspect for partial output

    @property
    def num_pages(self) -> int: ...  # len(pages), not source total

    def get_page(self, page_num: int) -> Optional[ParsedPage]: ...  # 1-indexed
@dataclass
class ParsedPage:
    page_num: int
    width: float
    height: float
    text: str
    text_items: List[TextItem]
    markdown: str
    page_label: Optional[str]
@dataclass
class TextItem:
    text: str
    x: float
    y: float
    width: float
    height: float
    font_name: Optional[str]
    font_size: Optional[float]
    confidence: Optional[float]   # 0.0–1.0 when from OCR

The type sketches show commonly used fields, not complete constructors.

Raises: FileNotFoundError, ParseError, and ParseTimeoutError in pool mode.

Raw lines 53 to 101
102### `screenshot(file_path, *, page_numbers=None)`
104**Input:** path to document (PDF or convertible format).
106**Returns:** `List[ScreenshotResult]` with PNG bytes.
108```python
109@dataclass
110class ScreenshotResult:
111 page_num: int
112 width: int
113 height: int
114 image_bytes: bytes
115```
117Non-PDF formats convert through LibreOffice (Office) or bundled image converters. Screenshots return pixel dimensions; text boxes use page coordinates. See `output_formats.md` before overlaying them.

screenshot(file_path, *, page_numbers=None)

Input: path to document (PDF or convertible format).

Returns: List[ScreenshotResult] with PNG bytes.

@dataclass
class ScreenshotResult:
    page_num: int
    width: int
    height: int
    image_bytes: bytes

Non-PDF formats convert through LibreOffice (Office) or bundled image converters. Screenshots return pixel dimensions; text boxes use page coordinates. See output_formats.md before overlaying them.

Raw lines 102 to 118
119### `get_config()`
121Returns resolved `LiteParseConfig` dataclass.

get_config()

Returns resolved LiteParseConfig dataclass.

Raw lines 119 to 122
123### `search_items(items, phrase, *, case_sensitive=False)`
125Search a list of `TextItem` for a phrase that may span multiple items. Returns merged `TextItem` objects with combined bounding boxes.
127```python
128from liteparse import search_items
130matches = search_items(page.text_items, "Figure 1", case_sensitive=False)
131```
133---

search_items(items, phrase, *, case_sensitive=False)

Search a list of TextItem for a phrase that may span multiple items. Returns merged TextItem objects with combined bounding boxes.

from liteparse import search_items

matches = search_items(page.text_items, "Figure 1", case_sensitive=False)

Raw lines 123 to 134
135## Process pools and page integrity
137In-process PDFium parsing serializes under a process-global lock. `num_workers`
138controls OCR concurrency, not parallel PDF parses. A pool provides separate
139processes and `parse_timeout` kills/replaces a timed-out worker:
141```python
142from liteparse import LiteParse
144with LiteParse(ocr_enabled=False, pool_size=2, parse_timeout=30, quiet=True) as parser:
145 result = parser.parse("document.pdf")
146 if result.page_errors:
147 raise RuntimeError(f"Partial document: {result.page_errors}")
148```
150A page cap or explicit `target_pages` is an intentional subset: compare actual
151page numbers with the requested range and `result.total_pages`. A nonempty
152result is not proof every page was ingested. `is_complex(path_or_bytes)` returns
153per-page `needs_ocr`/`reasons` heuristics; it does not certify transcription quality.
155---

Process pools and page integrity

In-process PDFium parsing serializes under a process-global lock. num_workers controls OCR concurrency, not parallel PDF parses. A pool provides separate processes and parse_timeout kills/replaces a timed-out worker:

from liteparse import LiteParse

with LiteParse(ocr_enabled=False, pool_size=2, parse_timeout=30, quiet=True) as parser:
    result = parser.parse("document.pdf")
    if result.page_errors:
        raise RuntimeError(f"Partial document: {result.page_errors}")

A page cap or explicit target_pages is an intentional subset: compare actual page numbers with the requested range and result.total_pages. A nonempty result is not proof every page was ingested. is_complex(path_or_bytes) returns per-page needs_ocr/reasons heuristics; it does not certify transcription quality.


Raw lines 135 to 156
157## TypeScript / Node.js
159```typescript
160import { LiteParse } from '@llamaindex/liteparse';
162const parser = new LiteParse();
163const result = await parser.parse('document.pdf');
164console.log(result.text);
166for (const page of result.pages) {
167 console.log(`Page ${page.pageNum}: ${page.textItems.length} items`);
169```

TypeScript / Node.js

import { LiteParse } from '@llamaindex/liteparse';

const parser = new LiteParse();
const result = await parser.parse('document.pdf');
console.log(result.text);

for (const page of result.pages) {
  console.log(`Page ${page.pageNum}: ${page.textItems.length} items`);
}
Raw lines 157 to 170
171### Constructor options (camelCase)
173| TypeScript | Python equivalent |
174|------------|-------------------|
175| `ocrEnabled` | `ocr_enabled` |
176| `ocrLanguage` | `ocr_language` |
177| `ocrServerUrl` | `ocr_server_url` |
178| `ocrServerHeaders` | `ocr_server_headers` |
179| `outputFormat` | `output_format` |
180| `extractImages` / `imageOutputDir` | `extract_images` / `image_output_dir` |
181| `poolSize` | `pool_size` |
182| `parseTimeoutMs` | `parse_timeout` (Node milliseconds, Python seconds) |
183| `tessdataPath` | `tessdata_path` |
184| `maxPages` | `max_pages` |
185| `targetPages` | `target_pages` |
186| `dpi` | `dpi` |
187| `preserveVerySmallText` | `preserve_very_small_text` |
188| `password` | `password` |
189| `quiet` | `quiet` |
190| `numWorkers` | `num_workers` |

Constructor options (camelCase)

TypeScriptPython equivalent
ocrEnabledocr_enabled
ocrLanguageocr_language
ocrServerUrlocr_server_url
ocrServerHeadersocr_server_headers
outputFormatoutput_format
extractImages / imageOutputDirextract_images / image_output_dir
poolSizepool_size
parseTimeoutMsparse_timeout (Node milliseconds, Python seconds)
tessdataPathtessdata_path
maxPagesmax_pages
targetPagestarget_pages
dpidpi
preserveVerySmallTextpreserve_very_small_text
passwordpassword
quietquiet
numWorkersnum_workers
Raw lines 171 to 191
192### Parse from bytes
194```typescript
195import { readFile } from 'fs/promises';
197const pdfBytes = await readFile('document.pdf');
198const result = await parser.parse(pdfBytes);
199```

Parse from bytes

import { readFile } from 'fs/promises';

const pdfBytes = await readFile('document.pdf');
const result = await parser.parse(pdfBytes);
Raw lines 192 to 200
201### Screenshots
203```typescript
204const screenshots = parser.screenshot('document.pdf', [1, 2, 3]);
205for (const s of screenshots) {
206 // s.pageNum, s.width, s.height, s.imageBuffer (PNG)
208```
210Install: `npm i @llamaindex/liteparse@2.15.0` (includes `lit` CLI).
212Browser/edge uses the separate `@llamaindex/liteparse-wasm` package; native examples are not browser APIs. Consult its [WASM README](https://github.com/run-llama/liteparse/tree/main/packages/wasm) for runtime-specific requirements (not exercised here).
214---

Screenshots

const screenshots = parser.screenshot('document.pdf', [1, 2, 3]);
for (const s of screenshots) {
  // s.pageNum, s.width, s.height, s.imageBuffer (PNG)
}

Install: npm i @llamaindex/liteparse@2.15.0 (includes lit CLI).

Browser/edge uses the separate @llamaindex/liteparse-wasm package; native examples are not browser APIs. Consult its WASM README for runtime-specific requirements (not exercised here).


Raw lines 201 to 215
216## Rust (library)
218```rust
219use liteparse::{LiteParse, LiteParseConfig};
221let parser = LiteParse::new(LiteParseConfig::default());
222let result = parser.parse("document.pdf").await?;
223```
225Custom OCR: implement `OcrEngine` trait and `.with_ocr_engine(Arc::new(engine))`.
227CLI: `cargo install liteparse`
229Sources: [Python API](https://github.com/run-llama/liteparse/blob/d3a79177b9e9e570f8c2d9878ace601445fdaf76/packages/python/README.md), [Node API](https://github.com/run-llama/liteparse/blob/d3a79177b9e9e570f8c2d9878ace601445fdaf76/packages/node/README.md), [Rust API](https://github.com/run-llama/liteparse/blob/d3a79177b9e9e570f8c2d9878ace601445fdaf76/crates/liteparse/README.md).

Rust (library)

use liteparse::{LiteParse, LiteParseConfig};

let parser = LiteParse::new(LiteParseConfig::default());
let result = parser.parse("document.pdf").await?;

Custom OCR: implement OcrEngine trait and .with_ocr_engine(Arc::new(engine)).

CLI: cargo install liteparse

Sources: Python API, Node API, Rust API.

Raw lines 216 to 229