talonic 0.1.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.
Files changed (66) hide show
  1. talonic-0.1.0/.gitignore +51 -0
  2. talonic-0.1.0/CHANGELOG.md +49 -0
  3. talonic-0.1.0/LICENSE +21 -0
  4. talonic-0.1.0/PKG-INFO +213 -0
  5. talonic-0.1.0/README.md +176 -0
  6. talonic-0.1.0/pyproject.toml +91 -0
  7. talonic-0.1.0/src/talonic/__init__.py +35 -0
  8. talonic-0.1.0/src/talonic/__main__.py +6 -0
  9. talonic-0.1.0/src/talonic/_config.py +45 -0
  10. talonic-0.1.0/src/talonic/_http.py +307 -0
  11. talonic-0.1.0/src/talonic/_models/__init__.py +4 -0
  12. talonic-0.1.0/src/talonic/_models/models.py +18263 -0
  13. talonic-0.1.0/src/talonic/_types/__init__.py +1 -0
  14. talonic-0.1.0/src/talonic/_types/cost.py +60 -0
  15. talonic-0.1.0/src/talonic/_types/extract_input.py +66 -0
  16. talonic-0.1.0/src/talonic/_types/rate_limit.py +59 -0
  17. talonic-0.1.0/src/talonic/_version.py +1 -0
  18. talonic-0.1.0/src/talonic/cli.py +191 -0
  19. talonic-0.1.0/src/talonic/client.py +325 -0
  20. talonic-0.1.0/src/talonic/errors.py +92 -0
  21. talonic-0.1.0/src/talonic/py.typed +0 -0
  22. talonic-0.1.0/src/talonic/resources/__init__.py +0 -0
  23. talonic-0.1.0/src/talonic/resources/_base.py +14 -0
  24. talonic-0.1.0/src/talonic/resources/credits.py +24 -0
  25. talonic-0.1.0/src/talonic/resources/documents.py +217 -0
  26. talonic-0.1.0/src/talonic/resources/extractions.py +157 -0
  27. talonic-0.1.0/src/talonic/resources/fields.py +79 -0
  28. talonic-0.1.0/src/talonic/resources/jobs.py +105 -0
  29. talonic-0.1.0/src/talonic/resources/pricing.py +31 -0
  30. talonic-0.1.0/src/talonic/resources/schemas.py +121 -0
  31. talonic-0.1.0/src/talonic/resources/usage.py +35 -0
  32. talonic-0.1.0/tests/__init__.py +0 -0
  33. talonic-0.1.0/tests/cli/__init__.py +0 -0
  34. talonic-0.1.0/tests/cli/test_cli_commands.py +137 -0
  35. talonic-0.1.0/tests/conftest.py +53 -0
  36. talonic-0.1.0/tests/live/__init__.py +0 -0
  37. talonic-0.1.0/tests/live/test_live.py +117 -0
  38. talonic-0.1.0/tests/models/__init__.py +0 -0
  39. talonic-0.1.0/tests/models/fixtures/credits_balance.json +5 -0
  40. talonic-0.1.0/tests/models/fixtures/document_get.json +6 -0
  41. talonic-0.1.0/tests/models/fixtures/extraction_get.json +16 -0
  42. talonic-0.1.0/tests/models/fixtures/field_list.json +19 -0
  43. talonic-0.1.0/tests/models/fixtures/job_get.json +7 -0
  44. talonic-0.1.0/tests/models/fixtures/schema_list.json +21 -0
  45. talonic-0.1.0/tests/models/fixtures/search_result.json +13 -0
  46. talonic-0.1.0/tests/models/test_model_roundtrip.py +44 -0
  47. talonic-0.1.0/tests/smoke.py +27 -0
  48. talonic-0.1.0/tests/unit/__init__.py +0 -0
  49. talonic-0.1.0/tests/unit/_multipart.py +36 -0
  50. talonic-0.1.0/tests/unit/test_client.py +209 -0
  51. talonic-0.1.0/tests/unit/test_config.py +44 -0
  52. talonic-0.1.0/tests/unit/test_cost.py +48 -0
  53. talonic-0.1.0/tests/unit/test_credits.py +34 -0
  54. talonic-0.1.0/tests/unit/test_documents.py +140 -0
  55. talonic-0.1.0/tests/unit/test_errors.py +71 -0
  56. talonic-0.1.0/tests/unit/test_extract_input.py +48 -0
  57. talonic-0.1.0/tests/unit/test_extractions.py +128 -0
  58. talonic-0.1.0/tests/unit/test_fields.py +49 -0
  59. talonic-0.1.0/tests/unit/test_http_async.py +52 -0
  60. talonic-0.1.0/tests/unit/test_http_base.py +65 -0
  61. talonic-0.1.0/tests/unit/test_http_sync.py +204 -0
  62. talonic-0.1.0/tests/unit/test_jobs.py +70 -0
  63. talonic-0.1.0/tests/unit/test_pricing.py +41 -0
  64. talonic-0.1.0/tests/unit/test_rate_limit.py +52 -0
  65. talonic-0.1.0/tests/unit/test_schemas.py +77 -0
  66. talonic-0.1.0/tests/unit/test_usage.py +42 -0
@@ -0,0 +1,51 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+ MANIFEST
23
+
24
+ # Virtual envs
25
+ .venv/
26
+ venv/
27
+ ENV/
28
+ env/
29
+
30
+ # Tools
31
+ .mypy_cache/
32
+ .ruff_cache/
33
+ .pytest_cache/
34
+ .coverage
35
+ htmlcov/
36
+ *.coverage.*
37
+
38
+ # Editors
39
+ .vscode/
40
+ .idea/
41
+ *.swp
42
+ *.swo
43
+ .DS_Store
44
+
45
+ # Secrets / local env
46
+ .env
47
+ .env.*
48
+ !.env.example
49
+
50
+ # npm (we only have package.json for the spec pin)
51
+ node_modules/
@@ -0,0 +1,49 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-12-01
11
+
12
+ First public release. Mirrors `@talonic/node@0.1.24`: 28 operations with both a sync (`Talonic`) and an async (`AsyncTalonic`) client, plus a `talonic` CLI.
13
+
14
+ ### Added
15
+
16
+ - `extract()` and `search()` on the client; `documents`, `extractions`, `fields`, `jobs`, `schemas`, `credits` resources.
17
+ - `pricing.get()`: the public credit pricing catalog (`GET /v1/pricing`).
18
+ - `usage.get_by_function(days)`: per-function credit consumption (`GET /v1/usage/credits`).
19
+ - `extract()` accepts `instructions`, `options`, `content_type` and a JSON-string `schema`, next to `include_markdown` / `include_provenance`.
20
+ - List filters the API supports: `order` everywhere, `status` / `after` / `before` on extractions and jobs, `search` / `limit` / `cursor` on schemas.
21
+ - `python -m talonic` runs the CLI regardless of PATH order.
22
+ - Hybrid build: Pydantic v2 response models generated from `@talonic/docs/openapi.json` (spec 0.21.102) via `datamodel-code-generator`; hand-written transport, resources and CLI.
23
+ - PyPI Trusted Publisher (OIDC), no long-lived secrets. A release runs the same checks as CI before anything is uploaded.
24
+ - CI: lint (`ruff`), typecheck (`mypy --strict`), spec-drift check, tests on Python 3.10 to 3.14, Ubuntu and macOS.
25
+
26
+ ### Fixed before release
27
+
28
+ Found by auditing every call against the Node SDK and the API's request validation.
29
+
30
+ - `search()` sent the query as `query`; the API reads `q`, so every search came back empty.
31
+ - `extract()` now always sends multipart form fields. The JSON body used for `file_url` / `document_id` was rejected (the API validates `schema` as a JSON string), and `include_markdown=True` was sent as `"True"`, which the API rejects (it accepts only `"true"` / `"false"`).
32
+ - Upload content types come from a fixed extension table instead of the host's `mimetypes` database, which varies by OS and Python version.
33
+ - `extractions.patch()` sends the flat `{field: value}` map the API expects, not a `corrections` wrapper (which would have been stored as a field called `corrections`). The list form `[{"field": ..., "value": ...}]` is still accepted and flattened.
34
+ - `documents.filter()` sends `fieldId`, `page` and `source_id`; it sent `cursor` and `source_connection_id`, which the API silently drops.
35
+ - `fields.list()` filters by `cluster_id` (was `cluster`, silently ignored).
36
+ - `jobs.create()` no longer requires `document_ids` (omit it to run over every completed document) and accepts `name`; `include_provenance` was never an API parameter.
37
+ - `documents.re_extract()` and `fields.similar()` no longer take parameters the API ignores.
38
+ - `extractions.get_data(format="csv")` goes through the normal transport, so failures raise `TalonicError` subclasses and are retried like any other call.
39
+ - Error mapping understands every shape the API returns (flat, nested, and `{error: "<code>", message}`), joins validation message lists, falls back to the `x-request-id` header, and no longer crashes on a non-object error body.
40
+ - CLI commands print a one-line error and exit 1 on any API failure instead of a traceback.
41
+ - Generated models import without the optional `email-validator` package.
42
+ - Test suite runs on current `pytest-asyncio` (the unset loop-scope warning was fatal under `filterwarnings = error`).
43
+
44
+ ### Known limitations (v0.1.0)
45
+
46
+ - `extract()` requires either a `schema` or a `schema_id` (auto-populates `required` from `properties` when missing, the same guardrail as `@talonic/node`).
47
+ - `is_not_empty` filter checks materialized values; expect a few seconds' lag after extraction for batch documents.
48
+ - Responses are returned as plain dicts in `.data`; the generated Pydantic models are available under `talonic._models` but are not wired into the client yet.
49
+ - API coverage matches the Node SDK (a small part of the full API); broader coverage is planned for v0.2.
talonic-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Talonic GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
talonic-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.5
2
+ Name: talonic
3
+ Version: 0.1.0
4
+ Summary: Official Talonic SDK for Python. Extract structured, schema-validated data from any document.
5
+ Project-URL: Homepage, https://talonic.com
6
+ Project-URL: Repository, https://github.com/talonicdev/talonic-python
7
+ Project-URL: Documentation, https://github.com/talonicdev/talonic-python#readme
8
+ Project-URL: Issues, https://github.com/talonicdev/talonic-python/issues
9
+ Author-email: Talonic GmbH <info@talonic.ai>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: ai,document-extraction,llm,ocr,pdf,schema,structured-data,talonic
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: httpx>=0.27
25
+ Requires-Dist: pydantic>=2.10.3
26
+ Requires-Dist: typer>=0.12.4
27
+ Provides-Extra: dev
28
+ Requires-Dist: build>=1.2; extra == 'dev'
29
+ Requires-Dist: datamodel-code-generator<0.96,>=0.92; extra == 'dev'
30
+ Requires-Dist: mypy>=1.10; extra == 'dev'
31
+ Requires-Dist: pre-commit>=3.7; extra == 'dev'
32
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
33
+ Requires-Dist: pytest>=8; extra == 'dev'
34
+ Requires-Dist: respx>=0.20; extra == 'dev'
35
+ Requires-Dist: ruff<0.18,>=0.16; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # talonic
39
+
40
+ Official Talonic SDK for Python. Extract structured, schema-validated data from any document.
41
+
42
+ [![CI](https://github.com/talonicdev/talonic-python/actions/workflows/ci.yml/badge.svg)](https://github.com/talonicdev/talonic-python/actions/workflows/ci.yml)
43
+ [![PyPI](https://img.shields.io/pypi/v/talonic.svg)](https://pypi.org/project/talonic/)
44
+ [![Python](https://img.shields.io/pypi/pyversions/talonic.svg)](https://pypi.org/project/talonic/)
45
+ [![License](https://img.shields.io/pypi/l/talonic.svg)](https://github.com/talonicdev/talonic-python/blob/main/LICENSE)
46
+
47
+ > **Looking for the AI-agent / MCP path?** [`@talonic/mcp`](https://github.com/talonicdev/talonic-mcp) wraps the Talonic API as a Model Context Protocol server. Easiest install on Claude.ai is the hosted endpoint at `https://mcp.talonic.com/mcp`. For Node SDK consumers, see [`@talonic/node`](https://github.com/talonicdev/talonic-node).
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install talonic
53
+ ```
54
+
55
+ Requires Python 3.10 or newer. Three runtime deps: `httpx`, `pydantic`, `typer`.
56
+
57
+ ## Quickstart
58
+
59
+ ```python
60
+ from talonic import Talonic
61
+
62
+ client = Talonic(api_key="tlnc_...") # or set TALONIC_API_KEY env var
63
+
64
+ result = client.extract(
65
+ file_path="./invoice.pdf",
66
+ schema={
67
+ "type": "object",
68
+ "properties": {
69
+ "vendor_name": {"type": "string"},
70
+ "total_amount": {"type": "number"},
71
+ "due_date": {"type": "string", "format": "date"},
72
+ },
73
+ "required": ["vendor_name", "total_amount"],
74
+ },
75
+ )
76
+
77
+ print(result.data["data"]) # {'vendor_name': 'Acme Corp', 'total_amount': 14250, ...}
78
+ print(result.data["confidence"]["overall"]) # 0.97
79
+ print(result.cost) # CostInfo(cost_credits=12, cost_eur=0.024, ...) | None
80
+ print(result.rate_limit) # RateLimitInfo(limit=100, remaining=99, reset_at=…) | None
81
+ ```
82
+
83
+ Every call returns a `WithRateLimit` wrapper: `.data` is the API's JSON response as a plain dict, `.rate_limit` and `.cost` are parsed from the response headers.
84
+
85
+ `extract()` takes exactly one source (`file_path`, `file_data` + `filename`, `file_url` or `document_id`) and either an inline `schema` or a saved `schema_id`. Optional: `instructions`, `options`, `include_markdown`, `include_provenance`.
86
+
87
+ ## Async
88
+
89
+ ```python
90
+ import asyncio
91
+ from talonic import AsyncTalonic
92
+
93
+
94
+ async def main():
95
+ async with AsyncTalonic(api_key="tlnc_...") as client:
96
+ result = await client.extract(file_path="./invoice.pdf", schema={...})
97
+ print(result.data["data"])
98
+
99
+
100
+ asyncio.run(main())
101
+ ```
102
+
103
+ ## API surface
104
+
105
+ 28 operations. Direct sibling of `@talonic/node@0.1.x`:
106
+
107
+ | Category | Methods |
108
+ | --- | --- |
109
+ | top-level | `extract()`, `search()` |
110
+ | `documents` | `list`, `get`, `get_markdown`, `re_extract`, `delete`, `filter` |
111
+ | `extractions` | `list`, `get`, `get_data`, `patch` |
112
+ | `fields` | `list`, `get`, `similar` |
113
+ | `jobs` | `create`, `list`, `get`, `get_results`, `cancel` |
114
+ | `schemas` | `list`, `get`, `create`, `update`, `delete` |
115
+ | `credits` | `get_balance` |
116
+ | `pricing` | `get` |
117
+ | `usage` | `get_by_function` |
118
+
119
+ ```python
120
+ # Search and list (cursor paging)
121
+ hits = client.search("indemnification", limit=5).data["documents"]
122
+ page = client.documents.list(limit=20, status="completed")
123
+ next_page = client.documents.list(limit=20, cursor=page.data["pagination"]["next_cursor"])
124
+
125
+ # Filter by extracted values (page-based paging)
126
+ matches = client.documents.filter(
127
+ conditions=[{"field": "total_amount", "operator": "gt", "value": 1000}],
128
+ sort={"field": "total_amount", "direction": "desc"},
129
+ page=1,
130
+ limit=50,
131
+ )
132
+ print(matches.data["total"], matches.data["data"])
133
+
134
+ # Correct extracted values (locked at confidence 1.0)
135
+ client.extractions.patch(extraction_id, corrections={"vendor_name": "Acme Corporation Ltd."})
136
+
137
+ # Export as CSV
138
+ csv_text = client.extractions.get_data(extraction_id, format="csv")
139
+
140
+ # Batch job over saved documents
141
+ job = client.jobs.create(schema_id=schema_id, document_ids=[doc_a, doc_b], name="March batch")
142
+ results = client.jobs.get_results(job.data["id"])
143
+
144
+ # Credits: balance, where they went, and what things cost
145
+ client.credits.get_balance().data["balance_credits"]
146
+ client.usage.get_by_function(30).data["by_function"]
147
+ client.pricing.get().data["units"]
148
+ ```
149
+
150
+ ## CLI
151
+
152
+ ```bash
153
+ talonic --version
154
+ talonic schemas list
155
+ talonic documents list --limit=20
156
+ talonic credits balance
157
+ talonic extract ./invoice.pdf --schema='{"type":"object",...}'
158
+ talonic search "indemnification clauses"
159
+ ```
160
+
161
+ The `talonic` binary name overlaps with `@talonic/node`'s CLI. If both are installed globally, PATH order picks the winner; `python -m talonic` forces the Python CLI.
162
+
163
+ ## Configuration
164
+
165
+ ```python
166
+ client = Talonic(
167
+ api_key=..., # or TALONIC_API_KEY env
168
+ base_url="https://api.talonic.com", # default; or TALONIC_BASE_URL
169
+ timeout=60.0, # per-request seconds
170
+ max_retries=3, # 429/500-504/network/timeout
171
+ )
172
+ ```
173
+
174
+ ## Errors
175
+
176
+ ```python
177
+ from talonic import (
178
+ TalonicError,
179
+ TalonicAuthError,
180
+ TalonicNotFoundError,
181
+ TalonicValidationError,
182
+ TalonicRateLimitError,
183
+ TalonicServerError,
184
+ TalonicNetworkError,
185
+ TalonicTimeoutError,
186
+ )
187
+
188
+ try:
189
+ client.extract(...)
190
+ except TalonicRateLimitError as exc:
191
+ print(f"Reset at {exc.rate_limit.reset_at}")
192
+ except TalonicError as exc:
193
+ print(f"{exc.code} (status {exc.status}, request {exc.request_id}): {exc.message}")
194
+ ```
195
+
196
+ ## Development
197
+
198
+ ```bash
199
+ git clone https://github.com/talonicdev/talonic-python
200
+ cd talonic-python
201
+ make install # editable install + pre-commit hook
202
+ make test # unit + CLI + models
203
+ make check # everything CI runs: lint, typecheck, spec drift, tests, build
204
+ make typecheck # mypy --strict
205
+ make lint # ruff
206
+ make models # regenerate Pydantic models from openapi.json
207
+ make build # sdist + wheel
208
+ TALONIC_API_KEY=tlnc_... make test-live # opt-in, read-only checks against the live API
209
+ ```
210
+
211
+ ## License
212
+
213
+ MIT (c) Talonic GmbH
@@ -0,0 +1,176 @@
1
+ # talonic
2
+
3
+ Official Talonic SDK for Python. Extract structured, schema-validated data from any document.
4
+
5
+ [![CI](https://github.com/talonicdev/talonic-python/actions/workflows/ci.yml/badge.svg)](https://github.com/talonicdev/talonic-python/actions/workflows/ci.yml)
6
+ [![PyPI](https://img.shields.io/pypi/v/talonic.svg)](https://pypi.org/project/talonic/)
7
+ [![Python](https://img.shields.io/pypi/pyversions/talonic.svg)](https://pypi.org/project/talonic/)
8
+ [![License](https://img.shields.io/pypi/l/talonic.svg)](https://github.com/talonicdev/talonic-python/blob/main/LICENSE)
9
+
10
+ > **Looking for the AI-agent / MCP path?** [`@talonic/mcp`](https://github.com/talonicdev/talonic-mcp) wraps the Talonic API as a Model Context Protocol server. Easiest install on Claude.ai is the hosted endpoint at `https://mcp.talonic.com/mcp`. For Node SDK consumers, see [`@talonic/node`](https://github.com/talonicdev/talonic-node).
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pip install talonic
16
+ ```
17
+
18
+ Requires Python 3.10 or newer. Three runtime deps: `httpx`, `pydantic`, `typer`.
19
+
20
+ ## Quickstart
21
+
22
+ ```python
23
+ from talonic import Talonic
24
+
25
+ client = Talonic(api_key="tlnc_...") # or set TALONIC_API_KEY env var
26
+
27
+ result = client.extract(
28
+ file_path="./invoice.pdf",
29
+ schema={
30
+ "type": "object",
31
+ "properties": {
32
+ "vendor_name": {"type": "string"},
33
+ "total_amount": {"type": "number"},
34
+ "due_date": {"type": "string", "format": "date"},
35
+ },
36
+ "required": ["vendor_name", "total_amount"],
37
+ },
38
+ )
39
+
40
+ print(result.data["data"]) # {'vendor_name': 'Acme Corp', 'total_amount': 14250, ...}
41
+ print(result.data["confidence"]["overall"]) # 0.97
42
+ print(result.cost) # CostInfo(cost_credits=12, cost_eur=0.024, ...) | None
43
+ print(result.rate_limit) # RateLimitInfo(limit=100, remaining=99, reset_at=…) | None
44
+ ```
45
+
46
+ Every call returns a `WithRateLimit` wrapper: `.data` is the API's JSON response as a plain dict, `.rate_limit` and `.cost` are parsed from the response headers.
47
+
48
+ `extract()` takes exactly one source (`file_path`, `file_data` + `filename`, `file_url` or `document_id`) and either an inline `schema` or a saved `schema_id`. Optional: `instructions`, `options`, `include_markdown`, `include_provenance`.
49
+
50
+ ## Async
51
+
52
+ ```python
53
+ import asyncio
54
+ from talonic import AsyncTalonic
55
+
56
+
57
+ async def main():
58
+ async with AsyncTalonic(api_key="tlnc_...") as client:
59
+ result = await client.extract(file_path="./invoice.pdf", schema={...})
60
+ print(result.data["data"])
61
+
62
+
63
+ asyncio.run(main())
64
+ ```
65
+
66
+ ## API surface
67
+
68
+ 28 operations. Direct sibling of `@talonic/node@0.1.x`:
69
+
70
+ | Category | Methods |
71
+ | --- | --- |
72
+ | top-level | `extract()`, `search()` |
73
+ | `documents` | `list`, `get`, `get_markdown`, `re_extract`, `delete`, `filter` |
74
+ | `extractions` | `list`, `get`, `get_data`, `patch` |
75
+ | `fields` | `list`, `get`, `similar` |
76
+ | `jobs` | `create`, `list`, `get`, `get_results`, `cancel` |
77
+ | `schemas` | `list`, `get`, `create`, `update`, `delete` |
78
+ | `credits` | `get_balance` |
79
+ | `pricing` | `get` |
80
+ | `usage` | `get_by_function` |
81
+
82
+ ```python
83
+ # Search and list (cursor paging)
84
+ hits = client.search("indemnification", limit=5).data["documents"]
85
+ page = client.documents.list(limit=20, status="completed")
86
+ next_page = client.documents.list(limit=20, cursor=page.data["pagination"]["next_cursor"])
87
+
88
+ # Filter by extracted values (page-based paging)
89
+ matches = client.documents.filter(
90
+ conditions=[{"field": "total_amount", "operator": "gt", "value": 1000}],
91
+ sort={"field": "total_amount", "direction": "desc"},
92
+ page=1,
93
+ limit=50,
94
+ )
95
+ print(matches.data["total"], matches.data["data"])
96
+
97
+ # Correct extracted values (locked at confidence 1.0)
98
+ client.extractions.patch(extraction_id, corrections={"vendor_name": "Acme Corporation Ltd."})
99
+
100
+ # Export as CSV
101
+ csv_text = client.extractions.get_data(extraction_id, format="csv")
102
+
103
+ # Batch job over saved documents
104
+ job = client.jobs.create(schema_id=schema_id, document_ids=[doc_a, doc_b], name="March batch")
105
+ results = client.jobs.get_results(job.data["id"])
106
+
107
+ # Credits: balance, where they went, and what things cost
108
+ client.credits.get_balance().data["balance_credits"]
109
+ client.usage.get_by_function(30).data["by_function"]
110
+ client.pricing.get().data["units"]
111
+ ```
112
+
113
+ ## CLI
114
+
115
+ ```bash
116
+ talonic --version
117
+ talonic schemas list
118
+ talonic documents list --limit=20
119
+ talonic credits balance
120
+ talonic extract ./invoice.pdf --schema='{"type":"object",...}'
121
+ talonic search "indemnification clauses"
122
+ ```
123
+
124
+ The `talonic` binary name overlaps with `@talonic/node`'s CLI. If both are installed globally, PATH order picks the winner; `python -m talonic` forces the Python CLI.
125
+
126
+ ## Configuration
127
+
128
+ ```python
129
+ client = Talonic(
130
+ api_key=..., # or TALONIC_API_KEY env
131
+ base_url="https://api.talonic.com", # default; or TALONIC_BASE_URL
132
+ timeout=60.0, # per-request seconds
133
+ max_retries=3, # 429/500-504/network/timeout
134
+ )
135
+ ```
136
+
137
+ ## Errors
138
+
139
+ ```python
140
+ from talonic import (
141
+ TalonicError,
142
+ TalonicAuthError,
143
+ TalonicNotFoundError,
144
+ TalonicValidationError,
145
+ TalonicRateLimitError,
146
+ TalonicServerError,
147
+ TalonicNetworkError,
148
+ TalonicTimeoutError,
149
+ )
150
+
151
+ try:
152
+ client.extract(...)
153
+ except TalonicRateLimitError as exc:
154
+ print(f"Reset at {exc.rate_limit.reset_at}")
155
+ except TalonicError as exc:
156
+ print(f"{exc.code} (status {exc.status}, request {exc.request_id}): {exc.message}")
157
+ ```
158
+
159
+ ## Development
160
+
161
+ ```bash
162
+ git clone https://github.com/talonicdev/talonic-python
163
+ cd talonic-python
164
+ make install # editable install + pre-commit hook
165
+ make test # unit + CLI + models
166
+ make check # everything CI runs: lint, typecheck, spec drift, tests, build
167
+ make typecheck # mypy --strict
168
+ make lint # ruff
169
+ make models # regenerate Pydantic models from openapi.json
170
+ make build # sdist + wheel
171
+ TALONIC_API_KEY=tlnc_... make test-live # opt-in, read-only checks against the live API
172
+ ```
173
+
174
+ ## License
175
+
176
+ MIT (c) Talonic GmbH
@@ -0,0 +1,91 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.21"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "talonic"
7
+ dynamic = ["version"]
8
+ description = "Official Talonic SDK for Python. Extract structured, schema-validated data from any document."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [{ name = "Talonic GmbH", email = "info@talonic.ai" }]
13
+ keywords = ["talonic", "ai", "document-extraction", "ocr", "structured-data", "pdf", "schema", "llm"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Typing :: Typed",
25
+ ]
26
+ dependencies = [
27
+ "httpx>=0.27",
28
+ "pydantic>=2.10.3",
29
+ "typer>=0.12.4",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ dev = [
34
+ "pytest>=8",
35
+ "pytest-asyncio>=0.24",
36
+ "respx>=0.20",
37
+ "ruff>=0.16,<0.18",
38
+ "mypy>=1.10",
39
+ "datamodel-code-generator>=0.92,<0.96",
40
+ "build>=1.2",
41
+ "pre-commit>=3.7",
42
+ ]
43
+
44
+ [project.scripts]
45
+ talonic = "talonic.cli:app"
46
+
47
+ [project.urls]
48
+ Homepage = "https://talonic.com"
49
+ Repository = "https://github.com/talonicdev/talonic-python"
50
+ Documentation = "https://github.com/talonicdev/talonic-python#readme"
51
+ Issues = "https://github.com/talonicdev/talonic-python/issues"
52
+
53
+ [tool.hatch.version]
54
+ path = "src/talonic/_version.py"
55
+
56
+ [tool.hatch.build.targets.wheel]
57
+ packages = ["src/talonic"]
58
+
59
+ # The source archive carries the package and its tests, not repo tooling or planning notes.
60
+ [tool.hatch.build.targets.sdist]
61
+ include = [
62
+ "/src",
63
+ "/tests",
64
+ "/README.md",
65
+ "/CHANGELOG.md",
66
+ "/LICENSE",
67
+ ]
68
+
69
+ [tool.ruff]
70
+ line-length = 100
71
+ target-version = "py310"
72
+
73
+ [tool.ruff.lint]
74
+ select = ["E", "F", "I", "B", "UP", "ANN", "SIM"]
75
+
76
+ [tool.ruff.lint.per-file-ignores]
77
+ "tests/**" = ["ANN"]
78
+ "src/talonic/_models/**" = ["ALL"]
79
+
80
+ [tool.mypy]
81
+ python_version = "3.10"
82
+ strict = true
83
+ warn_unused_ignores = true
84
+ exclude = ["src/talonic/_models/", "tests/"]
85
+
86
+ [tool.pytest.ini_options]
87
+ asyncio_mode = "auto"
88
+ asyncio_default_fixture_loop_scope = "function"
89
+ testpaths = ["tests"]
90
+ markers = ["live: requires TALONIC_API_KEY against production"]
91
+ filterwarnings = ["error"]
@@ -0,0 +1,35 @@
1
+ """Official Talonic SDK for Python."""
2
+
3
+ from talonic._types.cost import CostInfo
4
+ from talonic._types.extract_input import ExtractInputError
5
+ from talonic._types.rate_limit import RateLimitInfo, WithRateLimit
6
+ from talonic._version import __version__
7
+ from talonic.client import AsyncTalonic, Talonic
8
+ from talonic.errors import (
9
+ TalonicAuthError,
10
+ TalonicError,
11
+ TalonicNetworkError,
12
+ TalonicNotFoundError,
13
+ TalonicRateLimitError,
14
+ TalonicServerError,
15
+ TalonicTimeoutError,
16
+ TalonicValidationError,
17
+ )
18
+
19
+ __all__ = [
20
+ "__version__",
21
+ "AsyncTalonic",
22
+ "Talonic",
23
+ "CostInfo",
24
+ "RateLimitInfo",
25
+ "WithRateLimit",
26
+ "ExtractInputError",
27
+ "TalonicAuthError",
28
+ "TalonicError",
29
+ "TalonicNetworkError",
30
+ "TalonicNotFoundError",
31
+ "TalonicRateLimitError",
32
+ "TalonicServerError",
33
+ "TalonicTimeoutError",
34
+ "TalonicValidationError",
35
+ ]
@@ -0,0 +1,6 @@
1
+ """`python -m talonic` — runs the CLI without relying on PATH order."""
2
+
3
+ from talonic.cli import app
4
+
5
+ if __name__ == "__main__":
6
+ app()