# Python OCR SDK

## Mindee API Helper Library for Python

Quickly and easily connect to Mindee's API services using Python.

### Quick Start

Here's the TL;DR of getting started.

First, get an [API Key](https://docs.mindee.com/v1/get-started/create-api-key)

Then, install this library:

```shell
pip install mindee
```

Finally, Python away!

#### Loading a File and Parsing It

**Global Documents**

```python
from mindee import Client, product, PathInput

# Init a new client
mindee_client = Client(api_key="my-api-key")

# Load a file from disk
input_source = PathInput("/path/to/the/file.ext")

# Parse the document as an invoice by passing the appropriate type
result = mindee_client.parse(product.InvoiceV4, input_source)

# Print a brief summary of the parsed data
print(result.document)
```

**Note:** Files can also be loaded from:

A python `BinaryIO` compatible file:

```python
from pathlib import Path
from mindee import BytesInput

input_path = Path("/path/to/the/file.ext")
with input_path.open("rb") as fh:
    input_bytes = fh.read()

input_source = BytesInput(
    input_bytes,
    filename="file.ext",
)
```

A URL (`HTTPS` only):

```python
from mindee import UrlInputSource

input_source = UrlInputSource(
    "https://example.com/file.ext"
)
```

A base64-encoded string, making sure to specify the extension of the file name:

```python
from mindee import Base64Input

input_base64 = "iVBORw0KGgoAAAANSUhEUgAAABgAAA ..."
input_source = Base64Input(
    input_base64,
    filename="base64_file.txt",
)
```

Raw bytes, making sure to specify the extension of the file name:

```python
input_doc = mindee_client.source_from_bytes(my_raw_bytes_sequence, "my-file-name.ext")
```

**Region-Specific Documents**

```python
from mindee import Client, product, PathInput

# Init a new client
mindee_client = Client(api_key="my-api-key")

# Load a file from disk
input_source = PathInput("/path/to/the/file.ext")

# Parse the document as a USA bank check by passing the appropriate type
result = mindee_client.parse(product.us.BankCheckV1, input_source)

# Print a brief summary of the parsed data
print(result.document)
```

#### Additional Options

Options to pass when sending a file.

**Page Options**

Allows sending only certain pages in a PDF.

In this example we only send the first, penultimate and last pages:

```python
from mindee import Client, product, PageOptions

result = mindee_client.parse(
    product.InvoiceV4,
    input_source,
    page_options=PageOptions(
        page_indexes=[0, -2, -1],
        operation=PageOptions.KEEP_ONLY,
        on_min_pages=2
    )
)
```

### Further Reading

You can view the source code on [GitHub](https://github.com/mindee/mindee-api-python).

You can also take a look at the [**Reference Documentation**](https://mindee.github.io/mindee-api-python/).

### License

Copyright © Mindee

Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
