Skip to main content

Official client for Siftrics' Sight API, which is a text recognition service

Project description

This repository contains the official Sight API Python client. The Sight API is a text recognition service.

Quickstart

  1. Install the package.
pip install sight-api

or

poetry add sight-api

etc.

  1. Grab an API key from the Sight dashboard.
  2. 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'])

pages looks like this:

[
    {
        "Error": "",
        "FileIndex": 0,
        "PageNumber": 1,
        "NumberOfPagesInFile": 3,
        "RecognizedText": [ ... ]
    },
    ...
]

FileIndex is the index of this file in the original request's "files" array.

RecognizedText looks 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 Results

If 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 (pages objects) 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 pages

Word-Level Bounding Boxes

client.recognize(files, words=False) has a parameter, words, which defaults to False, but if it's set to True then word-level bounding boxes are returned instead of sentence-level bounding boxes.

Auto-Rotate

The 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 parameter autoRotate set to True:

pages = client.recognize(['invoice.pdf'], autoRotate=True)

Now, the Base64Image field will be set in the elements of pages.

Why are the bounding boxes are rotated 90 degrees?

Some images, particularly .jpeg images, use the EXIF data 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 parameter exifRotate set to True:

pages = client.recognize(['invoice.pdf'], exifRotate=True)

By default, the Sight API ignores EXIF orientation.

Official API Documentation

Here is the official documentation for the Sight API.

Apache V2 License

This code is licensed under Apache V2.0. The full text of the license can be found in the "LICENSE" file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sight-api-1.2.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sight_api-1.2.0-py2.py3-none-any.whl (8.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sight-api-1.2.0.tar.gz.

File metadata

  • Download URL: sight-api-1.2.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.8.5 Linux/4.5.1-1-ARCH

File hashes

Hashes for sight-api-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8a159f00d46d55f6d61c7d8d227432bc1ec31852661b9a683b1f9f470e425eee
MD5 7d1e4354ccb852f6b87c84393cad6de9
BLAKE2b-256 0c4481e6e2a8554d74159b4cd699df65e7f80a70e61d84360e274103f479e67c

See more details on using hashes here.

File details

Details for the file sight_api-1.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sight_api-1.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.8.5 Linux/4.5.1-1-ARCH

File hashes

Hashes for sight_api-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0cbe57fd9812840f6b68f7ad42c37eb0554866a5658262ff7c8c76992750faf0
MD5 4413e7e9927978d8e89a3b4a4dfc9954
BLAKE2b-256 10607895ad9d70d721984ef6cb3d763754c1787f2f700f4febbc08c04d7a9986

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page