Skip to main content

python-orthanc-tools

A set of python tools to ease Orthanc scripting.

Functionalities are very limited now ! Backward compat will break a lot in the near future !

Installation

pip3 install orthanc-tools

cloning an Orthanc to another

The 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:  

OrthancCloner performance

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 ?

import files from a folder from a Docker container

$ 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

Implement a simple forwarder

The forwarder simply forwards the content of an Orthanc to another DICOM destination and then, deletes the instances. This is usefull 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.

from a shell:

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=StableStudy

migrate DICOM Data from a modality to another

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"]}'

compare DICOM Data found in Orthanc and in a remote modality

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"

uploading a Test DB in Orthanc

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=256

purge old studies from an Orthanc

Allows 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

Deploy an HL7 server parsing ORM^O01 messages to create and store worklists files in a folder

   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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

orthanc_tools-0.22.0.tar.gz (200.6 kB view details)

Uploaded Source

Built Distribution

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

orthanc_tools-0.22.0-py3-none-any.whl (203.7 kB view details)

Uploaded Python 3

File details

Details for the file orthanc_tools-0.22.0.tar.gz.

File metadata

  • Download URL: orthanc_tools-0.22.0.tar.gz
  • Upload date:
  • Size: 200.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for orthanc_tools-0.22.0.tar.gz
Algorithm Hash digest
SHA256 b9394b64715c2ce544beceb2f2754e696dce810331f473b75135952ff5ecfd91
MD5 be55f6705d25cd1174fe6085eeed8f95
BLAKE2b-256 00d70b0bf8d114402d97b7a7a0673d8727914e45437f2063acb34333f80e90a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for orthanc_tools-0.22.0.tar.gz:

Publisher: release.yml on orthanc-team/python-orthanc-tools

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

File details

Details for the file orthanc_tools-0.22.0-py3-none-any.whl.

File metadata

  • Download URL: orthanc_tools-0.22.0-py3-none-any.whl
  • Upload date:
  • Size: 203.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for orthanc_tools-0.22.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1e46e1f35832afd6084af71f45c9c106610efec4db43813e5132cfe4cdc1ee0
MD5 b1e461e1181b0f0b1f7504ba049cc581
BLAKE2b-256 7c2be3e84d7c41000d9239c40bed6d9e9f5674fbc293c1380f13fec1197db114

See more details on using hashes here.

Provenance

The following attestation bundles were made for orthanc_tools-0.22.0-py3-none-any.whl:

Publisher: release.yml on orthanc-team/python-orthanc-tools

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

Release history Release notifications | RSS feed

This release

0.22.0 This release

2 files

0.21.2

2 files

0.21.0

2 files

0.20.0

2 files

0.19.1

2 files

0.19.0

2 files

0.18.4

2 files

0.18.3

2 files

0.18.2

2 files

0.18.1

2 files

0.18.0

2 files

0.17.17

2 files

0.17.16

2 files

0.17.15

2 files

0.17.14

2 files

0.17.13

2 files

0.17.12

2 files

0.17.11

2 files

0.17.10

2 files

0.17.9

2 files

0.17.7

2 files

0.17.6

2 files

0.17.5

2 files

0.17.4

2 files

0.17.3

2 files

0.17.2

2 files

0.17.1

2 files

0.17.0

2 files

0.16.12

2 files

0.16.11

2 files

0.16.10

2 files

0.16.9

2 files

0.16.8

2 files

0.16.6

2 files

0.16.5

2 files

0.16.4

2 files

0.16.3

2 files

0.16.2

2 files

0.16.1

2 files

0.16.0

2 files

0.15.4

2 files

0.15.2

2 files

0.15.1

2 files

0.15.0

2 files

0.14.5

2 files

0.14.4

2 files

0.14.3

2 files

0.14.2

2 files

0.14.1

2 files

0.14.0

2 files

0.13.11

2 files

0.13.10

2 files

0.13.9

2 files

0.13.8

2 files

0.13.7

2 files

0.13.6

2 files

0.13.5

2 files

0.13.4

2 files

0.13.3

2 files

0.13.2

2 files

0.13.1

2 files

0.13.0

2 files

0.12.18

2 files

0.12.17

2 files

0.12.16

2 files

0.12.15

2 files

0.12.14

2 files

0.12.13

2 files

0.12.12

2 files

0.12.11

2 files

0.12.10

2 files

0.12.9

2 files

0.12.8

2 files

0.12.7

2 files

0.12.6

2 files

0.12.5

2 files

0.12.3

2 files

0.12.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.15

2 files

0.9.14

2 files

0.9.13

2 files

0.9.12

2 files

0.9.11

2 files

0.9.10

2 files

0.9.9

2 files

0.9.8

2 files

0.9.7

2 files

0.9.6

2 files

0.9.5

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.9

2 files

0.8.8

2 files

0.8.7

2 files

0.8.4

2 files

0.8.3

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.0

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.4

2 files

0.3.3

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page