
Security News
Python Adopts Standard Lock File Format for Reproducible Installs
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
Quickly and easily connect to Mindee's API services using Python.
Here's the TL;DR of getting started.
First, get an API Key
Then, install this library:
pip install mindee
Finally, Python away!
from mindee import Client, product
# Init a new client
mindee_client = Client(api_key="my-api-key")
# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
# Parse the document as an invoice by passing the appropriate type
result = mindee_client.parse(product.InvoiceV4, input_doc)
# Print a brief summary of the parsed data
print(result.document)
Note: Files can also be loaded from:
A python BinaryIO
compatible file:
input_doc = mindee_client.source_from_file(my_file)
A URL (HTTPS
only):
input_doc = mindee_client.source_from_url("https://files.readme.io/a74eaa5-c8e283b-sample_invoice.jpeg")
A base64-encoded string, making sure to specify the extension of the file name:
input_doc = mindee_client.source_from_b64string(my_input_string, "my-file-name.ext")
Raw bytes, making sure to specify the extension of the file name:
input_doc = mindee_client.source_from_bytes(my_raw_bytes_sequence, "my-file-name.ext")
from mindee import Client, product
# Init a new client
mindee_client = Client(api_key="my-api-key")
# Load a file from disk
input_doc = mindee_client.source_from_path("/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_doc)
# Print a brief summary of the parsed data
print(result.document)
from mindee import Client, product
# Init a new client
mindee_client = Client(api_key="my-api-key")
# Add your custom endpoint (document)
my_endpoint = mindee_client.create_endpoint(
account_name="my-account",
endpoint_name="my-endpoint",
)
# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")
# Parse the file.
# The endpoint must be specified since it cannot be determined from the class.
result = mindee_client.enqueue_and_parse(
product.GeneratedV1,
input_doc,
endpoint=my_endpoint
)
# Print a brief summary of the parsed data
print(result.document)
# Iterate over all the fields in the document
for field_name, field_values in result.document.fields.items():
print(field_name, "=", field_values)
This is an optional way of handling asynchronous APIs.
Options to pass when sending a file.
from mindee import Client, product
from mindee.client import LocalResponse
# Init a new client
mindee_client = Client()
# Load a file from disk
input_source = mindee_client.source_from_path("/path/to/the/file.ext")
# Parse the file
enqueue_response = mindee_client.enqueue(
product.InternationalIdV2,
input_source,
)
# You can keep track of the job's ID for traceability concerns.
job_id = enqueue_response.job.id
# Load the JSON string sent by the Mindee webhook POST callback.
# Reading the callback data will vary greatly depending on your HTTP server.
# This is therefore beyond the scope of this example.
local_response = LocalResponse(request.body())
# You can also load the json from a local path.
# local_response = LocalResponse("path/to/my/file.ext")
# Optional: verify the HMAC signature
if not local_response.is_valid_hmac_signature(my_secret_key, "some signature"):
raise Error("Invalid HMAC signature!")
# Deserialize the response
result = mindee_client.load_prediction(
product.InternationalIdV2,
local_response
)
# Print a full summary of the parsed data in RST format
print(result.document)
Allows sending only certain pages in a PDF.
In this example we only send the first, penultimate and last pages:
from mindee import 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
)
)
Complete details on the working of the library are available in the following guides:
You can view the source code on GitHub.
You can also take a look at the Reference Documentation.
Copyright © Mindee
Available as open source under the terms of the MIT License.
FAQs
Mindee API helper library for Python
We found that mindee demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.