Package: pyorthanc
PyOrthancPyOrthancis 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 herehttps://gacou54.github.io/pyorthancInstall PyOrthanc using pip:pipinstallpyorthancThen use the client. If Orthanc is running locally, the default URL ishttp://localhost:8042.importpyorthancclient=pyorthanc.Orthanc('http://localhost:8042',username='orthanc',password='orthanc')patient_ids=client.get_patients()Interact with connected modalitiesimportpyorthancmodality=pyorthanc.Modality(client,'MY_MODALITY')assertmodality.echo()# C-Find on modalityresponse=modality.query({'Level':'Study','Query':{'PatientID':'*'}})# C-Move to target modalitymodality.move(response['ID'],{'TargetAet':'target_modality'})Find patientspatients=pyorthanc.find_patients(client,{'PatientID':'*P001'})forpatientinpatients:patient.labelspatient.is_stablepatient.name...forstudyinpatient.studies:study.labelsstudy.date...forseriesinstudy.series:...forinstanceinseries.instances:pydicom_ds=instance.get_pydicom()Resources (Patient,Study,Series,Instance) can be easilyanonymized.importpyorthancorthanc_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, usejob=patient.anonymize_as_job()job.state# You can follow the job statejob.wait_until_completion()# Or just wait on its completionnew_patient=pyorthanc.Patient(job.content['ID'],client)Notes on versioningTheOrthancandAsyncOrthancclasses are generated fromhttps://api.orthanc-server.com/.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 versionGenerated from>= 1.13.2Orthanc API 1.12.1 with Python Plugin 4.11.13.0, 1.13.1Orthanc API 1.12.1 with Python Plugin 4.01.12.*Orthanc API 1.12.11.11.*Orthanc API 1.11.30.2.*Provided Google sheet from Orthanc maintainerYou can still use the old client withfrompyorthanc.deprecated.clientimportOrthanc# Old client wrote by handfrompyorthanc.deprecated.client_1_11_3importOrthancNote 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.CitationIf you publish using PyOrthanc, we kindly ask that you credit us. PyOrthanc can be found on Zenodo :https://zenodo.org/record/7086219.CreditsTheorthanc_sdk.pyhas been generated from thescripts/data/python-sdk.txtfile,
which is from thePython Orthanc PluginContributingYou can contribute to this project with the following steps:First, fork the project on GithubClone the projectgitclonehttps://github.com/<your-github-username>/pyorthanccdpyorthancCreate a poetry environment
(this project use thepoetryfor dependency management)peotryinstallMake a new git branch where you will apply the changesgitcheckout-byour-branch-nameNow you can make your changesOnce done,git add,git commitandgit pushthe changes.Make a Pull Request from your branch to thehttps://github.com/gacou54/pyorthanc.