Processing a Result
Requirements
Before proceeding you'll need to have already sent a file to the Mindee servers using a client library.
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.
Assuming you're able to get the raw HTTP request via the variable request
.
from mindee import LocalResponse, InferenceResponse
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")
if not local_response.is_valid_hmac_signature(my_secret_key, hmac_signature):
raise Error("Bad HMAC signature! Is someone trying to do evil?")
# Deserialize the response
result = local_response.deserialize_response(InferenceResponse)
Extract Field Values
Fields are dynamic depending on your model.
In the client library, you'll have access to the various fields as a mapping type.
Each field will then be one of the following types:
A single value.
Multiple values, an object.
A list or array of fields.
Single-Value Fields
Basic field type having a single value attribute.
Possible types: string, number (integer or floating-point), boolean. All types can be null.
Multiple-Value Fields (Objects)
Each field can theoretically be of any type (single, multi, list). In practice: we limit to a single value, meaning no recursive objects nor lists.
Lists
Each item in the list can theoretically be of any type (single, multi, list). In practice: we limit items to be either single or multi field, meaning no lists of lists.
Last updated
Was this helpful?