Skip to main content

Framework-neutral Python SDK for building LAREX Action processors.

Project description

LAREX Action SDK

This SDK is work in progress. The public API can still change before LAREX Actions and the SDK are considered stable.

Framework-neutral Python SDK for building LAREX Action processors.

The core package verifies LAREX dispatch requests, parses typed run/input payloads, sends heartbeats, downloads selected files, and uploads result manifests. FastAPI support is available as an optional convenience extra.

Installation

uv add "larex-action-sdk[fastapi]"

For framework-neutral usage only:

uv add larex-action-sdk

FastAPI Processor

import os

from larex_actions import ActionContext
from larex_actions.fastapi import create_larex_action_app


async def process(ctx: ActionContext) -> None:
    action_input = await ctx.pull_input()
    results = ctx.result_builder()

    if action_input.target_selection and action_input.target_selection.type == "TEXT_LINE":
        for target_page in action_input.target_selection.pages:
            for line in target_page.text_lines:
                results.add_text_line_text(
                    page_id=target_page.page_id,
                    text_line_id=line.id,
                    text="recognized text",
                )
        await ctx.complete(results, "Updated selected text lines")
        return

    for page in action_input.pages:
        async with ctx.step(f"Processing {page.name}", progress_percent=25):
            if page.xml:
                xml_bytes = await ctx.download_bytes(page.xml[0])
                results.add_xml_bytes(
                    page_id=page.id,
                    content=xml_bytes,
                    file_name=f"{page.name}-processed.xml",
                )

    await ctx.complete(results, "Done")


app = create_larex_action_app(
    processor_id="my-processor",
    dispatch_secret=os.environ["LAREX_DISPATCH_HMAC_SECRET"],
    handler=process,
)

Target-Aware Runs

LAREX can dispatch page, region, and textline targeted runs. The SDK exposes the requested target on both dispatch and pulled input payloads:

payload_target = ctx.payload.target
action_input = await ctx.pull_input()
input_target = action_input.target

Processors still receive full page files according to the Action YAML inputs. Target metadata contains selected region/textline ids, geometry, and current text; LAREX does not generate crops.

Use ResultBuilder.add_text_line_text(...) for OCR/HTR text patches and ResultBuilder.add_layout_xml_bytes(...) or add_layout_xml_path(...) for layout PAGE XML patches.

Framework-Neutral Dispatch Verification

from larex_actions import DispatchVerifier

payload = DispatchVerifier(
    processor_id="my-processor",
    dispatch_secret=secret,
).verify(
    method=request_method,
    path_and_query=request_path_and_query,
    headers=request_headers,
    body=request_body,
)

You can then pass payload.model_dump(mode="json", by_alias=True) to your own queue/worker system and use ActionClient.from_dispatch(payload) in async workers.

Security

  • Dispatch requests are verified with the X-LAREX-Action-* HMAC headers.
  • Timestamps and nonces are checked to reduce replay risk.
  • The FastAPI adapter rejects dispatch bodies larger than max_dispatch_body_bytes.
  • Per-run bearer secrets and dispatch HMAC secrets are never included in model reprs.
  • Processor YAML must still declare the inputs and outputs LAREX should expose or accept.

Development

uv sync --all-extras
uv run ruff format .
uv run ruff check .
uv run pyright
uv run pytest
uv build

Releases are published with PyPI Trusted Publishing from GitHub Actions. Release candidate tags containing rc publish to TestPyPI; published GitHub releases publish to PyPI.

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

larex_action_sdk-0.2.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

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

larex_action_sdk-0.2.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file larex_action_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: larex_action_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for larex_action_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fb6ab72fef00f163ab5d4be4d47e63ee957bd07d911802db182bc8c41761cf82
MD5 a0ca8559281d6daf9dcb9bf02133e682
BLAKE2b-256 7f229976f707734f3e213d7aa66b0502f66fa69d4db31bca1a3c4be631e4df5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for larex_action_sdk-0.2.0.tar.gz:

Publisher: publish.yml on OCR4all/larex-action-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file larex_action_sdk-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for larex_action_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce37dc686e96b7c364556366ec86a6ca69966f2a77c16340e1d5a073295d9a30
MD5 9b98fe507b792eccd96bdb02bbd6b645
BLAKE2b-256 2e399fe40e73631539c60bb46233e7d6cf130aff6f92081be3a956411f342ea3

See more details on using hashes here.

Provenance

The following attestation bundles were made for larex_action_sdk-0.2.0-py3-none-any.whl:

Publisher: publish.yml on OCR4all/larex-action-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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