Skip to main content

Microsoft Azure Ink Recognizer Library for Python

Project description

Azure Ink Recognizer client library for Python

Azure Ink Recognizer SDK is an SDK for developers to work with Azure Ink Recognizer Service. The service recognize a collection of ink strokes and return a tree hierarchy of the recognized units, such as lines, words, shapes, as well as the handwriting recognition result of the words.


  • Connect to Azure Ink Recognizer Service
  • Convert collections of ink strokes into HTTP requests
  • Parse HTTP response into ink recognition units

Source code | Package (PyPi) | API reference documentation | Product documentation | Samples

Getting started

Install the package

Install the Azure Cosmos DB client library for Python with pip:

pip install azure-cognitiveservices-inkrecognizer

Prerequisites: You must have an Azure subscription. You must have Python 2.7 or Python 3.5.3+ to use this package. Asynchronous features supports Python 3.5.3+ only.


Please find the URL at Ink Recognizer Rest API documentation

Get credentials

Please follow the instructions on Ink Recognizer.

Key concepts

Implement ink stroke

If you don't have any pre-defined ink point or ink stroke classes, you can either follow the Ink Stroke Interfaces to build your stroke, or build your own class that has all required fields. If you already defined ink strokes yourself, you should feed attributes in your class according to the interfaces.

from azure.cognitiveservices.inkrecognizer import InkStrokeKind

InkPoint = namedtuple("InkPoint", "x y")

class InkStroke():
    def __init__(self,
                 stroke_language=""): = ink_stroke_id
        self.points = ink_points
        self.kind = stroke_kind
        self.language = stroke_language

You can then create a list (or any iterable object) of ink strokes for recognition.

Create a client

Once you got the url for ink recognizer service and an Azure credential instance, you can create an InkRecognizerClient

from azure.cognitiveservices.inkrecognizer import InkRecognizerClient
client = InkRecognizerClient(url, api_key)  # api_key is your key as string

Or use Async version (Python 3.5.3+ only)

from azure.cognitiveservices.inkrecognizer.aio import InkRecognizerClient
client = InkRecognizerClient(url, api_key)  # api_key is your key as string

Send a request

You can then send stroke list to Ink Recognizer Service and get the root of all ink recognition results.

# Sync version
recognition_root = client.recognize_ink(ink_stroke_list)
# Async version
recognition_root = await client.recognize_ink(ink_stroke_list)

Get recognition units from results

You can get all the recognition units either by InkRecognitionUnitKind or by hierarchy, then visit support properties of the units. API reference documentation

lines = recognition_root.lines
for line in lines:
    for word in line.words:


The Samples provide several code snippets covering some of the most common Ink Recognizer SDK tasks, including:

  • Implement InkPoint and InkStroke classes
  • Convert stroke unit from pixel to mm
  • Set language recognition locale
  • Indexing a key word from recognition results
  • Set application kind if user know expected type of ink content



Ink Recognizer clients raise exceptions defined in azure-core. For example, if you try to reach an invalid URL, InkRecognizerClient raises ResourceNotFoundError:

from azure.core.exceptions import ResourceNotFoundError
client = InkRecognizerClient("invalid_url", credential)

except ResourceNotFoundError as e:


Network trace logging is disabled by default for this library. When enabled, HTTP requests will be logged at DEBUG level using the logging library. You can configure logging to print debugging information to stdout or write it to a file:

import sys
import logging

# Create a logger for the 'azure' SDK
logger = logging.getLogger(__name__)

# Configure a console output
handler = logging.StreamHandler(stream=sys.stdout)

# Configure a file output
file_handler = logging.FileHandler(filename)

# Enable network trace logging. Each HTTP request will be logged at DEBUG level.
client = InkRecognizerClient(url=url, credential=credential, logging_enable=True)

Next steps

Please find interactive inking samples at tkinter sample and wxpython sample.

Additional documentation

For more extensive documentation on the Ink Recognizer Service, see the Ink Recognizer Service Documentation.


This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact with any additional questions or comments.


Version 1.0.0b1

Initial version for preview

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

Built Distribution

Supported by

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