SDKs overview

Hirak OCR offers a suite of Software Development Kits (SDKs) designed to streamline the integration of its optical character recognition and document processing capabilities into various applications. These SDKs abstract the complexities of direct HTTP requests, authentication, and response parsing, allowing developers to interact with the Hirak OCR API using familiar programming language constructs. The primary goal of these libraries is to reduce development time and effort when implementing features like text extraction from images, document structuring, and specialized processing for invoices and receipts.

The SDKs are maintained by Hirak OCR and are regularly updated to reflect new API features and improvements. They are designed to provide a consistent and reliable interface across different programming environments, supporting common operations such as uploading documents, initiating OCR tasks, retrieving processing results, and handling errors. For a complete understanding of the API's capabilities and available endpoints, developers can consult the official Hirak OCR API reference documentation.

Official SDKs by language

Hirak OCR currently provides official SDKs for Python, Node.js, and Java. These libraries are developed and supported by Hirak OCR to ensure compatibility and optimal performance with their API services.

Language Package Name Install Command Maturity
Python hirak-ocr-python pip install hirak-ocr-python Stable
Node.js @hirak-ocr/nodejs-sdk npm install @hirak-ocr/nodejs-sdk or yarn add @hirak-ocr/nodejs-sdk Stable
Java com.hirak.ocr:java-sdk Add to pom.xml (Maven) or build.gradle (Gradle) Stable

Each SDK is tailored to the idiomatic practices of its respective language, offering a natural developer experience. For detailed usage instructions and method definitions, developers are encouraged to consult the official Hirak OCR documentation.

Installation

Installation procedures vary depending on the programming language and its package management system. Below are the common installation steps for each official SDK:

Python SDK

The Python SDK can be installed using pip, the standard package installer for Python. Python is a widely used language for scripting and backend development, often leveraging libraries for various tasks including data processing and machine learning, as detailed by Google Cloud's Python documentation.

pip install hirak-ocr-python

After installation, the library can be imported into Python scripts:

import hirak_ocr

Node.js SDK

The Node.js SDK is available via npm, the default package manager for Node.js. Node.js is frequently used for building scalable server-side applications and APIs.

npm install @hirak-ocr/nodejs-sdk

Alternatively, if using Yarn:

yarn add @hirak-ocr/nodejs-sdk

To use the SDK in a Node.js application:

const hirakOcr = require('@hirak-ocr/nodejs-sdk'); // For CommonJS
// import hirakOcr from '@hirak-ocr/nodejs-sdk'; // For ES Modules

Java SDK

For Java projects, the Hirak OCR SDK is typically managed through build tools like Maven or Gradle. Java is a robust language often favored for enterprise-level applications and large-scale systems, as noted in Microsoft Learn's Java resources.

Maven

Add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.hirak.ocr</groupId>
    <artifactId>java-sdk</artifactId&n>    <version>1.0.0</version> <!-- Replace with the latest version -->
</dependency>

Gradle

Add the following to your build.gradle file:

implementation 'com.hirak.ocr:java-sdk:1.0.0' // Replace with the latest version

After adding the dependency, you can initialize and use the client in your Java code.

Quickstart example

This section provides a basic quickstart example demonstrating how to use the Hirak OCR SDKs to process a document. The example focuses on uploading an image file and extracting text using the main OCR API. For full code examples and advanced features, refer to the Hirak OCR developer documentation.

Python Quickstart

This example shows how to initialize the client, upload a file, and get the OCR results.

import hirak_ocr
import os

# Initialize the client with your API key
client = hirak_ocr.Client(api_key=os.environ.get("HIRAK_OCR_API_KEY"))

# Path to the document image you want to process
document_path = "./path/to/your/document.png"

try:
    # Upload the document for OCR processing
    print(f"Uploading document: {document_path}")
    response = client.ocr.process_document(file_path=document_path)

    # Check if the processing was successful
    if response.status == "success":
        print("Document processed successfully!")
        print("Extracted Text:")
        for page in response.data.pages:
            print(page.text)
    else:
        print(f"Error processing document: {response.message}")

except hirak_ocr.HirakOcrError as e:
    print(f"An API error occurred: {e.message}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

Node.js Quickstart

This Node.js example demonstrates asynchronous file upload and text extraction.

const hirakOcr = require('@hirak-ocr/nodejs-sdk');
const fs = require('fs');

// Initialize the client with your API key
const client = new hirakOcr.Client({ apiKey: process.env.HIRAK_OCR_API_KEY });

// Path to the document image you want to process
const documentPath = './path/to/your/document.png';

async function processDocument() {
  try {
    // Ensure the file exists
    if (!fs.existsSync(documentPath)) {
      console.error(`Error: Document not found at ${documentPath}`);
      return;
    }

    console.log(`Uploading document: ${documentPath}`);
    const response = await client.ocr.processDocument({ filePath: documentPath });

    if (response.status === 'success') {
      console.log('Document processed successfully!');
      console.log('Extracted Text:');
      response.data.pages.forEach(page => {
        console.log(page.text);
      });
    } else {
      console.error(`Error processing document: ${response.message}`);
    }
  } catch (error) {
    console.error('An error occurred:', error.message);
  }
}

processDocument();

Java Quickstart

This Java example illustrates how to use the SDK to upload a document and retrieve OCR results.

import com.hirak.ocr.Client;
import com.hirak.ocr.models.requests.ProcessDocumentRequest;
import com.hirak.ocr.models.responses.ProcessDocumentResponse;
import com.hirak.ocr.core.HirakOcrException;

import java.io.File;

public class HirakOcrQuickstart {
    public static void main(String[] args) {
        // Initialize the client with your API key from environment variable
        String apiKey = System.getenv("HIRAK_OCR_API_KEY");
        if (apiKey == null || apiKey.isEmpty()) {
            System.err.println("Error: HIRAK_OCR_API_KEY environment variable is not set.");
            return;
        }
        Client client = new Client(apiKey);

        // Path to the document image you want to process
        File documentFile = new File("./path/to/your/document.png");

        if (!documentFile.exists()) {
            System.err.println("Error: Document file not found at " + documentFile.getAbsolutePath());
            return;
        }

        try {
            System.out.println("Uploading document: " + documentFile.getAbsolutePath());
            ProcessDocumentRequest request = new ProcessDocumentRequest.Builder()
                    .setFilePath(documentFile.getAbsolutePath())
                    .build();
            
            ProcessDocumentResponse response = client.ocr.processDocument(request);

            if ("success".equals(response.getStatus())) {
                System.out.println("Document processed successfully!");
                System.out.println("Extracted Text:");
                response.getData().getPages().forEach(page -> {
                    System.out.println(page.getText());
                });
            } else {
                System.err.println("Error processing document: " + response.getMessage());
            }

        } catch (HirakOcrException e) {
            System.err.println("An API error occurred: " + e.getMessage());
        } catch (Exception e) {
            System.err.println("An unexpected error occurred: " + e.getMessage());
        }
    }
}

Community libraries

While Hirak OCR provides official SDKs for Python, Node.js, and Java, the developer community may also contribute open-source libraries or wrappers for additional programming languages or specialized use cases. These community-driven projects are not officially supported or maintained by Hirak OCR but can offer alternative integration paths.

Developers seeking community libraries are advised to search platforms like GitHub or package repositories specific to their desired language. When using community-contributed code, it is important to review the project's documentation, license, and community activity to assess its reliability and security. Users should verify that community libraries are compatible with the latest Hirak OCR API versions and adhere to best practices for secure API key management and data handling. While official SDKs ensure direct compatibility and support, community efforts can sometimes fill gaps or offer unique functionalities not present in official offerings.

For the most up-to-date and authoritative information regarding supported SDKs and integration methods, always refer to the official Hirak OCR documentation portal.