datalab-python-sdk 0.4.0__py3-none-any.whl → 0.6.0__py3-none-any.whl
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.
- datalab_python_sdk-0.6.0.dist-info/METADATA +151 -0
- datalab_python_sdk-0.6.0.dist-info/RECORD +12 -0
- {datalab_python_sdk-0.4.0.dist-info → datalab_python_sdk-0.6.0.dist-info}/WHEEL +1 -1
- datalab_sdk/__init__.py +47 -1
- datalab_sdk/cli.py +515 -71
- datalab_sdk/client.py +1810 -393
- datalab_sdk/exceptions.py +76 -4
- datalab_sdk/models.py +463 -28
- datalab_sdk/settings.py +12 -2
- datalab_python_sdk-0.4.0.dist-info/METADATA +0 -80
- datalab_python_sdk-0.4.0.dist-info/RECORD +0 -12
- {datalab_python_sdk-0.4.0.dist-info → datalab_python_sdk-0.6.0.dist-info}/entry_points.txt +0 -0
- {datalab_python_sdk-0.4.0.dist-info → datalab_python_sdk-0.6.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datalab-python-sdk
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: SDK for the Datalab document intelligence API
|
|
5
|
+
Project-URL: Homepage, https://www.datalab.to
|
|
6
|
+
Project-URL: Documentation, https://documentation.datalab.to
|
|
7
|
+
Project-URL: Repository, https://github.com/datalab-to/sdk
|
|
8
|
+
Author-email: Datalab Team <hi@datalab.to>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,datalab,document-intelligence,sdk
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Requires-Dist: aiohttp>=3.12.14
|
|
14
|
+
Requires-Dist: click>=8.2.1
|
|
15
|
+
Requires-Dist: ijson>=3.3.0
|
|
16
|
+
Requires-Dist: pydantic-settings>=2.10.1
|
|
17
|
+
Requires-Dist: pydantic>=2.11.7
|
|
18
|
+
Requires-Dist: tenacity>=8.2.3
|
|
19
|
+
Requires-Dist: tqdm>=4.66.0
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# Datalab SDK
|
|
23
|
+
|
|
24
|
+
A Python SDK for the [Datalab API](https://www.datalab.to/?utm_source=gh-sdk) - it turns documents into verifiable knowledge your agents act on. Datalab is the team behind [Chandra](https://github.com/datalab-to/chandra), [marker](https://github.com/datalab-to/marker), [surya](https://github.com/datalab-to/surya), and [lift](https://github.com/datalab-to/lift).
|
|
25
|
+
|
|
26
|
+
See the full documentation at [https://documentation.datalab.to](https://documentation.datalab.to).
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install datalab-python-sdk
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
### Authentication
|
|
37
|
+
|
|
38
|
+
[Sign up](https://www.datalab.to/?utm_source=gh-sdk), then get your API key from [https://www.datalab.to/app/keys](https://www.datalab.to/app/keys):
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
export DATALAB_API_KEY="your_api_key_here"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Basic Usage
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from datalab_sdk import DatalabClient
|
|
48
|
+
|
|
49
|
+
client = DatalabClient() # use env var from above, or pass api_key="your_api_key_here"
|
|
50
|
+
|
|
51
|
+
# Convert PDF to markdown
|
|
52
|
+
result = client.convert("document.pdf")
|
|
53
|
+
print(result.markdown)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`AsyncDatalabClient` has the same methods as `DatalabClient`, as coroutines.
|
|
57
|
+
|
|
58
|
+
## Conversion options
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from datalab_sdk import ConvertOptions
|
|
62
|
+
|
|
63
|
+
options = ConvertOptions(
|
|
64
|
+
mode="balanced", # lite, fast, balanced, accurate (SDK default: fast)
|
|
65
|
+
output_format="markdown,html", # markdown, html, json, chunks (comma-separated)
|
|
66
|
+
page_range="0-4",
|
|
67
|
+
extras="chart_understanding,table_cell_bboxes",
|
|
68
|
+
merge_cross_page=True, # merge tables, paragraphs and lists split across pages
|
|
69
|
+
word_bboxes=True, # per-word bounding boxes in the HTML output
|
|
70
|
+
save_checkpoint=True, # reuse the parse in extract() or segment()
|
|
71
|
+
)
|
|
72
|
+
result = client.convert("document.pdf", options=options)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Other options include `paginate`, `add_block_ids`, `disable_html_prettify`, `exact_transcription`, `token_efficient_markdown`, `include_markdown_in_chunks`, `disable_image_extraction`, `disable_image_captions`, `fence_synthetic_captions`, `keep_spreadsheet_formatting`, `keep_pageheader_in_output`, `keep_pagefooter_in_output`, `additional_config`, `webhook_url`, `skip_cache` and `processing_location`. The [API reference](https://documentation.datalab.to/api-reference/convert-document) describes each option.
|
|
76
|
+
|
|
77
|
+
## Structured extraction
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from datalab_sdk import ExtractOptions
|
|
81
|
+
|
|
82
|
+
result = client.extract(
|
|
83
|
+
"invoice.pdf",
|
|
84
|
+
options=ExtractOptions(
|
|
85
|
+
page_schema='{"properties": {"total": {"type": "number"}}}', # or schema_id="sch_..."
|
|
86
|
+
extraction_mode="balanced", # turbo, fast, balanced, accurate
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
print(result.extraction_schema_json, result.extraction_score_average)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
When you do not set the parse `mode`, the API picks the parse mode that matches `extraction_mode`.
|
|
93
|
+
|
|
94
|
+
## Other endpoints
|
|
95
|
+
|
|
96
|
+
| Method | Endpoint |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `run_agent()` | **Beta:** run an existing published processor (`AgentOptions(processor="cp_...")`) |
|
|
99
|
+
| `segment()` | Split a document into sections (`SegmentOptions`) |
|
|
100
|
+
| `fill()` | Fill a PDF or image form (`FormFillingOptions`) |
|
|
101
|
+
| `form_fields()` | Find the fillable fields in a PDF or image |
|
|
102
|
+
| `track_changes()` | Read tracked changes and comments from DOCX or PDF |
|
|
103
|
+
| `create_document()` | Make a DOCX from markdown with track changes markup |
|
|
104
|
+
| `generate_extraction_schemas()` | Suggest extraction schemas for a saved checkpoint |
|
|
105
|
+
| `delete_result()` | Result deletion, by `result.request_id` |
|
|
106
|
+
| `upload_files()`, `list_files()`, ... | File storage. Pass the returned `datalab://file-...` reference as `file_url` |
|
|
107
|
+
| `create_extraction_schema()`, ... | Saved extraction schemas |
|
|
108
|
+
| `create_pipeline()`, `run_pipeline()`, ... | [Pipelines](https://documentation.datalab.to/docs/welcome/sdk/pipelines) |
|
|
109
|
+
|
|
110
|
+
`run_custom_processor()` and `ocr()` call deprecated API endpoints. Use `run_agent()` and `convert()` instead.
|
|
111
|
+
|
|
112
|
+
Published-agent execution is in open beta; the API may change. Processor design and raw-prompt execution are not included.
|
|
113
|
+
|
|
114
|
+
## Inputs, polling and errors
|
|
115
|
+
|
|
116
|
+
- Send a local file with `file_path`, or a URL or a `datalab://file-...` reference with `file_url`. When you set `processing_location`, send the document as `file_url`.
|
|
117
|
+
- Processing methods poll until the result is ready. Set `max_polls` and `poll_interval` to change the limit (default: 300 polls, 1 second apart). Use `stream_response_to` to write a large result straight to disk.
|
|
118
|
+
- The SDK retries a submission that gets HTTP 429 or 503, and polls that get 408, 429, 5xx or a connection error. It waits for the `Retry-After` header when the API sends one.
|
|
119
|
+
- API errors raise `DatalabAPIError` (with `status_code` and `response_data`) or one of its subclasses: `DatalabAuthenticationError` (401, 403), `DatalabPaymentRequiredError` (402), `DatalabNotFoundError` (404), `DatalabRateLimitError` (429) and `DatalabServerError` (5xx). Invalid arguments raise `DatalabValidationError`, which is also a `ValueError`.
|
|
120
|
+
|
|
121
|
+
## Workflows
|
|
122
|
+
|
|
123
|
+
The Datalab API removed the Workflows API. The workflow methods and CLI commands in this SDK are deprecated, and the API does not answer them. Use pipelines instead.
|
|
124
|
+
|
|
125
|
+
## CLI Usage
|
|
126
|
+
|
|
127
|
+
The SDK includes a command-line interface:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Convert a document or a directory of documents
|
|
131
|
+
datalab convert document.pdf --mode balanced --format markdown,html
|
|
132
|
+
|
|
133
|
+
# Extract with a saved schema
|
|
134
|
+
datalab extract invoice.pdf --schema_id sch_XXXXX --extraction_mode fast
|
|
135
|
+
|
|
136
|
+
# Other commands
|
|
137
|
+
datalab agent --help
|
|
138
|
+
datalab segment --help
|
|
139
|
+
datalab fill --help
|
|
140
|
+
datalab form-fields --help
|
|
141
|
+
datalab track-changes --help
|
|
142
|
+
datalab create-document --help
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Contributing
|
|
146
|
+
|
|
147
|
+
Issues and bug reports are welcome here. We develop the SDK in a private repository and mirror each release to this one, so we do not merge pull requests here directly. Open an issue, or open a pull request to show the change, and we will port it and credit you.
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
MIT License
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
datalab_sdk/__init__.py,sha256=BLAqVuqjxhdjKabkDUePLSmGeVMo0BnWfVbLDt8haP4,2397
|
|
2
|
+
datalab_sdk/cli.py,sha256=DAI7fzs_1cqEctp9N_rw9VPuiIFHgN75w41FG55HxrM,52427
|
|
3
|
+
datalab_sdk/client.py,sha256=PvcNA7ff6yqIKvLkspG2XzSYMStYKlvAIkZRNDNblWg,125551
|
|
4
|
+
datalab_sdk/exceptions.py,sha256=5-lzlfvB7FKGOhvgyacceTFRRUxton_JqcIyuB8k_mU,2625
|
|
5
|
+
datalab_sdk/mimetypes.py,sha256=a4ULJmHxoR_RMsD0j51hx0t2Q7In_PzNm7UlWX07eEE,932
|
|
6
|
+
datalab_sdk/models.py,sha256=OpiIAdOVcL2tdfBkzRNHZ8MjGjRiBSjaKtFVf_U1l8w,32494
|
|
7
|
+
datalab_sdk/settings.py,sha256=B_B42QQADAz6ePXQTOqENZllcppFR4JpwonEk2vlzhw,693
|
|
8
|
+
datalab_python_sdk-0.6.0.dist-info/METADATA,sha256=E2qTxFzvZarV8CeVwvGR7UW-EA6lUn_iLG9NlIT450s,6582
|
|
9
|
+
datalab_python_sdk-0.6.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
10
|
+
datalab_python_sdk-0.6.0.dist-info/entry_points.txt,sha256=rqWxO21UV57JxxyeF20iBTxHpzBYOA69hCHIqwdn-Ok,48
|
|
11
|
+
datalab_python_sdk-0.6.0.dist-info/licenses/LICENSE,sha256=XGjT-Uz6t7UZzr3JCZfilsGcZEgMm_1aONcRunohxWg,1064
|
|
12
|
+
datalab_python_sdk-0.6.0.dist-info/RECORD,,
|
datalab_sdk/__init__.py
CHANGED
|
@@ -6,7 +6,18 @@ supporting document conversion, extraction, segmentation, and more.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from .client import DatalabClient, AsyncDatalabClient
|
|
9
|
-
from .exceptions import
|
|
9
|
+
from .exceptions import (
|
|
10
|
+
DatalabError,
|
|
11
|
+
DatalabAPIError,
|
|
12
|
+
DatalabAuthenticationError,
|
|
13
|
+
DatalabPaymentRequiredError,
|
|
14
|
+
DatalabNotFoundError,
|
|
15
|
+
DatalabRateLimitError,
|
|
16
|
+
DatalabServerError,
|
|
17
|
+
DatalabTimeoutError,
|
|
18
|
+
DatalabFileError,
|
|
19
|
+
DatalabValidationError,
|
|
20
|
+
)
|
|
10
21
|
from .models import (
|
|
11
22
|
ConversionResult,
|
|
12
23
|
CreateDocumentResult,
|
|
@@ -15,16 +26,30 @@ from .models import (
|
|
|
15
26
|
ConvertOptions,
|
|
16
27
|
ExtractOptions,
|
|
17
28
|
SegmentOptions,
|
|
29
|
+
CustomProcessorOptions,
|
|
18
30
|
CustomPipelineOptions,
|
|
19
31
|
TrackChangesOptions,
|
|
20
32
|
OCROptions,
|
|
21
33
|
FormFillingOptions,
|
|
22
34
|
FormFillingResult,
|
|
35
|
+
FormFieldsOptions,
|
|
36
|
+
FormFieldsResult,
|
|
37
|
+
AgentOptions,
|
|
38
|
+
AgentResult,
|
|
39
|
+
ExtractionSchemaSuggestions,
|
|
23
40
|
Workflow,
|
|
24
41
|
WorkflowStep,
|
|
25
42
|
WorkflowExecution,
|
|
26
43
|
InputConfig,
|
|
27
44
|
UploadedFileMetadata,
|
|
45
|
+
ExtractionSchema,
|
|
46
|
+
PipelineProcessor,
|
|
47
|
+
PipelineConfig,
|
|
48
|
+
PipelineVersion,
|
|
49
|
+
PipelineExecution,
|
|
50
|
+
PipelineExecutionStepResult,
|
|
51
|
+
CustomProcessor,
|
|
52
|
+
CustomProcessorVersion,
|
|
28
53
|
)
|
|
29
54
|
from .settings import settings
|
|
30
55
|
|
|
@@ -34,7 +59,14 @@ __all__ = [
|
|
|
34
59
|
"AsyncDatalabClient",
|
|
35
60
|
"DatalabError",
|
|
36
61
|
"DatalabAPIError",
|
|
62
|
+
"DatalabAuthenticationError",
|
|
63
|
+
"DatalabPaymentRequiredError",
|
|
64
|
+
"DatalabNotFoundError",
|
|
65
|
+
"DatalabRateLimitError",
|
|
66
|
+
"DatalabServerError",
|
|
37
67
|
"DatalabTimeoutError",
|
|
68
|
+
"DatalabFileError",
|
|
69
|
+
"DatalabValidationError",
|
|
38
70
|
"ConversionResult",
|
|
39
71
|
"CreateDocumentResult",
|
|
40
72
|
"FileResult",
|
|
@@ -42,14 +74,28 @@ __all__ = [
|
|
|
42
74
|
"ConvertOptions",
|
|
43
75
|
"ExtractOptions",
|
|
44
76
|
"SegmentOptions",
|
|
77
|
+
"CustomProcessorOptions",
|
|
45
78
|
"CustomPipelineOptions",
|
|
46
79
|
"TrackChangesOptions",
|
|
47
80
|
"OCROptions",
|
|
48
81
|
"FormFillingOptions",
|
|
49
82
|
"FormFillingResult",
|
|
83
|
+
"FormFieldsOptions",
|
|
84
|
+
"FormFieldsResult",
|
|
85
|
+
"AgentOptions",
|
|
86
|
+
"AgentResult",
|
|
87
|
+
"ExtractionSchemaSuggestions",
|
|
50
88
|
"Workflow",
|
|
51
89
|
"WorkflowStep",
|
|
52
90
|
"WorkflowExecution",
|
|
53
91
|
"InputConfig",
|
|
54
92
|
"UploadedFileMetadata",
|
|
93
|
+
"ExtractionSchema",
|
|
94
|
+
"PipelineProcessor",
|
|
95
|
+
"PipelineConfig",
|
|
96
|
+
"PipelineVersion",
|
|
97
|
+
"PipelineExecution",
|
|
98
|
+
"PipelineExecutionStepResult",
|
|
99
|
+
"CustomProcessor",
|
|
100
|
+
"CustomProcessorVersion",
|
|
55
101
|
]
|