Package: sight-api
This repository contains the officialSight APIPython client. The Sight API is a text recognition service.QuickstartInstall the package.pip install sight-apiorpoetry add sight-apietc.Grab an API key from theSight dashboard.Create a client, passing your API key into the constructor, and recognize text:import sight_api

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

pages = client.recognize(['invoice.pdf', 'receipt_1.png'])pageslooks like this:[
    {
        "Error": "",
        "FileIndex": 0,
        "PageNumber": 1,
        "NumberOfPagesInFile": 3,
        "RecognizedText": [ ... ]
    },
    ...
]FileIndexis the index of this file in the original request's "files" array.RecognizedTextlooks like this:"RecognizedText": [
    {
        "Text": "Invoice",
        "Confidence": 0.22863210084975458
        "TopLeftX": 395,
        "TopLeftY": 35,
        "TopRightX": 449,
        "TopRightY": 35,
        "BottomLeftX": 395,
        "BottomLeftY": 47,
        "BottomRightX": 449,
        "BottomRightY": 47,
    },
    ...
]Streaming in ResultsIf you process more than one page in a single.recognize([ ... ])call, results may come in over time, instead of all at once.To access results (pagesobjects) as soon as they come in, there is a generator you can use:for pages in self.recognizeAsGenerator(['invoice.pdf', 'receipt_1.png']):
    print(pages)In fact,.recognize([ ... ])is defined in terms of that generator:class Client:
    ...
    def recognize(self, files):
        ...
        pages = list()
        for ps in self.recognizeAsGenerator(files):
            pages.extend(ps)
        return pagesWord-Level Bounding Boxesclient.recognize(files, words=False)has a parameter,words, which defaults toFalse, but if it's set toTruethen word-level bounding boxes are returned instead of sentence-level bounding boxes.Auto-RotateThe Sight API can rotate and return input images so the majority of the recognized text is upright. Note that this feature is part of the "Advanced" Sight API and therefore each page processed with this behavior enabled is billed as 4 pages. To enable this behavior, call the recognize function with the default parameterautoRotateset toTrue:pages = client.recognize(['invoice.pdf'], autoRotate=True)Now, theBase64Imagefield will be set in the elements ofpages.Why are the bounding boxes are rotated 90 degrees?Some images, particularly .jpeg images, use theEXIFdata format. This data format contains a metadata field indicating the orientation of an image --- i.e., whether the image should be rotated 90 degrees, 180 degrees, flipped horizontally, etc., when viewing it in an image viewer.This means that when you view such an image in Chrome, Firefox, Safari, or the stock Windows and Mac image viewer applications, it will appear upright, despite the fact that the underlying pixels of the image are encoded in a different orientation.If you find your bounding boxes are rotated or flipped relative to your image, it is because the image decoder you are using to load images in your program obeys EXIF orientation, but the Sight API ignores it (or vice versa).All the most popular imaging libraries in Go, such as "image" and "github.com/disintegration/imaging", ignore EXIF orientation. You should determine whether your image decoder obeys EXIF orientation and tell the Sight API to do the same thing. You can tell the Sight API to obey the EXIF orientation by calling the recognize function with the default parameterexifRotateset toTrue:pages = client.recognize(['invoice.pdf'], exifRotate=True)By default, the Sight API ignores EXIF orientation.Official API DocumentationHere is theofficial documentation for the Sight API.Apache V2 LicenseThis code is licensed under Apache V2.0. The full text of the license can be found in the "LICENSE" file.