|
1 | | -# Mindee API helper library for Python |
| 1 | +# Mindee API Helper Library for Python |
2 | 2 |
|
3 | | -The full documentation is available [here](https://developers.mindee.com/docs/getting-started) |
| 3 | +## Quick Start |
| 4 | +Here's the TL;DR of getting started. |
4 | 5 |
|
5 | | -## Requirements |
6 | | - |
7 | | -This library is officially supported on Python 3.7 to 3.10. |
8 | | - |
9 | | -## Install |
10 | | - |
11 | | -Install from PyPi using pip, a package manager for Python. |
| 6 | +First, get an [API Key](https://developers.mindee.com/docs/make-your-first-request#create-an-api-key) |
12 | 7 |
|
| 8 | +Then, install this library: |
13 | 9 | ```shell script |
14 | 10 | pip install mindee |
15 | 11 | ``` |
16 | 12 |
|
17 | | -Don't have pip installed? Try installing it, by running this from the command line: |
18 | | - |
19 | | -```shell script |
20 | | -$ curl https://bootstrap.pypa.io/get-pip.py | python |
21 | | -``` |
22 | | - |
23 | | -Getting started with the Mindee API couldn't be easier. |
24 | | -Create a Client and you're ready to go. |
25 | | - |
26 | | -## Create your Client |
27 | | - |
28 | | -The mindee.Client needs your [API credentials](https://developers.mindee.com/docs/make-your-first-request#create-an-api-key). |
29 | | -You can either pass these directly to the constructor (see the code below) or via environment variables. |
30 | | - |
31 | | -Depending on what type of document you want to parse, you need to add specifics auth token for each endpoint. |
| 13 | +Finally, Python away! |
32 | 14 |
|
| 15 | +### Off-the-Shelf Document |
33 | 16 | ```python |
34 | 17 | from mindee import Client |
35 | 18 |
|
36 | | -mindee_client = Client( |
37 | | - expense_receipt_token="your_expense_receipt_api_token_here", |
38 | | - invoice_token="your_invoice_api_token_here", |
39 | | - passport_token="your_passport_api_token_here", |
40 | | - license_plate_token="your_license_plate_api_token_here", |
41 | | - raise_on_error=True |
42 | | -) |
43 | | -``` |
44 | | - |
45 | | -We suggest storing your credentials as environment variables. |
46 | | -Why? You'll never have to worry about committing your credentials and accidentally posting them somewhere public. |
| 19 | +# Init a new client and configure the Invoice API |
| 20 | +mindee_client = Client().config_invoice("my-invoice-api-key") |
47 | 21 |
|
| 22 | +# Load a file from disk and parse it |
| 23 | +api_response = mindee_client.doc_from_path("/path/to/the/invoice.pdf").parse("invoice") |
48 | 24 |
|
49 | | -## Parsing methods |
| 25 | +# Print a brief summary of the parsed data |
| 26 | +print(api_response.invoice) |
| 27 | +``` |
50 | 28 |
|
| 29 | +### Custom Document (API Builder) |
51 | 30 | ```python |
52 | | -# Call the receipt parsing API and create a receipt object under parsed_data.receipt |
53 | | -parsed_data = mindee_client.parse_receipt("/path/to/file") |
54 | | - |
55 | | -# Call the invoice parsing API and create an invoice object under parsed_data.invoice |
56 | | -parsed_data = mindee_client.parse_invoice("/path/to/file") |
| 31 | +from mindee import Client |
57 | 32 |
|
58 | | -# If you have a mixed data flow of invoice and receipt, use financial_document class |
59 | | -# Call the invoice or receipt parsing API according to your input data type |
60 | | -# and create a FinancialDocument object under parsed_data.financial_document |
61 | | -parsed_data = mindee_client.parse_financial_document("/path/to/file") |
| 33 | +# Init a new client and configure your custom document |
| 34 | +mindee_client = Client().config_custom_doc( |
| 35 | + document_type="pokemon-card", |
| 36 | + singular_name="card", |
| 37 | + plural_name="cards", |
| 38 | + account_name="pikachu", |
| 39 | + api_key="pokemon-card-api-key" |
| 40 | +) |
62 | 41 |
|
63 | | -# Call the passport parsing API and create a Passport object under parsed_data.passport |
64 | | -parsed_data = mindee_client.parse_passport("/path/to/file") |
| 42 | +# Load a file from disk and parse it |
| 43 | +api_response = mindee_client.doc_from_path("/path/to/the/card.jpg").parse("pokemon-card") |
65 | 44 |
|
66 | | -# Call the license_plates parsing API and create a CarPlate object under parsed_data.license_plate |
67 | | -parsed_data = mindee_client.parse_license_plate("/path/to/file") |
| 45 | +# Print a brief summary of the parsed data |
| 46 | +print(api_response.card) |
68 | 47 | ``` |
69 | 48 |
|
70 | | -## Input data |
71 | | - |
72 | | -You can pass your input file in three ways: |
| 49 | +## Further Reading |
| 50 | +There's more to it than that for those that need more features, or want to |
| 51 | +customize the experience. |
73 | 52 |
|
74 | | -From file path |
75 | | -```python |
76 | | -receipt_data = mindee_client.parse_receipt('/path/to/file', input_type="path") |
77 | | -``` |
| 53 | +All the juicy details are described in the |
| 54 | +**[Official Documentation](https://developers.mindee.com/docs/getting-started)**. |
78 | 55 |
|
79 | | -From a file object |
80 | | -```python |
81 | | -with open('/path/to/file', 'rb') as fp: |
82 | | - receipt_data = mindee_client.parse_receipt(fp, input_type="file") |
83 | | -``` |
| 56 | +## License |
| 57 | +Copyright © Mindee |
84 | 58 |
|
85 | | -From a base64 |
86 | | -```python |
87 | | -receipt_data = mindee_client.parse_receipt(base64_string, input_type="base64", filename="receipt.jpg") |
88 | | -``` |
| 59 | +Distributed under the MIT License. |
0 commit comments