A set of python tools to ease Orthanc scripting.
Functionalities are very limited now ! Backward compat will break a lot in the near future !
pip3 install orthanc-toolsThe cloners copies everything that is currently in the source Orthanc into the destination Orthanc and, once this is done continues the cloning process for every DICOM instance that is received by the source.
from a python script:
from orthanc_tools import OrthancCloner, ClonerMode
from orthanc_api_client import OrthancApiClient
orthanc_a = OrthancApiClient('http://localhost:8042', user='orthanc', pwd='orthanc')
orthanc_b = OrthancApiClient('http://localhost:8043', user='orthanc', pwd='orthanc')
cloner = OrthancCloner(source=orthanc_a, destination=orthanc_b)
cloner.execute(existing_changes_only=False)
# if the destination is declared as a peer:
cloner = OrthancCloner(source=orthanc_a, destination_peer='orthanc-b', mode=ClonerMode.TRANSFER)
cloner.execute(existing_changes_only=False)from a shell:
python3 -m orthanc_tools.orthanc_cloner --source_url=http://192.168.0.10:8042 --source_user=user --source_pwd=pwd --dest_url=http://192.168.0.10:8042 --dest_user=user --dest_pwd=pwd --timezone=Europe/Paris --run_schedule='{"Monday-Friday": ["0-7", "18-24"], "Saturday-Sunday": ["0-24"]}'or, inside a docker-compose file:
services:
orthanc-cloner:
image: orthancteam/python-orthanc-tools:0.19.1
volumes: ["orthanc-cloner:/status"]
environment:
TZ: "Etc/UTC"
RUN_SCHEDULE: '{"Monday-Friday": ["0-7", "18-24"], "Saturday-Sunday": ["0-24"]}'
SOURCE_URL: "http://orthanc-a:8042"
# SOURCE_USER: "user"
# SOURCE_PWD: "pwd"
DEST_URL: "http://orthanc-b:8042"
# DEST_USER: "user"
# DEST_PWD: "pwd"
MODE: "Default"
PERSIST_STATE_PATH: "/status/status.txt"
WORKER_THREADS_COUNT: "6"
# VERBOSE_ENABLED: "true"
ERROR_FOLDER_PATH: "/status"
MAX_RETRIES: "3"
entrypoint: python -m orthanc_tools.orthanc_cloner
volumes:
orthanc-cloner:
Here are a set of measures performed during a long transfer between 2 VMs running on Azure using OrthancCloner v 0.6.3.
The source Orthanc (v1.9.0) is running on a 4 vCPU VM with 16GB RAM. Postgresql is running on the same VM and DICOM files are stored on data disks are attached to the VM.
The destination Orthanc (v1.11.2) is running on a 4 vCPU VM with 16GB RAM. It is using a flexible managed Postgresql server and an object storage to store DICOM files.
| Cloner Mode | WorkersThreadCount | throughput [GB/h] | throughput [instances/h] |
|---|---|---|---|
| Default | 12 | 38 | ? |
| Default | 18 | 67 | 142.000 |
| Default | 24 | 66 | 160.000 |
| Transfer, Transfers.Threads=6, ConcurrentJobs=2 | 3 | 20 | ? |
| Transfer, Transfers.Threads=6, ConcurrentJobs=12 | 6 | 15 | ? |
$ docker exec -it xxxx bash
/# pip3 install orthanc-tools
/# python3 -m orthanc_tools.orthanc_folder_importer --folder_path=/import --url=http://localhost:8042 --user=test --password=test --skip_extensions=.cne,.bmp,.ini --worker_threads_count=5
The forwarder forwards the content of an Orthanc to one or more destinations and then deletes
the source instances after every eligible destination has succeeded. This is useful for, e.g. implementing an Inbox in front of a PACS that does some
IngestTranscoding and/or applies sanitization in a lua script or a python plugin.
When using --trigger=StableStudy, forwarding starts only after Orthanc reports a study as stable.
Set StableAge on the source Orthanc to control how long it waits after the last received instance.
From a shell, for one destination:
python3 -m orthanc_tools.orthanc_forwarder --source_url=http://192.168.0.10:8042 --source_user=user --source_pwd=pwd --destination=target_modality_alias --trigger=StableStudyRepeat --destination, or use a comma-separated DESTINATIONS environment variable, to forward to
multiple destinations. Each entry accepts an optional mode and a case-insensitive StudyDescription
filter:
python3 -m orthanc_tools.orthanc_forwarder \
--source_url=http://localhost:8042 \
--destination=archive:dicom \
--destination=rtg:dicom:substring:RTG \
--destination='ai:dicom:regex:^AI[ _-]' \
--trigger=StableStudyThe entry format is alias[:mode[:substring|regex:pattern]]. An empty mode uses the global MODE,
for example rtg::substring:RTG. Quote an entry if its pattern contains a comma. A missing
StudyDescription does not match a filtered destination.
For Docker Compose, the equivalent configuration is:
environment:
SOURCE_URL: http://orthanc:8042
DESTINATIONS: archive:dicom,rtg:dicom:substring:RTG
TRIGGER: StableStudy
HEARTBEAT_FILE: /tmp/forwarder-heartbeat
FAILURE_ALERT_AFTER: "1800"
healthcheck:
test:
- CMD-SHELL
- >-
find /tmp/forwarder-heartbeat -mmin -2 -print -quit | grep -q . &&
grep -q '"status": "ok"' /tmp/forwarder-heartbeatDESTINATION remains supported for a single destination. MODE sets the default mode. When
HEARTBEAT_FILE is set, successful source polling, worker activity, and forwarding-job polling
rewrite that file at most every 10 seconds. Its age measures process/API responsiveness. Its JSON
content reports delivery:
{"failing_resources": 1, "failure_alert_after_seconds": 1800, "oldest_failure_seconds": 1830,
"source_resources": 3, "status": "failing", "updated_at": "2026-11-08T17:20:39+00:00"}A resource is failing from its first failed attempt until it is forwarded, becomes ineligible, or
leaves the source. status becomes failing once the oldest failure is older than
FAILURE_ALERT_AFTER seconds, so the health check above turns a persistent destination outage or an
uncertain submission into an unhealthy container. The default 0 never reports failing, and the
status is only written when HEARTBEAT_FILE is set. After a destination recovers, the status clears
once every failing resource succeeds at its next retry, up to 60 minutes later. An uncertain
submission stays failing until it is reconciled. Failure state is kept in memory: restarting the
forwarder retries at once but also restarts the alert clock.
The container image runs as the unprivileged UID 10001 on a slim Python base. Its only writes are
to the heartbeat, so it works with a read-only root filesystem and a tmpfs /tmp. Set user: when
another tool must write to root-owned mounts.
Forwarding waits for an Orthanc job to report Success before deleting the source snapshot.
Destination successes and pending jobs are persisted in resource metadata 4601; no-match
routing uses metadata 4600. A restart resumes known jobs and skips confirmed destinations.
An uncertain job submission retains the source for operator reconciliation rather than replaying
the request automatically. See maintenance and recovery.
| Setting | Default | Purpose |
|---|---|---|
HTTP_CONNECT_TIMEOUT / --http-connect-timeout |
5 seconds | Bound source connection attempts. |
HTTP_READ_TIMEOUT / --http-read-timeout |
15 seconds | Bound each source HTTP response wait. |
FORWARD_TIMEOUT / --forward-timeout |
3600 seconds | Bound one job wait; retries keep checking the existing job. |
FAILURE_ALERT_AFTER / --failure-alert-after |
0 (disabled) | Report a failing HEARTBEAT_FILE status after this many seconds of failure. |
A failed resource retries after 1, 2, 5, 30 and then every 60 minutes. With StableStudy, until its
retry is due, each pass reads only the study itself. After a failed delivery, new instances in the
study are handled at once; after an unexpected error, the study waits for its retry. Log lines name
the Orthanc resource ID and destination, and a failed job includes Orthanc's error description and
details. Orthanc keeps only JobsHistorySize finished jobs (default 10), so a forwarder source
should keep a larger history, for example "JobsHistorySize": 500, for investigation.
Tool CLIs keep urllib3.connectionpool at ERROR so HTTP retry warnings do not bury application
logs. Requests still retry safe operations, and exhausted failures remain visible in tool logs.
Set URLLIB3_LOG_LEVEL=WARNING or DEBUG explicitly for transport diagnostics. Library imports
leave the embedding application's logging configuration alone.
If no configured destination matches a study, the source data is retained. The skip is persisted in Orthanc metadata to avoid an endless retry loop and is reconsidered when the study or routing configuration changes.
More info in the PacsMigrator class
$ docker exec -it xxxx bash
/# pip3 install orthanc-tools
/# python3 -m orthanc_tools.pacs_migrator --url=http://localhost:8042 --user=user --password=pwd --destination_modality=orthanc-debug --from_study_date=20000101 --to_study_date=20191231 --timezone=Europe/Paris --run_schedule='{"Monday-Friday": ["0-7", "18-24"], "Saturday-Sunday": ["0-24"]}'
Running in a Docker environment:
$ docker run -d --name comparator --network=mysetup_default python:3.14 bash -c "pip3 install orthanc-tools && python3 -u -m orthanc_tools.orthanc_comparator --level=Instance --url=http://pacs-2022:8042 --modality=pacs-2017 --from_study_date=20220201 --to_study_date=20220302 --transfer_missing_to_modality --ignore_missing_from_orthanc --run_only_at_night_and_weekend --night_start_hour=19 --night_end_hour=6"
The OrthancTestDbPopulator generates test images and uploads them in Orthanc. All images have only 4 pixels and take a minimum amount of space on disk. By default, the generator always generates the same data, use a different seed if you need variation.
From a shell:
python3 -m orthanc_tools.orthanc_test_db_populator --url=http://192.168.0.10:8042 --user=user --password=pwd --studies=5000 --series=2 --instances=100 --workers=5 --api_key=1234 --from_study_date=20150101 --to_study_date=20151231 --seed=42 --image_content_type=Random/Flat --image_width=256 --image_height=256Allows to clean the Orthanc by deleting the oldest studies according to the labels applied on them.
With that sample, all studies with the LABEL1 and older than 6 weeks will be deleted all studies with the LABEL2 and older than 12 weeks will be deleted.
LABEL1,6
LABEL2,12
The script will be executed every day at 2:30 (24 format!)
python3 -m orthanc_tools.orthanc_cleaner --url=http://localhost:8042 --user=orthanc --password=orthanc --execution_time=2:30 --labels_file_path=./tests/stimuli/labels.csv hl7-server:
image: orthancteam/python-orthanc-tools:0.10.0
ports: ["2575:2575"]
volumes: ["/worklists:/worklists"]
restart: unless-stopped
entrypoint: ["python", "-m", "orthanc_tools.hl7_worklist_server_for_orthanc"]
Then, add this env var to Orthanc:
ORTHANC__WORKLISTS__DATABASE: /var/lib/orthanc/worklists