Package: hydra-api
This repository contains the officialHydra APIPython client. The Hydra API is a text recognition service.QuickstartInstall the package.pip install hydra-apiorpoetry add hydra-apietc.Create a new data source onsiftrics.com.Grab an API key from the page of your newly created data source.Create a client, passing your API key into the constructor.Use the client to processes documents, passing in the id of a data source and the filepaths of the documents.import hydra_api

client = hydra_api.Client('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')

rows = client.recognize('my_data_source_id', ['invoice.pdf', 'receipt_1.png'])rowslooks like this:[
  {
    "Error": "",
    "FileIndex": 0,
    "RecognizedText": { ... }
  },
  ...
]FileIndexis the index of this file in the original request's "files" array.RecognizedTextis a dictionary mapping labels to values. Labels are the titles of the bounding boxes drawn during the creation of the data source. Values are the recognized text inside those bounding boxes.Using Base64 Strings Instead of File PathsThere is another function,client.recognizeBase64(dataSourceId, base64Files, doFaster=False), which accepts base64 strings (file contents) instead of file paths. Because it is not trivial to infer MIME type from the contents of a file, you must specify the MIME type associated to each base64 file string:base64Filesmust be a list ofdictobjects containing two fields:"mimeType"and ``"base64File"`. Example:base64Files = [
        {
            'mimeType': 'image/png',
            'base64File': '...',
        },
        {
            'mimeType': 'application/pdf',
            'base64File': '...',
        },
    ]
    rows = client.recognizeBase64('Helm-Test-Againe', base64Files, doFaster=True)Returning Transformed / Pre-Processed ImagesHydra can transform input documents so they are cropped and aligned with the original image used to create the data source.TherecognizeandrecognizeBase64functions have an additional default parameter,returnTransformedImages, which defaults toFalse, but if it's set toTruethen Siftrics transforms and returns images so they are aligned with the original image.Returned images will be available in the "TransformedImages" field of each element of "Rows" in the response:{
  "Rows": [
    {
      "Error": "",
      "FileIndex": 0,
      "RecognizedText": {
        "My Field 1": "text from your document...",
        "My Field 2": "text from your document...",
        ...
      },
      "TransformedImages": [
        {
          "Base64Image": ...,
          "PageNumber": 1
        },
        ...
      ]
    },
    ...
  ]
}Faster ResultsTherecognizeandrecognizeBase64functions have an additional default parameter,doFaster, which defaults toFalse, but if it's set toTruethen Siftrics processes the documents faster at the risk of lower text recognition accuracy. Experimentally, doFaster=true seems not to affect accuracy when all the documents to be processed have been rotated no more than 45 degrees.Exporting JPGs instead of PNGsTherecognizeandrecognizeBase64functions have additional default parameters,returnJpgs=FalseandjpgQuality=85. IfreturnJpgsis set toTrue, then Siftrics returns cropped images in JPG format instead of PNG format.jpgQualitymust be an integer between 1 and 100 inclusive.Official API DocumentationHere is theofficial documentation for the Hydra API.Apache V2 LicenseThis code is licensed under Apache V2.0. The full text of the license can be found in the "LICENSE" file.