Skip to main content

Official Python SDK for the Iteration Layer API

Project description

Iteration Layer Python SDK

Official Python SDK for the Iteration Layer API.

Installation

pip install iterationlayer

Usage

from iterationlayer import IterationLayer

client = IterationLayer(api_key="il_your_api_key")

Document Extraction

Extract structured data from documents using AI.

result = client.extract(
    files=[{"type": "url", "name": "invoice.pdf", "url": "https://example.com/invoice.pdf"}],
    schema={
        "fields": [
            {"type": "TEXT", "name": "company_name", "description": "The company name"},
            {"type": "CURRENCY_AMOUNT", "name": "total", "description": "The invoice total"},
        ]
    },
)

print(result["company_name"]["value"])       # "Acme Corp"
print(result["company_name"]["confidence"])  # 0.95

Image Transformation

Resize, crop, convert, and apply effects to images.

result = client.transform(
    file={"type": "url", "name": "photo.jpg", "url": "https://example.com/photo.jpg"},
    operations=[
        {"type": "resize", "width_in_px": 800, "height_in_px": 600, "fit": "cover"},
        {"type": "convert", "format": "webp", "quality": 85},
    ],
)

import base64
image_bytes = base64.b64decode(result["buffer"])

Image Generation

Compose images from layer definitions.

result = client.generate_image(
    dimensions={"width_in_px": 1200, "height_in_px": 630},
    layers=[
        {"type": "solid-color", "index": 0, "hex_color": "#1a1a2e"},
        {
            "type": "text",
            "index": 1,
            "text": "Hello World",
            "font_name": "Inter",
            "font_size_in_px": 48,
            "text_color": "#ffffff",
            "position": {"x_in_px": 50, "y_in_px": 50},
            "dimensions": {"width_in_px": 1100, "height_in_px": 530},
        },
    ],
    output_format="png",
)

import base64
image_bytes = base64.b64decode(result["buffer"])

Document Generation

Generate PDF, DOCX, EPUB, or PPTX from structured data.

result = client.generate_document(
    format="pdf",
    document={
        "metadata": {"title": "Invoice #123"},
        "page": {
            "size": {"preset": "A4"},
            "margins": {"top_in_pt": 36, "bottom_in_pt": 36, "left_in_pt": 36, "right_in_pt": 36},
        },
        "styles": {
            "text": {"font_family": "Helvetica", "font_size_in_pt": 12, "line_height": 1.5, "color": "#000000"},
            "headline": {"font_family": "Helvetica", "font_size_in_pt": 24, "color": "#000000", "spacing_before_in_pt": 12, "spacing_after_in_pt": 6},
            "link": {"color": "#0066cc"},
            "list": {"indent_in_pt": 18, "spacing_between_items_in_pt": 4},
            "table": {
                "header": {"background_color": "#f0f0f0", "font_family": "Helvetica", "font_size_in_pt": 12, "color": "#000000", "padding_in_pt": 6},
                "body": {"font_family": "Helvetica", "font_size_in_pt": 12, "color": "#000000", "padding_in_pt": 6},
            },
            "grid": {"gap_in_pt": 12},
            "separator": {"color": "#cccccc", "thickness_in_pt": 1, "margin_top_in_pt": 12, "margin_bottom_in_pt": 12},
            "image": {"alignment": "center", "margin_top_in_pt": 8, "margin_bottom_in_pt": 8},
        },
        "content": [
            {"type": "headline", "level": "h1", "text": "Invoice #123"},
            {"type": "paragraph", "markdown": "Thank you for your business."},
        ],
    },
)

import base64
pdf_bytes = base64.b64decode(result["buffer"])

Sheet Generation

Generate CSV, Markdown, or XLSX spreadsheets from structured data.

result = client.generate_sheet(
    format="xlsx",
    sheets=[
        {
            "name": "Invoices",
            "columns": [
                {"name": "Company", "width": 20},
                {"name": "Total", "width": 15},
            ],
            "rows": [
                [
                    {"value": "Acme Corp"},
                    {"value": 1500.50, "format": "currency", "currency_code": "EUR"},
                ],
            ],
        },
    ],
)

import base64
sheet_bytes = base64.b64decode(result["buffer"])

Webhooks (Async)

Use the *_async methods to receive results via webhook instead of waiting for the response.

result = client.extract_async(
    files=[{"type": "url", "name": "invoice.pdf", "url": "https://example.com/invoice.pdf"}],
    schema={
        "fields": [
            {"type": "CURRENCY_AMOUNT", "name": "total", "description": "The invoice total"},
        ]
    },
    webhook_url="https://your-app.com/webhooks/extraction",
)

Context Manager

The client can be used as a context manager to ensure the underlying HTTP connection is closed.

with IterationLayer(api_key="il_your_api_key") as client:
    result = client.extract(...)

Error Handling

from iterationlayer import IterationLayerError

try:
    result = client.extract(...)
except IterationLayerError as e:
    print(e.status_code)     # 422
    print(e.error_message)   # "Validation error: ..."

Documentation

Full documentation is available at https://iterationlayer.com/docs.

Issues & Feedback

Please report bugs and request features in the issues repository.

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

iterationlayer-1.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

iterationlayer-1.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file iterationlayer-1.1.0.tar.gz.

File metadata

  • Download URL: iterationlayer-1.1.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for iterationlayer-1.1.0.tar.gz
Algorithm Hash digest
SHA256 2d7680ebb0aab75984de16f79ae1bd7df1723e74b6e438250b39c0ed355d4a9f
MD5 a6d1adfd66589188937ab12958a327ab
BLAKE2b-256 1d027086d0191a74e4c031604b8179901e5e19f07e2ff6e8a28ad431ad9058a2

See more details on using hashes here.

File details

Details for the file iterationlayer-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: iterationlayer-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for iterationlayer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1912c1a43969aa7d95f786f055715a0c2142a7768534f14583272a7125b4a2e5
MD5 7d7ac0eed0957d7e5799dd0096687365
BLAKE2b-256 2304f4be600f1a93a71f1348b2a70413cda18e0252b07fe8d7d4965a450aa27f

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