Quick Start

Quickest way to get started using the client libraries.

Installation Instructions

Requires Python ≥ 3.9. Python ≥ 3.10 is highly recommended.

Simply install the PyPi package using pip:

pip install mindee>=4.29.1

Don't see support for your favorite language or framework? Make a feature request!

Send a File and Poll

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 basic code examples, these are self-contained and can be run as-is:

Requires Python ≥ 3.9. Python ≥ 3.10 is highly recommended. Requires the Mindee Python client library version 4.29.1 or greater.

from mindee import ClientV2, InferenceParameters, PathInput

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 parameters
params = InferenceParameters(
    # ID of the model, required.
    model_id=model_id,

    # Options: set to `True` or `False` to override defaults

    # Enhance extraction accuracy with Retrieval-Augmented Generation.
    rag=None,
    # Extract the full text content from the document as strings.
    raw_text=None,
    # Calculate bounding box polygons for all fields.
    polygon=None,
    # Boost the precision and accuracy of all extractions.
    # Calculate confidence scores for all fields.
    confidence=None,
)

# Load a file from disk
input_source = PathInput(input_path)

# Send for processing using polling
response = mindee_client.enqueue_and_get_inference(
    input_source, params
)

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

Details on Sending

For details on available options and advanced usage, check the following sections:

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 simple values, using the name of the field in the Data Schema.

We can (should!) specify the type of value, the possible types are str , bool , float . Note that all types may be None.

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
  fields: dict = response.inference.result.fields

  # texts, dates, classifications ...
  string_field_value: str | None = fields["string_field"].value

  # a JSON float will be a float
  float_field_value: float | None = fields["float_field"].value

  # even if the API always returns an integer, the type will be float
  int_field_value: float | None = fields["int_field"].value

  # booleans
  bool_field_value: bool | None = fields["bool_field"].value

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

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    simple_list_field = fields["my_simple_list_field"]

    # Loop over the list of Simple fields
    for list_item in simple_list_field.items:
        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 .

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    object_field = fields["my_object_field"]

    sub_fields: dict = object_field.fields

    # grab a single sub-field
    subfield_1 = sub_fields["subfield_1"]

    # loop over sub-fields
    for field_name, sub_field in sub_fields.items():
        sub_field.value

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

from mindee import InferenceResponse

def handle_response(response: InferenceResponse):
    fields: dict = response.inference.result.fields

    object_list_field = fields["my_object_list_field"]

    # Loop over the list of Object fields
    for object_item in object_list_field.items:
        # grab a single sub-field
        sub_field_value = object_item.fields["sub_field"].value
        
        # loop over sub-fields
        for field_name, sub_field in object_item.fields.items():
            sub_field.value

Details on Processing

For details on available options and advanced usage, check the following sections:

Last updated

Was this helpful?