Skip to main content

Orthanc REST API python wrapper with additional utilities

Project description

ci documentation PyPI - Version PyPI - Downloads

PyOrthanc

PyOrthanc is a python client for the Orthanc REST API, which fully wraps all the methods of the REST API. Additionally, it provides many utility functions to interact with an Orthanc instance.

See the full documentation here https://gacou54.github.io/pyorthanc


Install PyOrthanc using pip:

pip install pyorthanc

Then use the client. If Orthanc is running locally, the default URL is http://localhost:8042.

import pyorthanc

client = pyorthanc.Orthanc('http://localhost:8042', username='orthanc', password='orthanc')
patient_ids = client.get_patients()

Interact with connected modalities

import pyorthanc

modality = pyorthanc.Modality(client, 'MY_MODALITY')
assert modality.echo()

# C-Find on modality
response = modality.query({'Level': 'Study', 'Query': {'PatientID': '*'}})

# C-Move to target modality
modality.move(response['ID'], {'TargetAet': 'target_modality'})

Find patients

patients = pyorthanc.find_patients(client, {'PatientID': '*P001'})
for patient in patients:
    patient.labels
    patient.is_stable
    patient.name
    ...
    for study in patient.studies:
        study.labels
        study.date
        ...
        for series in study.series:
            ...
            for instance in series.instances:
                pydicom_ds = instance.get_pydicom()

Resources (Patient, Study, Series, Instance) can be easily anonymized.

import pyorthanc

orthanc_patient_id = client.get_patients()[0]
patient = pyorthanc.Patient(orthanc_patient_id, client)

Waiting the for the anonymization process:

new_patient = patient.anonymize()
new_patient_with_given_patient_id = patient.anonymize(
   keep=['PatientName'],
   replace={'PatientID': 'TheNewPatientID'},
   force=True  # Needed when changing PatientID/StudyInstanceUID/SeriesInstanceUID/SOPInstanceUID
)

For long-running job (i.e. large patient) or to submit many anonymization jobs at the same time, use

job = patient.anonymize_as_job()
job.state  # You can follow the job state

job.wait_until_completion() # Or just wait on its completion
new_patient = pyorthanc.Patient(job.content['ID'], client)

Notes on versioning

The Orthanc and AsyncOrthanc classes are generated from https://orthanc.uclouvain.be/api/.

Compatibility of versions between PyOrthanc and the Orthanc REST API are the following. Note that recent PyOrthanc versions will likely support older Orthanc version.

PyOrthanc version Generated from
>= 1.18.0 Orthanc API 1.12.4 with Python Plugin 4.2
1.17.0 Orthanc API 1.12.3 with Python Plugin 4.2
1.13.2 to 1.16.1 Orthanc API 1.12.1 with Python Plugin 4.1
1.13.0, 1.13.1 Orthanc API 1.12.1 with Python Plugin 4.0
1.12.* Orthanc API 1.12.1
1.11.* Orthanc API 1.11.3
0.2.* Provided Google sheet from Orthanc maintainer

You can still use the old client implementation with

from pyorthanc.deprecated.client import Orthanc  # Old client wrote by hand

Note that due to automatic generation some method names may be less clear. However, the automatic generation allows PyOrthanc to cover all the routes of the API of Orthanc.

Citation

If you publish using PyOrthanc, we kindly ask that you credit us. PyOrthanc can be found on Zenodo : https://zenodo.org/record/7086219 .

Credits

The orthanc_sdk.py has been generated from the scripts/data/python-sdk.txt file, which is from the Python Orthanc Plugin

Contributing

You can contribute to this project with the following steps:

  1. First, fork the project on Github
  2. Clone the project
    git clone https://github.com/<your-github-username>/pyorthanc
    cd pyorthanc
    
  3. Create a poetry environment (this project use the poetry for dependency management)
    peotry install 
    
  4. Make a new git branch where you will apply the changes
    git checkout -b your-branch-name
    
    Now you can make your changes
  5. Once done, git add, git commit and git push the changes.
  6. Make a Pull Request from your branch to the https://github.com/gacou54/pyorthanc.

Run tests

docker compose run --build test

Project details


Download files

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

Source Distribution

pyorthanc-1.18.0.tar.gz (102.4 kB view details)

Uploaded Source

Built Distribution

pyorthanc-1.18.0-py3-none-any.whl (114.9 kB view details)

Uploaded Python 3

File details

Details for the file pyorthanc-1.18.0.tar.gz.

File metadata

  • Download URL: pyorthanc-1.18.0.tar.gz
  • Upload date:
  • Size: 102.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.18 Linux/5.14.0-427.20.1.el9_4.x86_64

File hashes

Hashes for pyorthanc-1.18.0.tar.gz
Algorithm Hash digest
SHA256 677913be829743bcc7cead84145ecc93feea304ab697ae2b30c50faea852a3a9
MD5 b9829e1901b761fbce3357bf33c406fa
BLAKE2b-256 b9095d830808a5b7c4ad6dd6298484aeb5504f6404db8e951071bc1b9ae359e8

See more details on using hashes here.

File details

Details for the file pyorthanc-1.18.0-py3-none-any.whl.

File metadata

  • Download URL: pyorthanc-1.18.0-py3-none-any.whl
  • Upload date:
  • Size: 114.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.18 Linux/5.14.0-427.20.1.el9_4.x86_64

File hashes

Hashes for pyorthanc-1.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe563cf38f8f0ad4f7ed49d3272d564b70e8e5566d6cdeadeb84322320bcc240
MD5 fe05d64499a0c284bf21a46cf5471f95
BLAKE2b-256 1abc3e54f725818d3129b00d44004044960a5d1c105985fb518ae4dee23619e9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page