> For the complete documentation index, see [llms.txt](https://docs.mindee.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mindee.com/v1/integration/python-sdk.md).

# 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](/v1/get-started/create-api-key.md)

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).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.mindee.com/v1/integration/python-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
