skills/omero-integration/references/scripts.md
The local files in this skill's scripts/ directory are client-side safety
helpers. They are not OMERO.server scripts and are never uploaded
automatically.
Every bundled executable:
argparse;--help without OMERO installed;omero only after argument parsing and only for --execute;OMERO_* variables;.env;finally.Remote helpers require --execute. That flag authorizes a read-only
connection, not broader scope or mutation.
python -B scripts/validate_config.py
python -B scripts/validate_config.py --require-auth --json
By default it performs only local syntax checks. --resolve-host performs DNS
resolution but does not connect to an OMERO port.
Output reports which named variables are present and the authentication mode. It never displays credential values.
Examples of failures:
http://, a path, whitespace, or shell syntax;1..65535;OMERO_SECURE is not a recognized boolean;OMERO_USER/OMERO_PASSWORD is present;--require-auth is used without either a session key or complete password
authentication.Dry run:
python -B scripts/inventory.py \
--object-type Image \
--limit 50 \
--page-size 25
Execute after reviewing endpoint/group/scope:
python -B scripts/inventory.py \
--object-type Image \
--limit 50 \
--page-size 25 \
--group-id 42 \
--execute \
--output ./image-inventory.json
Properties:
obj.id ordering request;-1;--include-names;--overwrite.limit_reached means the requested cap was filled; it does not assert that
more server rows exist.
Dry run:
python -B scripts/export_image_metadata.py \
--image-id 101 \
--image-id 102 \
--max-annotations-per-image 100 \
--max-rois-per-image 100 \
--max-shapes-per-roi 500 \
--output ./selected-image-metadata.json
Execute:
python -B scripts/export_image_metadata.py \
--image-id 101 \
--image-id 102 \
--group-id 42 \
--execute \
--output ./selected-image-metadata.json
Default redactions:
Optional inclusion flags are independent. The helper never retrieves pixels or
FileAnnotation bytes. It uses the currently documented IRoi.findByImage
pattern and records that IRoi is deprecated.
Because findByImage has no page argument, the ROI caps bound serialization
but may not bound server-side assembly. Do not run it on a known extreme image
without reviewing the ROI count or using a site-approved paginated API.
The planner is always local and has no --execute.
Import scan plan:
python -B scripts/plan_transfer.py import \
--target Dataset:id:42 \
--max-files 100 \
--scan-depth 4 \
./explicit-input
It walks only explicit paths, does not follow directory symlinks, caps depth
and file count, and proposes omero import -f plus a future scoped import
command. It does not invoke either.
Per-image export plan:
python -B scripts/plan_transfer.py export \
--format ome-tiff \
--output-dir ./reviewed-existing-directory \
Image:101 Image:102
It accepts explicit Image:<id> selectors only, proposes one output per image,
and reports collisions. Dataset iteration is intentionally excluded because
the official export mode is experimental and too easy to broaden.
Global --output and --overwrite arguments must precede the subcommand:
python -B scripts/plan_transfer.py \
--output ./transfer-plan.json \
import ./explicit-input
No proposed command includes -w, --password, -k, or a session value.
No real OMERO server is needed:
PYTHONDONTWRITEBYTECODE=1 \
python -B -m unittest discover \
-s skills/omero-integration/tests \
-p "test_*.py"
The tests use temporary directories and fake gateway objects.
OMERO.server scripts are Python plugins registered with the Script Service. Clients can launch them and receive typed outputs. Inputs often include an explicit data type, object IDs, thresholds, or options.
A minimal structure:
import omero
import omero.scripts as scripts
from omero.gateway import BlitzGateway
from omero.rtypes import rlong, rstring
def main():
client = scripts.client(
"Bounded_Image_Summary.py",
"Returns IDs for an explicit bounded image list.",
scripts.List(
"Image_IDs",
optional=False,
description="Explicit image IDs (maximum enforced by script)",
).ofType(rlong(0)),
namespaces=[omero.constants.namespaces.NSDYNAMIC],
version="1.0",
)
try:
inputs = client.getInputs(unwrap=True)
image_ids = list(inputs["Image_IDs"])
if not 1 <= len(image_ids) <= 25:
raise ValueError("Image_IDs must contain 1..25 IDs")
conn = BlitzGateway(client_obj=client)
found = []
for image_id in image_ids:
image = conn.getObject("Image", image_id)
if image is not None:
found.append(image.getId())
client.setOutput("Message", rstring(f"Found {len(found)} images"))
finally:
client.closeSession()
if __name__ == "__main__":
main()
The script session is supplied by OMERO. Do not read a password or create a second login inside a server script.
Even a server script that only reads can be expensive. It must enforce:
client.closeSession() in finally.For writes, additionally require an explicit “save” input or other reviewed gate and document every created/linked object. A client-side confirmation is not enough if the server script itself accepts unbounded inputs.
Do not use Python eval() or exec() for parameters. Do not interpolate
parameter text into HQL, filesystem paths, commands, or table conditions.
Uploading registers executable code and is a mutation:
omero script upload ./Bounded_Image_Summary.py
omero script list
Before upload:
Launching is also a remote operation:
omero script launch <SCRIPT_ID> Image_IDs=101,102
Use an already prompted session. Confirm the exact script ID, version, group, input IDs, expected writes, and resource limits. Never launch based only on a script display name.
Server scripts may return strings, objects, images, or FileAnnotations. For a file output:
finally;Do not place server paths, credentials, session IDs, or stack traces in client outputs.
IRoi/other deprecated service dependencies documented