> 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
