|
3 | 3 | # Mindee API Helper Library for Python
|
4 | 4 | Quickly and easily connect to Mindee's API services using Python.
|
5 | 5 |
|
6 |
| -## Quick Start |
7 |
| -Here's the TL;DR of getting started. |
| 6 | +## Mindee API Versions |
| 7 | +This client library has support for both Mindee platform versions. |
8 | 8 |
|
9 |
| -First, get an [API Key](https://developers.mindee.com/docs/create-api-key) |
| 9 | +### Latest - V2 |
| 10 | +This is the new platform located here: |
10 | 11 |
|
11 |
| -Then, install this library: |
12 |
| -```shell |
13 |
| -pip install mindee |
14 |
| -``` |
| 12 | +https://app.mindee.com |
15 | 13 |
|
16 |
| -Finally, Python away! |
| 14 | +It uses **API version 2**. |
17 | 15 |
|
18 |
| -### Loading a File and Parsing It |
| 16 | +Consult the |
| 17 | +**[Latest Documentation](https://docs.mindee.com/integrations/client-libraries-sdk)** |
19 | 18 |
|
20 |
| -#### Global Documents |
21 |
| -```python |
22 |
| -from mindee import Client, product |
23 | 19 |
|
24 |
| -# Init a new client |
25 |
| -mindee_client = Client(api_key="my-api-key") |
| 20 | +### Legacy - V1 |
| 21 | +This is the legacy platform located here: |
26 | 22 |
|
27 |
| -# Load a file from disk |
28 |
| -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") |
| 23 | +https://platform.mindee.com/ |
29 | 24 |
|
30 |
| -# Parse the document as an invoice by passing the appropriate type |
31 |
| -result = mindee_client.parse(product.InvoiceV4, input_doc) |
| 25 | +It uses **API version 1**. |
32 | 26 |
|
33 |
| -# Print a brief summary of the parsed data |
34 |
| -print(result.document) |
35 |
| -``` |
| 27 | +Consult the |
| 28 | +**[Legacy Documentation](https://developers.mindee.com/docs/python-getting-started)** |
36 | 29 |
|
37 |
| -**Note:** Files can also be loaded from: |
| 30 | +## Additional Information |
38 | 31 |
|
39 |
| -A python `BinaryIO` compatible file: |
40 |
| -```python |
41 |
| -input_doc = mindee_client.source_from_file(my_file) |
42 |
| -``` |
| 32 | +**[Source Code](https://github.com/mindee/mindee-api-python)** |
43 | 33 |
|
44 |
| -A URL (`HTTPS` only): |
45 |
| -```python |
46 |
| -input_doc = mindee_client.source_from_url( |
47 |
| - "https://files.readme.io/a74eaa5-c8e283b-sample_invoice.jpeg" |
48 |
| -) |
49 |
| -``` |
| 34 | +**[Reference Documentation](https://mindee.github.io/mindee-api-python/)** |
50 | 35 |
|
51 |
| -A base64-encoded string, making sure to specify the extension of the file name: |
52 |
| -```python |
53 |
| -input_doc = mindee_client.source_from_b64string( |
54 |
| - my_input_string, "my-file-name.ext" |
55 |
| -) |
56 |
| -``` |
| 36 | +**[Feedback](https://feedback.mindee.com/)** |
57 | 37 |
|
58 |
| -Raw bytes, making sure to specify the extension of the file name: |
59 |
| -```python |
60 |
| -input_doc = mindee_client.source_from_bytes( |
61 |
| - my_raw_bytes_sequence, "my-file-name.ext" |
62 |
| -) |
63 |
| -``` |
64 |
| - |
65 |
| -#### Region-Specific Documents |
66 |
| -```python |
67 |
| -from mindee import Client, product |
68 |
| - |
69 |
| -# Init a new client |
70 |
| -mindee_client = Client(api_key="my-api-key") |
71 |
| - |
72 |
| -# Load a file from disk |
73 |
| -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") |
74 |
| - |
75 |
| -# Parse the document as a USA bank check by passing the appropriate type |
76 |
| -result = mindee_client.parse(product.us.BankCheckV1, input_doc) |
77 |
| - |
78 |
| -# Print a brief summary of the parsed data |
79 |
| -print(result.document) |
80 |
| -``` |
81 |
| - |
82 |
| -#### Custom Documents (docTI & Custom APIs) |
83 |
| - |
84 |
| -```python |
85 |
| -from mindee import Client, product |
86 |
| - |
87 |
| -# Init a new client |
88 |
| -mindee_client = Client(api_key="my-api-key") |
89 |
| - |
90 |
| -# Add your custom endpoint (document) |
91 |
| -my_endpoint = mindee_client.create_endpoint( |
92 |
| - account_name="my-account", |
93 |
| - endpoint_name="my-endpoint", |
94 |
| -) |
95 |
| - |
96 |
| -# Load a file from disk |
97 |
| -input_doc = mindee_client.source_from_path("/path/to/the/file.ext") |
98 |
| - |
99 |
| -# Parse the file. |
100 |
| -# The endpoint must be specified since it cannot be determined from the class. |
101 |
| -result = mindee_client.enqueue_and_parse( |
102 |
| - product.GeneratedV1, |
103 |
| - input_doc, |
104 |
| - endpoint=my_endpoint |
105 |
| -) |
106 |
| - |
107 |
| -# Print a brief summary of the parsed data |
108 |
| -print(result.document) |
109 |
| - |
110 |
| -# Iterate over all the fields in the document |
111 |
| -for field_name, field_values in result.document.fields.items(): |
112 |
| - print(field_name, "=", field_values) |
113 |
| -``` |
114 |
| - |
115 |
| -### Enqueue and Parse a Webhook Response |
116 |
| -This is an optional way of handling asynchronous APIs. |
117 |
| - |
118 |
| -```python |
119 |
| -from mindee import Client, product |
120 |
| - |
121 |
| -mindee_client = Client() |
122 |
| -input_source = mindee_client.source_from_path("/path/to/the/file.ext") |
123 |
| - |
124 |
| -result = mindee_client.enqueue_and_parse( |
125 |
| - product.FinancialDocumentV1, |
126 |
| - input_source, |
127 |
| - workflow_id="my-workflow-id", |
128 |
| - rag=True, |
129 |
| -) |
130 |
| - |
131 |
| -print(result.document) |
132 |
| -``` |
133 |
| - |
134 |
| -### Additional Options |
135 |
| -Options to pass when sending a file. |
136 |
| -```python |
137 |
| -from mindee import Client, product |
138 |
| -from mindee.client import LocalResponse |
139 |
| - |
140 |
| -mindee_client = Client() |
141 |
| -input_source = mindee_client.source_from_path("/path/to/the/file.ext") |
142 |
| - |
143 |
| -enqueue_response = mindee_client.enqueue( |
144 |
| - product.InternationalIdV2, |
145 |
| - input_source, |
146 |
| -) |
147 |
| - |
148 |
| -# You can keep track of the job's ID for traceability concerns. |
149 |
| -job_id = enqueue_response.job.id |
150 |
| - |
151 |
| - |
152 |
| -# Load the JSON string sent by the Mindee webhook POST callback. |
153 |
| -# Reading the callback data will vary greatly depending on your HTTP server. |
154 |
| -# This is therefore beyond the scope of this example. |
155 |
| - |
156 |
| -local_response = LocalResponse(request.body()) |
157 |
| - |
158 |
| -# You can also load the json from a local path. |
159 |
| -# local_response = LocalResponse("path/to/my/file.ext") |
160 |
| - |
161 |
| -# Optional: verify the HMAC signature |
162 |
| -# You'll need to get the "X-Mindee-Hmac-Signature" custom HTTP header. |
163 |
| -hmac_signature = request.headers.get("X-Mindee-Hmac-Signature") |
164 |
| -if not local_response.is_valid_hmac_signature(my_secret_key, hmac_signature): |
165 |
| - raise Error("Bad HMAC signature! Is someone trying to do evil?") |
166 |
| - |
167 |
| -# Deserialize the response |
168 |
| - |
169 |
| -result = mindee_client.load_prediction( |
170 |
| - product.InternationalIdV2, |
171 |
| - local_response |
172 |
| -) |
173 |
| - |
174 |
| -# Print a full summary of the parsed data in RST format |
175 |
| -print(result.document) |
176 |
| -``` |
177 |
| - |
178 |
| - |
179 |
| -#### Page Options |
180 |
| -Allows sending only certain pages in a PDF. |
181 |
| - |
182 |
| -In this example we only send the first, penultimate and last pages: |
183 |
| - |
184 |
| -```python |
185 |
| -from mindee import product, PageOptions |
186 |
| - |
187 |
| -result = mindee_client.parse( |
188 |
| - product.InvoiceV4, |
189 |
| - input_source, |
190 |
| - page_options=PageOptions( |
191 |
| - page_indexes=[0, -2, -1], |
192 |
| - operation=PageOptions.KEEP_ONLY, |
193 |
| - on_min_pages=2 |
194 |
| - ) |
195 |
| -) |
196 |
| -``` |
197 |
| - |
198 |
| -You can view the source code on [GitHub](https://github.com/mindee/mindee-api-python). |
199 |
| - |
200 |
| -You can also take a look at the |
201 |
| -**[Reference Documentation](https://mindee.github.io/mindee-api-python/)**. |
202 |
| - |
203 |
| -## License |
| 38 | +### License |
204 | 39 | Copyright © Mindee
|
205 | 40 |
|
206 | 41 | Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
207 |
| - |
208 |
| -## Questions? |
209 |
| -[Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g) |
0 commit comments