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 with signed dispatch verification, typed payloads, and cooperative run cancellation.
The core package verifies LAREX dispatch requests, parses typed run/input payloads, sends heartbeats, downloads selected files, uploads result manifests, and helps processors acknowledge cancellation cleanly. 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()
for page in action_input.pages:
async with ctx.step(f"Processing {page.name}", progress_percent=25):
await ctx.check_cancelled()
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 only. LAREX sends full page images/XML and lets processors resolve geometry from PAGE XML, including whether to crop, mask, pad, deskew, or process the full image.
Processors return normal PAGE XML via ResultBuilder.add_xml_bytes(...) or
add_xml_path(...). For region or textline targeted runs, LAREX imports only the
selected target scope from the returned PAGE XML.
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.
Cooperative Cancellation
LAREX cancellation is cooperative. The processor keeps polling the heartbeat
endpoint and LAREX responds with cancelRequested: true when the run should stop.
- Use
await ctx.check_cancelled()at safe interruption points. ctx.check_cancelled()performs a heartbeat request, so avoid calling it in a hot inner loop without pacing.await ctx.heartbeat(..., raise_on_cancel=True)also raisesActionCancelledwhen a cancellation is pending.await ctx.run_subprocess(...)polls for cancellation while a child process is running, sends a finalstatus="cancelled"heartbeat, and terminates the child process gracefully before escalating tokill.- Once cancellation has been requested, the SDK refuses result uploads and acknowledges cancellation instead.
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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file larex_action_sdk-0.6.0.tar.gz.
File metadata
- Download URL: larex_action_sdk-0.6.0.tar.gz
- Upload date:
- Size: 34.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3171e2e3ad685cab042857ac18adc0e45f120ac941ea0b235bd0f3d22ddfae1e
|
|
| MD5 |
5224b11f1d7fba6caf4e3d429cfa7dcc
|
|
| BLAKE2b-256 |
92e0e70550c1b547ffaeeffcfdc5aa1a9f880bbbc39d5d2efebaed5507ff34c0
|
Provenance
The following attestation bundles were made for larex_action_sdk-0.6.0.tar.gz:
Publisher:
publish.yml on OCR4all/larex-action-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
larex_action_sdk-0.6.0.tar.gz -
Subject digest:
3171e2e3ad685cab042857ac18adc0e45f120ac941ea0b235bd0f3d22ddfae1e - Sigstore transparency entry: 1708235003
- Sigstore integration time:
-
Permalink:
OCR4all/larex-action-sdk@fb4e9214f1c4f9f8580e787477234a7eff7c3fb9 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/OCR4all
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb4e9214f1c4f9f8580e787477234a7eff7c3fb9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file larex_action_sdk-0.6.0-py3-none-any.whl.
File metadata
- Download URL: larex_action_sdk-0.6.0-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af2ecea5fc593fe56058c371d14fb90b5518c0f85d831a288240f80dc1803e42
|
|
| MD5 |
7186ccc1d3593924b2308cfc5454c806
|
|
| BLAKE2b-256 |
436d43523ae7709c2a0a735c735b1a91b737962e23298851c8a0a7893a0d7012
|
Provenance
The following attestation bundles were made for larex_action_sdk-0.6.0-py3-none-any.whl:
Publisher:
publish.yml on OCR4all/larex-action-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
larex_action_sdk-0.6.0-py3-none-any.whl -
Subject digest:
af2ecea5fc593fe56058c371d14fb90b5518c0f85d831a288240f80dc1803e42 - Sigstore transparency entry: 1708235040
- Sigstore integration time:
-
Permalink:
OCR4all/larex-action-sdk@fb4e9214f1c4f9f8580e787477234a7eff7c3fb9 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/OCR4all
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb4e9214f1c4f9f8580e787477234a7eff7c3fb9 -
Trigger Event:
release
-
Statement type: