Skip to main content

A simple SDK for using the Img2Txt API.

Project description

img2txt.io Python Package

A Python Package for the img2txt.io API. Easily upload images and convert them to plain text or structured output programmatically.

Installation

pip install img2txtio

Or install directly from source:

git clone https://github.com/Astro-gram/img2txt-python-package.git
cd img2txt-python-sdk
pip install .

Quick Start

from img2txtio import Img2TxtClient

# Initialize client with your API key
token = "YOUR_API_KEY_HERE"
client = Img2TxtClient(api_key=token)

# Convert an image to plain text
result = client.process(
    image_path="path/to/image.jpg",
    output_type="raw",           # default: raw text
    description="Receipt from grocery",  # optional
    outputStructure=""           # optional JSON string for structured output
)

# `result` is a dict containing the API response
print(result)

API Reference

Class: Img2TxtClient

__init__(api_key: str)

Create a new client instance.

process(image_path: str, output_type: str = "raw", description: str = "", outputStructure: str = "") -> dict

Uploads the image at image_path and converts it to text or structured output.

Parameters:

  • image_path (str): Local path to the image file. Must exist, otherwise raises FileNotFoundError.
  • output_type (str): The output format. Defaults to raw. Other valid types depend on the API (e.g., json, structured).
  • description (str): Optional description or context to improve text extraction.
  • outputStructure (str): Optional JSON string defining a structure/schema for the output. Must be valid JSON or raises ValueError.

Returns:

  • dict: Parsed JSON response from the API. On failure, raises RuntimeError.
  • Example response:
    {
        'text_output': [
            'Los Angeles', 'Florida', '$235', 'Round trip', 'Economy',
            '1 passenger', 'Lowest total price'
        ],
        'job_id': '16e2364a-e1e2-468e-9be9-e07b695b2afd',
        'creditsLeft': 86.115,
        'success': True,
        'message': 'Image processed successfully.'
    }
    

Error Handling

  • Network or HTTP errors raise requests.exceptions.HTTPError.
  • Missing files raise FileNotFoundError.
  • Invalid JSON in outputStructure raises ValueError.
  • API failures raise RuntimeError.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

img2txtio-0.0.4.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

img2txtio-0.0.4-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file img2txtio-0.0.4.tar.gz.

File metadata

  • Download URL: img2txtio-0.0.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for img2txtio-0.0.4.tar.gz
Algorithm Hash digest
SHA256 110f49a7b29d62b34b813ecd9b1e9378554983a988b95bd2062f12cb4cea79f8
MD5 f980bbb4bb38bfddd8e52a3bd8857707
BLAKE2b-256 295a76034839a9b21fb12ef99a6fc1a4f6453e55cf505e95aabefecd4f3e6188

See more details on using hashes here.

File details

Details for the file img2txtio-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: img2txtio-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for img2txtio-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9fbd92db2c7c8db88379f612983f4931f24936f1d814cc2571da56275fe50d0e
MD5 bd1a14561de22a4fdd5c66f848e73bec
BLAKE2b-256 bde90369c17999dad1ae9833c8212fda1a4695a05f34cb3d26204d8780824f4c

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