flatmark 1.0.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.
flatmark/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ """A client library for accessing flatmark"""
2
+
3
+ from .client import AuthenticatedClient, Client
4
+
5
+ __all__ = (
6
+ "AuthenticatedClient",
7
+ "Client",
8
+ )
@@ -0,0 +1 @@
1
+ """Contains methods for accessing the API"""
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,176 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.me_response import MeResponse
9
+ from ...types import Response
10
+
11
+
12
+ def _get_kwargs() -> dict[str, Any]:
13
+
14
+ _kwargs: dict[str, Any] = {
15
+ "method": "get",
16
+ "url": "/v1/me",
17
+ }
18
+
19
+ return _kwargs
20
+
21
+
22
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> MeResponse | None:
23
+ if response.status_code == 200:
24
+ response_200 = MeResponse.from_dict(response.json())
25
+
26
+ return response_200
27
+
28
+ if client.raise_on_unexpected_status:
29
+ raise errors.UnexpectedStatus(response.status_code, response.content)
30
+ else:
31
+ return None
32
+
33
+
34
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[MeResponse]:
35
+ return Response(
36
+ status_code=HTTPStatus(response.status_code),
37
+ content=response.content,
38
+ headers=response.headers,
39
+ parsed=_parse_response(client=client, response=response),
40
+ )
41
+
42
+
43
+ def sync_detailed(
44
+ *,
45
+ client: AuthenticatedClient,
46
+ ) -> Response[MeResponse]:
47
+ """Your plan, remaining requests, and remaining credits
48
+
49
+ Check where you stand before a call fails.
50
+
51
+ Returns the plan this request runs on and whether your key was recognized.
52
+ Without an `X-API-Key`, the call runs anonymously at the rate limit for
53
+ calls without a key. It also returns the requests left in the current window
54
+ and the features your plan includes. On plans priced in credits, it returns
55
+ the credits left in the current billing period.
56
+
57
+ This call does not count against your rate limit, so the numbers it reports
58
+ are the numbers you have.
59
+
60
+ **Credits:** free. This endpoint is not metered.
61
+
62
+ Raises:
63
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
64
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
65
+
66
+ Returns:
67
+ Response[MeResponse]
68
+ """
69
+
70
+ kwargs = _get_kwargs()
71
+
72
+ response = client.get_httpx_client().request(
73
+ **kwargs,
74
+ )
75
+
76
+ return _build_response(client=client, response=response)
77
+
78
+
79
+ def sync(
80
+ *,
81
+ client: AuthenticatedClient,
82
+ ) -> MeResponse | None:
83
+ """Your plan, remaining requests, and remaining credits
84
+
85
+ Check where you stand before a call fails.
86
+
87
+ Returns the plan this request runs on and whether your key was recognized.
88
+ Without an `X-API-Key`, the call runs anonymously at the rate limit for
89
+ calls without a key. It also returns the requests left in the current window
90
+ and the features your plan includes. On plans priced in credits, it returns
91
+ the credits left in the current billing period.
92
+
93
+ This call does not count against your rate limit, so the numbers it reports
94
+ are the numbers you have.
95
+
96
+ **Credits:** free. This endpoint is not metered.
97
+
98
+ Raises:
99
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
100
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
101
+
102
+ Returns:
103
+ MeResponse
104
+ """
105
+
106
+ return sync_detailed(
107
+ client=client,
108
+ ).parsed
109
+
110
+
111
+ async def asyncio_detailed(
112
+ *,
113
+ client: AuthenticatedClient,
114
+ ) -> Response[MeResponse]:
115
+ """Your plan, remaining requests, and remaining credits
116
+
117
+ Check where you stand before a call fails.
118
+
119
+ Returns the plan this request runs on and whether your key was recognized.
120
+ Without an `X-API-Key`, the call runs anonymously at the rate limit for
121
+ calls without a key. It also returns the requests left in the current window
122
+ and the features your plan includes. On plans priced in credits, it returns
123
+ the credits left in the current billing period.
124
+
125
+ This call does not count against your rate limit, so the numbers it reports
126
+ are the numbers you have.
127
+
128
+ **Credits:** free. This endpoint is not metered.
129
+
130
+ Raises:
131
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
132
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
133
+
134
+ Returns:
135
+ Response[MeResponse]
136
+ """
137
+
138
+ kwargs = _get_kwargs()
139
+
140
+ response = await client.get_async_httpx_client().request(**kwargs)
141
+
142
+ return _build_response(client=client, response=response)
143
+
144
+
145
+ async def asyncio(
146
+ *,
147
+ client: AuthenticatedClient,
148
+ ) -> MeResponse | None:
149
+ """Your plan, remaining requests, and remaining credits
150
+
151
+ Check where you stand before a call fails.
152
+
153
+ Returns the plan this request runs on and whether your key was recognized.
154
+ Without an `X-API-Key`, the call runs anonymously at the rate limit for
155
+ calls without a key. It also returns the requests left in the current window
156
+ and the features your plan includes. On plans priced in credits, it returns
157
+ the credits left in the current billing period.
158
+
159
+ This call does not count against your rate limit, so the numbers it reports
160
+ are the numbers you have.
161
+
162
+ **Credits:** free. This endpoint is not metered.
163
+
164
+ Raises:
165
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
166
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
167
+
168
+ Returns:
169
+ MeResponse
170
+ """
171
+
172
+ return (
173
+ await asyncio_detailed(
174
+ client=client,
175
+ )
176
+ ).parsed
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,253 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.body_convert_document import BodyConvertDocument
9
+ from ...models.problem import Problem
10
+ from ...models.sync_convert_response import SyncConvertResponse
11
+ from ...types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ body: BodyConvertDocument,
17
+ ) -> dict[str, Any]:
18
+ headers: dict[str, Any] = {}
19
+
20
+ _kwargs: dict[str, Any] = {
21
+ "method": "post",
22
+ "url": "/v1/convert",
23
+ }
24
+
25
+ _kwargs["files"] = body.to_multipart()
26
+
27
+ headers["Content-Type"] = "multipart/form-data; boundary=+++"
28
+
29
+ _kwargs["headers"] = headers
30
+ return _kwargs
31
+
32
+
33
+ def _parse_response(
34
+ *, client: AuthenticatedClient | Client, response: httpx.Response
35
+ ) -> Problem | SyncConvertResponse | None:
36
+ if response.status_code == 200:
37
+ response_200 = SyncConvertResponse.from_dict(response.json())
38
+
39
+ return response_200
40
+
41
+ if response.status_code == 402:
42
+ response_402 = Problem.from_dict(response.json())
43
+
44
+ return response_402
45
+
46
+ if response.status_code == 413:
47
+ response_413 = Problem.from_dict(response.json())
48
+
49
+ return response_413
50
+
51
+ if response.status_code == 415:
52
+ response_415 = Problem.from_dict(response.json())
53
+
54
+ return response_415
55
+
56
+ if response.status_code == 422:
57
+ response_422 = Problem.from_dict(response.json())
58
+
59
+ return response_422
60
+
61
+ if response.status_code == 429:
62
+ response_429 = Problem.from_dict(response.json())
63
+
64
+ return response_429
65
+
66
+ if response.status_code == 500:
67
+ response_500 = Problem.from_dict(response.json())
68
+
69
+ return response_500
70
+
71
+ if response.status_code == 503:
72
+ response_503 = Problem.from_dict(response.json())
73
+
74
+ return response_503
75
+
76
+ if response.status_code == 504:
77
+ response_504 = Problem.from_dict(response.json())
78
+
79
+ return response_504
80
+
81
+ if client.raise_on_unexpected_status:
82
+ raise errors.UnexpectedStatus(response.status_code, response.content)
83
+ else:
84
+ return None
85
+
86
+
87
+ def _build_response(
88
+ *, client: AuthenticatedClient | Client, response: httpx.Response
89
+ ) -> Response[Problem | SyncConvertResponse]:
90
+ return Response(
91
+ status_code=HTTPStatus(response.status_code),
92
+ content=response.content,
93
+ headers=response.headers,
94
+ parsed=_parse_response(client=client, response=response),
95
+ )
96
+
97
+
98
+ def sync_detailed(
99
+ *,
100
+ client: AuthenticatedClient,
101
+ body: BodyConvertDocument,
102
+ ) -> Response[Problem | SyncConvertResponse]:
103
+ """Convert a document to Markdown in one call
104
+
105
+ Converts one document up to 8 MB and returns the Markdown in the response.
106
+
107
+ Accepted types: PDF (`application/pdf`), Word `.docx`, PowerPoint `.pptx`,
108
+ Excel `.xlsx`, HTML (`text/html`) and plain text (`text/plain`). The
109
+ Content-Type of the file part decides how it is read. Conversion uses
110
+ MarkItDown. PDFs come back as plain text without headings and without OCR.
111
+ For scans, tables and page numbers, use the queue (`POST /v1/convert/jobs`).
112
+
113
+ Works without an API key at the anonymous rate limit. With a key, a
114
+ rejected or failed call costs no credits.
115
+
116
+ **Credits:** 1 per call.
117
+
118
+ Args:
119
+ body (BodyConvertDocument):
120
+
121
+ Raises:
122
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
123
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
124
+
125
+ Returns:
126
+ Response[Problem | SyncConvertResponse]
127
+ """
128
+
129
+ kwargs = _get_kwargs(
130
+ body=body,
131
+ )
132
+
133
+ response = client.get_httpx_client().request(
134
+ **kwargs,
135
+ )
136
+
137
+ return _build_response(client=client, response=response)
138
+
139
+
140
+ def sync(
141
+ *,
142
+ client: AuthenticatedClient,
143
+ body: BodyConvertDocument,
144
+ ) -> Problem | SyncConvertResponse | None:
145
+ """Convert a document to Markdown in one call
146
+
147
+ Converts one document up to 8 MB and returns the Markdown in the response.
148
+
149
+ Accepted types: PDF (`application/pdf`), Word `.docx`, PowerPoint `.pptx`,
150
+ Excel `.xlsx`, HTML (`text/html`) and plain text (`text/plain`). The
151
+ Content-Type of the file part decides how it is read. Conversion uses
152
+ MarkItDown. PDFs come back as plain text without headings and without OCR.
153
+ For scans, tables and page numbers, use the queue (`POST /v1/convert/jobs`).
154
+
155
+ Works without an API key at the anonymous rate limit. With a key, a
156
+ rejected or failed call costs no credits.
157
+
158
+ **Credits:** 1 per call.
159
+
160
+ Args:
161
+ body (BodyConvertDocument):
162
+
163
+ Raises:
164
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
165
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
166
+
167
+ Returns:
168
+ Problem | SyncConvertResponse
169
+ """
170
+
171
+ return sync_detailed(
172
+ client=client,
173
+ body=body,
174
+ ).parsed
175
+
176
+
177
+ async def asyncio_detailed(
178
+ *,
179
+ client: AuthenticatedClient,
180
+ body: BodyConvertDocument,
181
+ ) -> Response[Problem | SyncConvertResponse]:
182
+ """Convert a document to Markdown in one call
183
+
184
+ Converts one document up to 8 MB and returns the Markdown in the response.
185
+
186
+ Accepted types: PDF (`application/pdf`), Word `.docx`, PowerPoint `.pptx`,
187
+ Excel `.xlsx`, HTML (`text/html`) and plain text (`text/plain`). The
188
+ Content-Type of the file part decides how it is read. Conversion uses
189
+ MarkItDown. PDFs come back as plain text without headings and without OCR.
190
+ For scans, tables and page numbers, use the queue (`POST /v1/convert/jobs`).
191
+
192
+ Works without an API key at the anonymous rate limit. With a key, a
193
+ rejected or failed call costs no credits.
194
+
195
+ **Credits:** 1 per call.
196
+
197
+ Args:
198
+ body (BodyConvertDocument):
199
+
200
+ Raises:
201
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
202
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
203
+
204
+ Returns:
205
+ Response[Problem | SyncConvertResponse]
206
+ """
207
+
208
+ kwargs = _get_kwargs(
209
+ body=body,
210
+ )
211
+
212
+ response = await client.get_async_httpx_client().request(**kwargs)
213
+
214
+ return _build_response(client=client, response=response)
215
+
216
+
217
+ async def asyncio(
218
+ *,
219
+ client: AuthenticatedClient,
220
+ body: BodyConvertDocument,
221
+ ) -> Problem | SyncConvertResponse | None:
222
+ """Convert a document to Markdown in one call
223
+
224
+ Converts one document up to 8 MB and returns the Markdown in the response.
225
+
226
+ Accepted types: PDF (`application/pdf`), Word `.docx`, PowerPoint `.pptx`,
227
+ Excel `.xlsx`, HTML (`text/html`) and plain text (`text/plain`). The
228
+ Content-Type of the file part decides how it is read. Conversion uses
229
+ MarkItDown. PDFs come back as plain text without headings and without OCR.
230
+ For scans, tables and page numbers, use the queue (`POST /v1/convert/jobs`).
231
+
232
+ Works without an API key at the anonymous rate limit. With a key, a
233
+ rejected or failed call costs no credits.
234
+
235
+ **Credits:** 1 per call.
236
+
237
+ Args:
238
+ body (BodyConvertDocument):
239
+
240
+ Raises:
241
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
242
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
243
+
244
+ Returns:
245
+ Problem | SyncConvertResponse
246
+ """
247
+
248
+ return (
249
+ await asyncio_detailed(
250
+ client=client,
251
+ body=body,
252
+ )
253
+ ).parsed
@@ -0,0 +1,237 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+ from urllib.parse import quote
4
+
5
+ import httpx
6
+
7
+ from ... import errors
8
+ from ...client import AuthenticatedClient, Client
9
+ from ...models.get_conversion_result_format import GetConversionResultFormat
10
+ from ...models.problem import Problem
11
+ from ...types import UNSET, Response, Unset
12
+
13
+
14
+ def _get_kwargs(
15
+ job_id: str,
16
+ *,
17
+ format_: GetConversionResultFormat | Unset = GetConversionResultFormat.MARKDOWN,
18
+ ) -> dict[str, Any]:
19
+
20
+ params: dict[str, Any] = {}
21
+
22
+ json_format_: str | Unset = UNSET
23
+ if not isinstance(format_, Unset):
24
+ json_format_ = format_.value
25
+
26
+ params["format"] = json_format_
27
+
28
+ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
29
+
30
+ _kwargs: dict[str, Any] = {
31
+ "method": "get",
32
+ "url": "/v1/convert/jobs/{job_id}/result".format(
33
+ job_id=quote(str(job_id), safe=""),
34
+ ),
35
+ "params": params,
36
+ }
37
+
38
+ return _kwargs
39
+
40
+
41
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Problem | str | None:
42
+ if response.status_code == 200:
43
+ response_200 = response.text
44
+ return response_200
45
+
46
+ if response.status_code == 404:
47
+ response_404 = Problem.from_dict(response.json())
48
+
49
+ return response_404
50
+
51
+ if response.status_code == 409:
52
+ response_409 = Problem.from_dict(response.json())
53
+
54
+ return response_409
55
+
56
+ if response.status_code == 410:
57
+ response_410 = Problem.from_dict(response.json())
58
+
59
+ return response_410
60
+
61
+ if response.status_code == 422:
62
+ response_422 = Problem.from_dict(response.json())
63
+
64
+ return response_422
65
+
66
+ if response.status_code == 429:
67
+ response_429 = Problem.from_dict(response.json())
68
+
69
+ return response_429
70
+
71
+ if client.raise_on_unexpected_status:
72
+ raise errors.UnexpectedStatus(response.status_code, response.content)
73
+ else:
74
+ return None
75
+
76
+
77
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Problem | str]:
78
+ return Response(
79
+ status_code=HTTPStatus(response.status_code),
80
+ content=response.content,
81
+ headers=response.headers,
82
+ parsed=_parse_response(client=client, response=response),
83
+ )
84
+
85
+
86
+ def sync_detailed(
87
+ job_id: str,
88
+ *,
89
+ client: AuthenticatedClient,
90
+ format_: GetConversionResultFormat | Unset = GetConversionResultFormat.MARKDOWN,
91
+ ) -> Response[Problem | str]:
92
+ """Download a queued job's Markdown or JSON
93
+
94
+ Returns the output of one of your finished queued jobs.
95
+
96
+ Markdown (`text/markdown`) by default, or the DoclingDocument JSON
97
+ (`application/json`) with `?format=json`. The JSON carries page numbers for
98
+ PDF, slide numbers for PowerPoint and sheet names for Excel.
99
+
100
+ **Credits:** free. This endpoint is not metered.
101
+
102
+ Args:
103
+ job_id (str):
104
+ format_ (GetConversionResultFormat | Unset): `markdown` (default) or `json` for the
105
+ DoclingDocument structure file. Default: GetConversionResultFormat.MARKDOWN.
106
+
107
+ Raises:
108
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
109
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
110
+
111
+ Returns:
112
+ Response[Problem | str]
113
+ """
114
+
115
+ kwargs = _get_kwargs(
116
+ job_id=job_id,
117
+ format_=format_,
118
+ )
119
+
120
+ response = client.get_httpx_client().request(
121
+ **kwargs,
122
+ )
123
+
124
+ return _build_response(client=client, response=response)
125
+
126
+
127
+ def sync(
128
+ job_id: str,
129
+ *,
130
+ client: AuthenticatedClient,
131
+ format_: GetConversionResultFormat | Unset = GetConversionResultFormat.MARKDOWN,
132
+ ) -> Problem | str | None:
133
+ """Download a queued job's Markdown or JSON
134
+
135
+ Returns the output of one of your finished queued jobs.
136
+
137
+ Markdown (`text/markdown`) by default, or the DoclingDocument JSON
138
+ (`application/json`) with `?format=json`. The JSON carries page numbers for
139
+ PDF, slide numbers for PowerPoint and sheet names for Excel.
140
+
141
+ **Credits:** free. This endpoint is not metered.
142
+
143
+ Args:
144
+ job_id (str):
145
+ format_ (GetConversionResultFormat | Unset): `markdown` (default) or `json` for the
146
+ DoclingDocument structure file. Default: GetConversionResultFormat.MARKDOWN.
147
+
148
+ Raises:
149
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
150
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
151
+
152
+ Returns:
153
+ Problem | str
154
+ """
155
+
156
+ return sync_detailed(
157
+ job_id=job_id,
158
+ client=client,
159
+ format_=format_,
160
+ ).parsed
161
+
162
+
163
+ async def asyncio_detailed(
164
+ job_id: str,
165
+ *,
166
+ client: AuthenticatedClient,
167
+ format_: GetConversionResultFormat | Unset = GetConversionResultFormat.MARKDOWN,
168
+ ) -> Response[Problem | str]:
169
+ """Download a queued job's Markdown or JSON
170
+
171
+ Returns the output of one of your finished queued jobs.
172
+
173
+ Markdown (`text/markdown`) by default, or the DoclingDocument JSON
174
+ (`application/json`) with `?format=json`. The JSON carries page numbers for
175
+ PDF, slide numbers for PowerPoint and sheet names for Excel.
176
+
177
+ **Credits:** free. This endpoint is not metered.
178
+
179
+ Args:
180
+ job_id (str):
181
+ format_ (GetConversionResultFormat | Unset): `markdown` (default) or `json` for the
182
+ DoclingDocument structure file. Default: GetConversionResultFormat.MARKDOWN.
183
+
184
+ Raises:
185
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
186
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
187
+
188
+ Returns:
189
+ Response[Problem | str]
190
+ """
191
+
192
+ kwargs = _get_kwargs(
193
+ job_id=job_id,
194
+ format_=format_,
195
+ )
196
+
197
+ response = await client.get_async_httpx_client().request(**kwargs)
198
+
199
+ return _build_response(client=client, response=response)
200
+
201
+
202
+ async def asyncio(
203
+ job_id: str,
204
+ *,
205
+ client: AuthenticatedClient,
206
+ format_: GetConversionResultFormat | Unset = GetConversionResultFormat.MARKDOWN,
207
+ ) -> Problem | str | None:
208
+ """Download a queued job's Markdown or JSON
209
+
210
+ Returns the output of one of your finished queued jobs.
211
+
212
+ Markdown (`text/markdown`) by default, or the DoclingDocument JSON
213
+ (`application/json`) with `?format=json`. The JSON carries page numbers for
214
+ PDF, slide numbers for PowerPoint and sheet names for Excel.
215
+
216
+ **Credits:** free. This endpoint is not metered.
217
+
218
+ Args:
219
+ job_id (str):
220
+ format_ (GetConversionResultFormat | Unset): `markdown` (default) or `json` for the
221
+ DoclingDocument structure file. Default: GetConversionResultFormat.MARKDOWN.
222
+
223
+ Raises:
224
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
225
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
226
+
227
+ Returns:
228
+ Problem | str
229
+ """
230
+
231
+ return (
232
+ await asyncio_detailed(
233
+ job_id=job_id,
234
+ client=client,
235
+ format_=format_,
236
+ )
237
+ ).parsed