Process the Response
Reference documentation on processing responses using the Mindee client libraries.
Requirements
You'll need to have already sent a file or URL as described in the Send a File or URL section.
Overview
Depending on how you've sent the file, there are two ways of obtaining the result.
If you've sent via polling (or polling and webhook) you'll get the response directly in your method call.
If you've sent only via webhook, you'll receive the response on your Web server.
Here we'll go over how you can best process the results.
Load From Webhook
If you're using the webhook pattern, you'll need to use the payload sent to your Web server.
Reading the callback data will vary greatly depending on your HTTP server. This is therefore beyond the scope of this example.
Regardless of how you access the JSON payload sent by the Mindee servers, loading this data is done by using a LocalResponse class.
Once it is loaded you can access the data in exactly the same way as a polling response.
To verify the HMAC signature, you'll need the Signing Secret from the webhook:

Assuming you're able to get the raw HTTP request via the variable request
.
from mindee import LocalResponse, InferenceResponse
# Load the JSON string sent by the Mindee webhook POST callback.
local_response = LocalResponse(request.body())
# You can also load the json from a local path.
# local_response = LocalResponse("path/to/my/file.ext")
# Optionally: verify the HMAC signature
# You'll need to get the "X-Signature" custom HTTP header.
hmac_signature = request.headers.get("X-Signature")
is_valid = local_response.is_valid_hmac_signature(
"obviously-fake-secret-key", hmac_signature
)
if not is_valid:
raise Error("Bad HMAC signature! Is someone trying to do evil?")
# Deserialize the response into objects
response = local_response.deserialize_response(InferenceResponse)
The Inference Object
This is the top-level object in the response.
It contains the following attributes:
id
UUID of the inferencemodel
Model used for the inferencefile
Metadata concerning the file used for the inferenceresult
Result of inference processing, the most important portion of the response. For handling the extracted fields, see the Process Result Fields section.
File Metadata
You can access various metadata concerning the file sent for processing.
Using the response
deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
from mindee.parsing.v2 import InferenceFile
def handle_response(response: InferenceResponse):
inference_file: InferenceFile = response.inference.file
# various attributes are available, such as:
filename: str = inference_file.name
page_count: int = file.page_count
mime_type: str = file.mine_type
Results
Raw Text
Access the full text content from the document, extracted as strings.
Using the response
deserialized object from either the polling response or a webhook payload.
from mindee import InferenceResponse
def handle_response(response: InferenceResponse):
raw_text = inference.result.raw_text
# get the entire document as a single string
document_text = str(raw_text)
# loop over pages
for page in raw_text.pages:
print(page.content)
Fields
For handling the extracted fields, see the Process Result Fields section.
Last updated
Was this helpful?