Python Orthanc REST API client
Project description
python-orthanc-api-client
A python client to ease using the Orthanc Rest API.
Functionalities are very limited now ! Backward compat will break a lot in the near future !
Installation:
pip3 install orthanc-api-client
Examples:
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')
all_patients_ids = orthanc_a.patients.get_all_ids()
all_studies_ids = orthanc_a.studies.get_all_ids()
all_series_ids = orthanc_a.series.get_all_ids()
all_instances_ids = orthanc_a.instances.get_all_ids()
dicom_file = orthanc_a.instances.get_file(orthanc_id=all_instances_ids[0])
instances_ids = orthanc_b.upload(buffer=dicom_file)
study_id = orthanc_b.instances.get_parent_study_id(instances_ids[0])
orthanc_a.instances.set_metadata(orthanc_id=all_instances_ids[0], 1024, 'my-value')
tags = orthanc_a.instances.get_tags(orhtanc_id=all_instances_ids[0])
patient_name = tags['PatientName']
patient_id = tags['0010,0020']
patient_sex = tags['0010-0040']
anon_study_id = orthanc_b.studies.anonymize(
orthanc_id=study_id,
keep_tags=['PatientName'],
replace_tags={
'PatientID': 'ANON'
},
force=True,
delete_original=False
)
upload a folder to Orthanc
from orthanc_api_client import OrthancApiClient
o = OrthancApiClient('http://localhost:8042', user='orthanc', pwd='orthanc')
o.upload_folder('/home/o/files', ignore_errors=True)
running from inside an Orthanc python plugin
from orthanc_api_client import OrthancApiClient
import orthanc
import json
orthanc_client = None
def OnChange(changeType, level, resource):
global orthanc_client
if changeType == orthanc.ChangeType.ORTHANC_STARTED:
orthanc.LogWarning("Starting python plugin")
# at startup, use the python SDK direct access to the Rest API to retrieve info to pass to the OrthancApiClient that is using 'requests'
system = json.loads(orthanc.RestApiGet('/system'))
api_token = orthanc.GenerateRestApiAuthorizationToken()
orthanc_client = OrthancApiClient(
orthanc_root_url=f"http://localhost:{system['HttpPort']}",
api_token=api_token
)
...
orthanc.RegisterOnChangeCallback(OnChange)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
orthanc_api_client-0.2.0.tar.gz
(16.4 kB
view details)
Built Distribution
File details
Details for the file orthanc_api_client-0.2.0.tar.gz
.
File metadata
- Download URL: orthanc_api_client-0.2.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62241200b7580552123acba774ae4a6033e70a6e2ca427837f7a1b17ac1cf9dc |
|
MD5 | e60d0928447745ff6b787b0ec1596b80 |
|
BLAKE2b-256 | 67da0d00226fba1f8871814269d92f191666d6e5ac148a8d478a53e1d10eec76 |
File details
Details for the file orthanc_api_client-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: orthanc_api_client-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e4334277788d9edc8c50af7d457152969d35637ec2d100113554c445e95753f |
|
MD5 | 9cb2fafdd4361b374313dc6a87b4ba80 |
|
BLAKE2b-256 | 17ba1ca4b938d96bb7d9ba96bd092e477f9bb9492bbd2735e4482fb0ac921721 |