Skill Tracer
Skills › Scientific Agent Skills › omero-integration › connection.md

connection.md

308 lines · skills/omero-integration/references/connection.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# Connection, Sessions, and Transport Security
2
3This reference is current for the skill snapshot dated 2026-09-30. It uses
4`omero-py==5.22.1` and the OMERO.server 5.6.18 documentation.
5

Connection, Sessions, and Transport Security

This reference is current for the skill snapshot dated 2026-09-30. It uses omero-py==5.22.1 and the OMERO.server 5.6.18 documentation.

Raw lines 1 to 5
6## Compatibility Before Credentials
7
8OMERO.server and its Python, web, Java, Bio-Formats, and Ice components have
9independent release numbers. Do not compare their version strings as if they
10were one package.
12For the current stable pairing:
14- OMERO.server 5.6.18 was tested with OMERO.py 5.22.1 and OMERO.web 5.31.0.
15- `omero-py==5.22.1` declares Python `>=3.10`.
16- The OMERO matrix supports Python 3.10/3.11 and recommends 3.12.
17- Python 3.13/3.14 are listed as upcoming, not supported.
18- Ice 3.6 is recommended; Ice 3.7 is unsupported.
19- The OMERO-linked Glencoe wheel matrix provides IcePy 3.6.5 wheels through
20 Python 3.12 for documented platforms.
22OMERO.py 5.23.0 is the newer client release; local API checks for this refresh
23used it with IcePy 3.6.5. The historical server-tested pairing above remains
245.22.1; a local import or CLI help check does not establish server compatibility.
26For a different server release, read that release's history entry and use its
27tested OMERO.py version. A newest-client/old-server pairing may appear to work
28but is not the documented compatibility guarantee.

Compatibility Before Credentials

OMERO.server and its Python, web, Java, Bio-Formats, and Ice components have independent release numbers. Do not compare their version strings as if they were one package.

For the current stable pairing:

  • OMERO.server 5.6.18 was tested with OMERO.py 5.22.1 and OMERO.web 5.31.0.
  • omero-py==5.22.1 declares Python >=3.10.
  • The OMERO matrix supports Python 3.10/3.11 and recommends 3.12.
  • Python 3.13/3.14 are listed as upcoming, not supported.
  • Ice 3.6 is recommended; Ice 3.7 is unsupported.
  • The OMERO-linked Glencoe wheel matrix provides IcePy 3.6.5 wheels through Python 3.12 for documented platforms.

OMERO.py 5.23.0 is the newer client release; local API checks for this refresh used it with IcePy 3.6.5. The historical server-tested pairing above remains 5.22.1; a local import or CLI help check does not establish server compatibility.

For a different server release, read that release's history entry and use its tested OMERO.py version. A newest-client/old-server pairing may appear to work but is not the documented compatibility guarantee.

Raw lines 6 to 29
30## Installation
32Use an isolated Python 3.12 environment and a platform-matched Ice wheel:
34```bash
35uv venv --python 3.12 .venv
36source .venv/bin/activate
38# Obtain the matching wheel from the OMERO-linked Ice binary matrix.
39uv pip install "/absolute/path/to/zeroc_ice-3.6.5-<matching-tags>.whl"
40uv pip install "omero-py==5.22.1"
41```
43Wheel tags must match all of:
45- CPython version (`cp310`, `cp311`, or `cp312`)
46- operating system
47- architecture
48- platform compatibility tags
50Do not silently fall back to compiling IcePy if the wheel is rejected. Inspect
51the interpreter and platform first. Do not install Ice 3.7 as a substitute.
53`OMERODIR` is required for some CLI configuration and must point to a
54compatible extracted OMERO.server tree to enable import and admin commands.
55It is not required merely to use BlitzGateway against a remote server.

Installation

Use an isolated Python 3.12 environment and a platform-matched Ice wheel:

uv venv --python 3.12 .venv
source .venv/bin/activate

# Obtain the matching wheel from the OMERO-linked Ice binary matrix.
uv pip install "/absolute/path/to/zeroc_ice-3.6.5-<matching-tags>.whl"
uv pip install "omero-py==5.22.1"

Wheel tags must match all of:

  • CPython version (cp310, cp311, or cp312)
  • operating system
  • architecture
  • platform compatibility tags

Do not silently fall back to compiling IcePy if the wheel is rejected. Inspect the interpreter and platform first. Do not install Ice 3.7 as a substitute.

OMERODIR is required for some CLI configuration and must point to a compatible extracted OMERO.server tree to enable import and admin commands. It is not required merely to use BlitzGateway against a remote server.

Raw lines 30 to 56
Runs code bin/activate :36
57## Named Configuration
59The bundled helpers read exactly these variables:
61- `OMERO_HOST`: required hostname, without `http://`, `https://`, or path
62- `OMERO_PORT`: optional integer, default `4064`
63- `OMERO_USER`: username for password authentication
64- `OMERO_PASSWORD`: password for password authentication
65- `OMERO_SESSION_KEY`: existing session key, alternative to user/password
66- `OMERO_SECURE`: boolean, default `true`
68Rules:
701. Never crawl for `.env` files or read unrelated environment variables.
712. Never accept a password/session key as a command argument.
723. Never print an environment dump, password, or session key.
734. Treat a session key as a bearer credential and expire/logout when finished.
745. Prefer a secret manager or process-scoped environment over shell history.

Named Configuration

The bundled helpers read exactly these variables:

  • OMERO_HOST: required hostname, without http://, https://, or path
  • OMERO_PORT: optional integer, default 4064
  • OMERO_USER: username for password authentication
  • OMERO_PASSWORD: password for password authentication
  • OMERO_SESSION_KEY: existing session key, alternative to user/password
  • OMERO_SECURE: boolean, default true

Rules:

  1. Never crawl for .env files or read unrelated environment variables.
  2. Never accept a password/session key as a command argument.
  3. Never print an environment dump, password, or session key.
  4. Treat a session key as a bearer credential and expire/logout when finished.
  5. Prefer a secret manager or process-scoped environment over shell history.
Raw lines 57 to 75
76## Password Connection
78Use `try/finally` when connection success must be checked explicitly:
80```python
81import os
82from omero.gateway import BlitzGateway
84conn = BlitzGateway(
85 os.environ["OMERO_USER"],
86 os.environ["OMERO_PASSWORD"],
87 host=os.environ["OMERO_HOST"],
88 port=int(os.environ.get("OMERO_PORT", "4064")),
89 secure=True,
92try:
93 if not conn.connect():
94 raise RuntimeError("OMERO connection failed")
96 # Keep reads bounded and group-scoped.
97 for image in conn.getObjects(
98 "Image",
99 opts={"limit": 25, "offset": 0, "order_by": "obj.id"},
100 ):
101 print(image.getId())
102finally:
103 conn.close()
104```
106BlitzGateway can also be a context manager. Its context manager calls
107`connect()` and closes the underlying client:
109```python
110import os
111from omero.gateway import BlitzGateway
113with BlitzGateway(
114 os.environ["OMERO_USER"],
115 os.environ["OMERO_PASSWORD"],
116 host=os.environ["OMERO_HOST"],
117 port=int(os.environ.get("OMERO_PORT", "4064")),
118 secure=True,
119) as conn:
120 for project in conn.getObjects(
121 "Project",
122 opts={"limit": 10, "offset": 0, "order_by": "obj.id"},
123 ):
124 print(project.getId())
125```
127Do not catch an exception merely to print its full representation: connection
128errors may include endpoint or identity details. Report the exception class
129and a scrubbed message; never include credential values.

Password Connection

Use try/finally when connection success must be checked explicitly:

import os
from omero.gateway import BlitzGateway

conn = BlitzGateway(
    os.environ["OMERO_USER"],
    os.environ["OMERO_PASSWORD"],
    host=os.environ["OMERO_HOST"],
    port=int(os.environ.get("OMERO_PORT", "4064")),
    secure=True,
)

try:
    if not conn.connect():
        raise RuntimeError("OMERO connection failed")

    # Keep reads bounded and group-scoped.
    for image in conn.getObjects(
        "Image",
        opts={"limit": 25, "offset": 0, "order_by": "obj.id"},
    ):
        print(image.getId())
finally:
    conn.close()

BlitzGateway can also be a context manager. Its context manager calls connect() and closes the underlying client:

import os
from omero.gateway import BlitzGateway

with BlitzGateway(
    os.environ["OMERO_USER"],
    os.environ["OMERO_PASSWORD"],
    host=os.environ["OMERO_HOST"],
    port=int(os.environ.get("OMERO_PORT", "4064")),
    secure=True,
) as conn:
    for project in conn.getObjects(
        "Project",
        opts={"limit": 10, "offset": 0, "order_by": "obj.id"},
    ):
        print(project.getId())

Do not catch an exception merely to print its full representation: connection errors may include endpoint or identity details. Report the exception class and a scrubbed message; never include credential values.

Raw lines 76 to 130
131## Existing Session
133`BlitzGateway.connect()` accepts `sUuid`, the existing session UUID:
135```python
136import os
137from omero.gateway import BlitzGateway
139conn = BlitzGateway(
140 host=os.environ["OMERO_HOST"],
141 port=int(os.environ.get("OMERO_PORT", "4064")),
142 secure=True,
145try:
146 if not conn.connect(sUuid=os.environ["OMERO_SESSION_KEY"]):
147 raise RuntimeError("Could not join the OMERO session")
148 print(conn.getEventContext().groupId)
149finally:
150 conn.close(hard=False) # Release this client without killing a shared session.
151```
153`close()` defaults to `hard=True`, which kills the session regardless of
154reference count. Use `close(hard=False)` for a joined session and reserve hard
155closure for a session this client created. The gateway context manager uses
156hard closure, so it is unsuitable for a borrowed session.
158Joining a session does not make it safe to log the key. If a low-level
159`omero.client` is supplied through `BlitzGateway(client_obj=client)`, the
160gateway does not necessarily own every other use of that client. Close it only
161when ownership is clear; the official context-manager example is appropriate
162when nothing else uses the client.

Existing Session

BlitzGateway.connect() accepts sUuid, the existing session UUID:

import os
from omero.gateway import BlitzGateway

conn = BlitzGateway(
    host=os.environ["OMERO_HOST"],
    port=int(os.environ.get("OMERO_PORT", "4064")),
    secure=True,
)

try:
    if not conn.connect(sUuid=os.environ["OMERO_SESSION_KEY"]):
        raise RuntimeError("Could not join the OMERO session")
    print(conn.getEventContext().groupId)
finally:
    conn.close(hard=False)  # Release this client without killing a shared session.

close() defaults to hard=True, which kills the session regardless of reference count. Use close(hard=False) for a joined session and reserve hard closure for a session this client created. The gateway context manager uses hard closure, so it is unsuitable for a borrowed session.

Joining a session does not make it safe to log the key. If a low-level omero.client is supplied through BlitzGateway(client_obj=client), the gateway does not necessarily own every other use of that client. Close it only when ownership is clear; the official context-manager example is appropriate when nothing else uses the client.

Raw lines 131 to 163
164## CLI Login Without a Password Argument
166The CLI stores sessions locally. Let it prompt:
168```bash
169omero login -s "$OMERO_HOST" -p "$OMERO_PORT" -u "$OMERO_USER"
170omero sessions list
171omero sessions file
172omero logout
173```
175Do not use `-w` or `--password`. Although the CLI supports
176`OMERO_PASSWORD`, avoid putting the secret in a persistent shell profile.
178The CLI also supports joining a session with `-k`, but entering a session key
179on the command line exposes it in shell history and process listings. Prefer a
180short-lived, protected workflow and never paste the key into logs.
182By default, session files are under `~/omero/sessions`. `OMERO_USERDIR` or
183`OMERO_SESSIONDIR` can change the location. Protect any custom directory with
184user-only permissions and remove stale sessions with `omero logout`.

CLI Login Without a Password Argument

The CLI stores sessions locally. Let it prompt:

omero login -s "$OMERO_HOST" -p "$OMERO_PORT" -u "$OMERO_USER"
omero sessions list
omero sessions file
omero logout

Do not use -w or --password. Although the CLI supports OMERO_PASSWORD, avoid putting the secret in a persistent shell profile.

The CLI also supports joining a session with -k, but entering a session key on the command line exposes it in shell history and process listings. Prefer a short-lived, protected workflow and never paste the key into logs.

By default, session files are under ~/omero/sessions. OMERO_USERDIR or OMERO_SESSIONDIR can change the location. Protect any custom directory with user-only permissions and remove stale sessions with omero logout.

Raw lines 164 to 185
186## Group Context
188The default connection group comes from the session event context:
190```python
191ctx = conn.getEventContext()
192print(ctx.groupId) # Avoid printing the session ID.
193```
195Set one explicit accessible group before scoped queries:
197```python
198group_id = 42
199conn.SERVICE_OPTS.setOmeroGroup(str(group_id))
200```
202`-1` requests cross-group behavior. It is not a harmless convenience:
204```python
205# Only after the user explicitly requests all accessible groups:
206conn.SERVICE_OPTS.setOmeroGroup("-1")
207```
209Do not set `-1` by default, and do not combine it with an unbounded query.
210Gateway methods such as `getObject()` apply `SERVICE_OPTS`; direct service
211methods do not add it automatically. Pass it as the final Ice context argument,
212for example `conn.getRoiService().findByImage(image_id, None, conn.SERVICE_OPTS)`.
213An `opts={"group": ...}` argument to `getObjects()` is not a general group
214filter. Use `SERVICE_OPTS` for the selected group.
216Record the original group if temporarily changing context and restore it
217before subsequent writes.
219The CLI can switch its current session group:
221```bash
222omero group list
223omero sessions group 42
224```
226Confirm the target group before import, link creation, table writes, ownership
227changes, or script execution.

Group Context

The default connection group comes from the session event context:

ctx = conn.getEventContext()
print(ctx.groupId)  # Avoid printing the session ID.

Set one explicit accessible group before scoped queries:

group_id = 42
conn.SERVICE_OPTS.setOmeroGroup(str(group_id))

-1 requests cross-group behavior. It is not a harmless convenience:

# Only after the user explicitly requests all accessible groups:
conn.SERVICE_OPTS.setOmeroGroup("-1")

Do not set -1 by default, and do not combine it with an unbounded query. Gateway methods such as getObject() apply SERVICE_OPTS; direct service methods do not add it automatically. Pass it as the final Ice context argument, for example conn.getRoiService().findByImage(image_id, None, conn.SERVICE_OPTS). An opts={"group": ...} argument to getObjects() is not a general group filter. Use SERVICE_OPTS for the selected group.

Record the original group if temporarily changing context and restore it before subsequent writes.

The CLI can switch its current session group:

omero group list
omero sessions group 42

Confirm the target group before import, link creation, table writes, ownership changes, or script execution.

Raw lines 186 to 228
229## What `secure=True` Does
231Official OMERO security documentation distinguishes authentication from later
232traffic:
234- Login and password changes use SSL by default.
235- After login, other traffic is unencrypted by default for performance.
236- In that mode, the session ID is the critical value sent in clear text.
237- `BlitzGateway(..., secure=True)` requests encryption for all transfers.
238- Servers can redirect/disable insecure connections.
239- Default router ports are 4063 (insecure) and 4064 (SSL), but admins may
240 change or prefix them.
241- OMERO.web HTTPS normally uses port 443 and is a separate transport path.
243Therefore, default to `secure=True` and the administrator-provided SSL router
244port. Do not infer security merely from the number `4064`.

What secure=True Does

Official OMERO security documentation distinguishes authentication from later traffic:

  • Login and password changes use SSL by default.
  • After login, other traffic is unencrypted by default for performance.
  • In that mode, the session ID is the critical value sent in clear text.
  • BlitzGateway(..., secure=True) requests encryption for all transfers.
  • Servers can redirect/disable insecure connections.
  • Default router ports are 4063 (insecure) and 4064 (SSL), but admins may change or prefix them.
  • OMERO.web HTTPS normally uses port 443 and is a separate transport path.

Therefore, default to secure=True and the administrator-provided SSL router port. Do not infer security merely from the number 4064.

Raw lines 229 to 245
246## Certificate and Host Verification
248Encryption is not the same as server identity verification. OME explicitly
249states that standard OMERO clients do not automatically verify the host, so a
250man-in-the-middle attack remains possible without additional configuration.
252The official developer guidance lists these Ice properties for certificate
253validation:
255- `IceSSL.Ciphers=HIGH` (or a supported explicit cipher family)
256- `IceSSL.VerifyPeer=1`
257- `IceSSL.VerifyDepthMax=0`
258- `IceSSL.UsePlatformCAs=1`, or `IceSSL.CAs=/path/to/cacert.pem`
259- `IceSSL.CheckCertName=1` for exact hostname checking
260- `IceSSL.TrustOnly=...` for documented alternative name restrictions
261- optionally `IceSSL.Protocols=tls1_2` if required by server policy
263These are site-specific low-level client settings. Do not invent them from a
264hostname or disable verification to make a connection succeed. Ask the OMERO
265administrator for the CA, expected certificate name, router port, and policy.
266The bundled helpers enforce encrypted transport by default but do not claim to
267configure hostname verification.
269For OMERO.web, use an administrator-managed HTTPS deployment with a recognized
270certificate. Never send JSON API credentials over plain HTTP.

Certificate and Host Verification

Encryption is not the same as server identity verification. OME explicitly states that standard OMERO clients do not automatically verify the host, so a man-in-the-middle attack remains possible without additional configuration.

The official developer guidance lists these Ice properties for certificate validation:

  • IceSSL.Ciphers=HIGH (or a supported explicit cipher family)
  • IceSSL.VerifyPeer=1
  • IceSSL.VerifyDepthMax=0
  • IceSSL.UsePlatformCAs=1, or IceSSL.CAs=/path/to/cacert.pem
  • IceSSL.CheckCertName=1 for exact hostname checking
  • IceSSL.TrustOnly=... for documented alternative name restrictions
  • optionally IceSSL.Protocols=tls1_2 if required by server policy

These are site-specific low-level client settings. Do not invent them from a hostname or disable verification to make a connection succeed. Ask the OMERO administrator for the CA, expected certificate name, router port, and policy. The bundled helpers enforce encrypted transport by default but do not claim to configure hostname verification.

For OMERO.web, use an administrator-managed HTTPS deployment with a recognized certificate. Never send JSON API credentials over plain HTTP.

Raw lines 246 to 271
272## Stateful Services and Reconnection
274BlitzGateway reuses stateless `get...Service()` proxies. Stateful services such
275as rendering engines, raw stores, thumbnail stores, tables, and other
276`create...` services should be created, used, and closed in the shortest
277practicable scope.
279Gateway recovery may recreate its own services after a connection failure.
280Client-held stateful proxies can then be stale. Do not retain them across long
281idle periods or reconnects.
283Generic pattern:
285```python
286store = conn.createRawFileStore()
287try:
288 store.setFileId(original_file_id, conn.SERVICE_OPTS)
289 # Perform one explicitly bounded read.
290finally:
291 store.close()
292```
294Closing the gateway is still mandatory even if every stateful child was closed.

Stateful Services and Reconnection

BlitzGateway reuses stateless get...Service() proxies. Stateful services such as rendering engines, raw stores, thumbnail stores, tables, and other create... services should be created, used, and closed in the shortest practicable scope.

Gateway recovery may recreate its own services after a connection failure. Client-held stateful proxies can then be stale. Do not retain them across long idle periods or reconnects.

Generic pattern:

store = conn.createRawFileStore()
try:
    store.setFileId(original_file_id, conn.SERVICE_OPTS)
    # Perform one explicitly bounded read.
finally:
    store.close()

Closing the gateway is still mandatory even if every stateful child was closed.

Raw lines 272 to 295
296## Connection Failure Checklist
298Without exposing credentials:
3001. Validate `OMERO_HOST` has no URL scheme/path and `OMERO_PORT` is in range.
3012. Confirm the server release and tested OMERO.py pairing.
3023. Confirm Python and Ice wheel tags match.
3034. Confirm the SSL router port and `secure=True`.
3045. Confirm the account is active and has access to the selected group.
3056. For an existing session, confirm it is still valid without printing it.
3067. For certificate verification, confirm CA and expected certificate name.
3078. Close the failed connection before retrying.
3089. Do not retry authentication in a tight loop; server throttling may apply.

Connection Failure Checklist

Without exposing credentials:

  1. Validate OMERO_HOST has no URL scheme/path and OMERO_PORT is in range.
  2. Confirm the server release and tested OMERO.py pairing.
  3. Confirm Python and Ice wheel tags match.
  4. Confirm the SSL router port and secure=True.
  5. Confirm the account is active and has access to the selected group.
  6. For an existing session, confirm it is still valid without printing it.
  7. For certificate verification, confirm CA and expected certificate name.
  8. Close the failed connection before retrying.
  9. Do not retry authentication in a tight loop; server throttling may apply.
Raw lines 296 to 308