Integrating Mindee

Once you have your model set up, you'll want to start using it!

API key

Make sure you've created your API Key before continuing.

To create and manage your API keys, go to the "API Keys" section on the Mindee Platform.

Click on create API Key, choose a name for this API Key, and validate.

You're now ready to go!

Sending a File

To process your document using Mindee, simply send the file using the REST API.

Make a note of your model's ID for use in the API.

When getting started, we recommend using the Polling method which will be quickest (unless you happen to already have access to a public-facing Web server).

Here are some code examples, these are self-contained and can be run as-is:

Requires Python 3.9 or greater and the Mindee Python client library version 4.24.0 or greater. Currently you'll need the RC version, full release coming soon!

from mindee import ClientV2, InferencePredictOptions
from mindee.parsing.v2 import InferenceResponse

input_path = "/path/to/the/file.ext"
api_key = "MY_API_KEY"
model_id = "MY_MODEL_ID"

# Init a new client
mindee_client = ClientV2(api_key)

# Set inference options
options = InferencePredictOptions(
    # ID of the model, required.
    model_id=model_id,
    # If set to `True`, will enable Retrieval-Augmented Generation.
    rag=False,
)

# Load a file from disk
input_source = mindee_client.source_from_path(input_path)

# Upload the file
response: InferenceResponse = mindee_client.enqueue_and_parse(
    input_source, options
)

# Print a brief summary of the parsed data
print(response.inference)

Processing the Results

Once you've sent the file and retrieved the results, you can start extracting the JSON payload.

The model's fields will be in the fields object in the returned JSON, in the response variable returned from the above step.

Each key in the fields object corresponds to the field's name in your model configuration.

You'll want to adapt your processing depending on the type of field, for example looping over lists.

Accessing a simple value, where my_simple_field is the name of the field in the Model.

my_simple_field = response.inference.fields["my_simple_field"]
field_value = my_simple_field.value

Accessing a list of values, where my_list_field is the name of the field in the Model.

my_list_field = response.inference.fields["my_list_field"]

# access a value at a given position
field_first_value = my_list_field[0].value

# loop over all values in the list
for list_item in my_list_field:
    item_value = list_item.value

Accessing an object field, where my_object_field is the name of the field in the Model. In this hypothetical case, the object has a sub-field named sub_field .

object_field = response.inference.fields["my_object_field"]
sub_field_value = object_field.fields["sub_field"].value

Accessing a list of objects, where my_object_list_field is the name of the field in the Model.

object_list_field = response.inference.fields["my_object_list_field"]

# access an object at a given position
object_item_0 = object_list_field[0]
sub_field_0_value = object_item_0["sub_field"].value

# loop over object lists
for object_item in object_list_field:
  sub_field_value = object_item.fields["sub_field"].value

Last updated

Was this helpful?