PyOrthanc
PyOrthanc: A Python Interface for Orthanc DICOM Servers - Published in JOSS (2025)
Science Score: 93.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 1 DOI reference(s) in JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Repository
Python library that wrap the Orthanc REST API and facilitate the manipulation of data in Orthanc
Basic Info
- Host: GitHub
- Owner: gacou54
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://gacou54.github.io/pyorthanc/
- Size: 3.93 MB
Statistics
- Stars: 55
- Watchers: 2
- Forks: 13
- Open Issues: 3
- Releases: 24
Metadata Files
README.md
PyOrthanc
PyOrthanc is a comprehensive Python client for Orthanc, providing:
- Complete wrapping of the Orthanc REST API methods
- High-level utilities for common DICOM operations
- Asynchronous client support
- Helper functions for working with DICOM data
- Integration with the Orthanc Python plugin
Why PyOrthanc?
PyOrthanc makes it easy to work with DICOM medical images stored on Orthanc servers using Python - instead of dealing with the DICOM protocol directly or creating complex code to interact with Orthanc's REST API.
Researchers and clinicians can make simple Python script to access and manage their medical imaging data.
Advanced users can use PyOrthanc to make Orthanc query a hospital PACS (Picture Archiving and Communication System). This allows to find and retrieve images produced in the clinic for research or quality control purposes. Additionally, since PyOrthanc simplifies Orthanc's anonymization operations, an entire medical image management workflow can be implemented in Python.
PyOrthanc or python-orthanc-api-client?
Another project python-orthanc-api-client
from orthanc-team is quite similar to pyorthanc.
If you are wondering which one to use, please refer to this discussion.
Quick Install
bash
pip install pyorthanc # Basic installation
pip install pyorthanc[all] # Install all optional dependencies
Basic Usage
Assuming an Orthanc server running locally at http://localhost:8042:
```python
from pyorthanc import Orthanc, upload
Connect to Orthanc server
client = Orthanc('http://localhost:8042')
Or with authentication:
client = Orthanc('http://localhost:8042', username='orthanc', password='orthanc')
Basic operations
patientids = client.getpatients() studies = client.get_studies()
Upload DICOM files
upload(client, 'image.dcm') # From a file upload(client, 'dicom_files.zip') # From a zip upload(client, 'path/to/directory') # Upload all dicom files in a directory upload(client, 'path/to/directory', recursive=True) # Upload all dicom files in a directory recursively
Check if dicom is in Orthanc before upload
upload(client, 'path/to/directory', recursive=True, checkbeforeupload=True) ```
Working with DICOM Modalities
```python from pyorthanc import Modality
Create modality connection
modality = Modality(client, 'REMOTE_PACS')
Test connection with C-ECHO
if modality.echo(): print("Successfully connected to PACS")
Query studies with C-FIND
response = modality.find({ 'Level': 'Study', 'Query': { 'PatientID': '12345*', 'StudyDate': '20230101-20231231' } })
Matches (i.e. answers in Orthanc nomenclature) can be reviewed before retrieving results
response['answers']
Retrieve results with C-MOVE to a target AET
modality.move(response['ID'], {'TargetAet': 'ORTHANC'}) ```
Finding and Processing DICOM Data
```python from pyorthanc import findpatients, findstudies, findseries, findinstances
Search for patients
patients = find_patients( client, query={'PatientName': '*Gabriel'}, labels=['research'] # It is also possible to filter by labels )
Process patient data
for patient in patients: print(f"Patient: {patient.name} (ID: {patient.patientid})") print(f"Birth Date: {patient.birthdate}") print(f"Labels: {patient.labels}")
# Access studies
for study in patient.studies:
print(f"\nStudy Date: {study.date}")
print(f"Description: {study.description}")
# Access series
for series in study.series:
print(f"\nModality: {series.modality}")
print(f"Series Description: {series.description}")
# Access individual DICOM instances
for instance in series.instances:
# Convert to pydicom dataset
ds = instance.get_pydicom()
# Process DICOM data...
Note the existing function to query Orthanc
findstudies(client, query={...}) findseries(client, query={...}) find_instances(client, query={...}) ```
Using pyorthanc within Orthanc's Python plugin
Use the orthanc_sdk module when using Orthanc's Python plugin.
orthanc_sdk acts as the same as orthanc, but it provides type hints and autocompletion.
For example:
```python from pyorthanc import orthanc_sdk
Register a new REST endpoint
def handleapi(output: orthancsdk.RestOutput, uri: str, **request): """Handle REST API request""" if request['method'] == 'GET': output.AnswerBuffer('Hello from plugin!', 'text/plain') else: output.SendMethodNotAllowed('GET')
orthancsdk.RegisterRestCallback('/hello-world', handleapi)
Handle incoming DICOM
def onstore(dicom: orthancsdk.DicomInstance, instanceid: str): """Process stored DICOM instances""" print(f'Received instance {instanceid}') print(f'Size: {dicom.GetInstanceSize()} bytes') print(f'Transfer Syntax: {dicom.GetInstanceTransferSyntaxUid()}')
orthancsdk.RegisterOnStoredInstanceCallback(onstore) ```
Examples
Typical example can be found in these notebooks. - This notebook shows how a user can query image data from an Orthanc server - This notebook shows how a user can query and pull data from other modality (such as a CT scan or a PACS) connected to an Orthanc Server.
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.20.0 | Orthanc API 1.12.6 with Python Plugin 4.2 | | 1.19.0, 1.19.1 | Orthanc API 1.12.5 with Python Plugin 4.2 | | 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 |
Running tests
The tests are run in a docker image launched with docker compose.
shell
docker compose run test
This command starts 3 containers :
1. A Python image with the PyOrthanc source code and launches pytest
2. An instance of Orthanc (orthanc1) on which the PyOrthanc client is connected
3. A second Orthanc instance (orthanc2) which acts as a modality connected to orthanc1
Cheat sheet
First steps
Getting started
- Connect to Orthanc
- Upload DICOM files to Orthanc
- Handle connected DICOM modalities
- Find and download patients according to criteria
- Query (C-Find) and Retrieve (C-Move) from remote modality ### Advanced examples ### Releases ### Community guidelines
- Report an issue
- Support
- Contribute ## Contacts
- Maintainers Team
- Useful links ## Citation
Owner
- Name: Gabriel Couture
- Login: gacou54
- Kind: user
- Location: Québec, QC, Canada
- Company: IUCPQ - Centre de recherche de l'Institut universitaire de cardiologie et de pneumologie de Québec-Université Laval
- Repositories: 23
- Profile: https://github.com/gacou54
Scientific software developer.
JOSS Publication
PyOrthanc: A Python Interface for Orthanc DICOM Servers
Authors
Centre de recherche de l’Institut universitaire de cardiologie et de pneumologie de Québec-Université Laval, 2725 Ch Ste-Foy, G1V 4G5, Québec, Canada
Tags
Orthanc Medical physicsGitHub Events
Total
- Create event: 15
- Release event: 4
- Issues event: 16
- Watch event: 5
- Issue comment event: 23
- Push event: 67
- Pull request review comment event: 3
- Pull request review event: 10
- Pull request event: 26
- Fork event: 2
Last Year
- Create event: 15
- Release event: 4
- Issues event: 16
- Watch event: 5
- Issue comment event: 23
- Push event: 67
- Pull request review comment event: 3
- Pull request review event: 10
- Pull request event: 26
- Fork event: 2
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Gabriel Couture | g****4@g****m | 362 |
| Yannick Lemaréchal | y****1@u****a | 36 |
| Gabriel Couture | g****4@u****a | 12 |
| Renal-Of-Loon | 6****n | 3 |
| Justin Hamel | 5****8@u****1 | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 32
- Total pull requests: 73
- Average time to close issues: 23 days
- Average time to close pull requests: about 1 month
- Total issue authors: 11
- Total pull request authors: 4
- Average comments per issue: 1.5
- Average comments per pull request: 0.29
- Merged pull requests: 60
- Bot issues: 0
- Bot pull requests: 7
Past Year
- Issues: 11
- Pull requests: 29
- Average time to close issues: 13 days
- Average time to close pull requests: 26 days
- Issue authors: 6
- Pull request authors: 3
- Average comments per issue: 1.09
- Average comments per pull request: 0.34
- Merged pull requests: 25
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- gacou54 (13)
- ylemarechal (3)
- sinhaharsh (2)
- jrkerns (2)
- devnums (2)
- nilgoyette (1)
- OmarAbuhassan (1)
- uditgoswami (1)
- ranasrule (1)
- rjkowalski (1)
- sahertariq07 (1)
Pull Request Authors
- gacou54 (56)
- ylemarechal (10)
- dependabot[bot] (7)
- Renal-Of-Loon (4)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 4,870 last-month
- Total docker downloads: 271
- Total dependent packages: 1
- Total dependent repositories: 3
- Total versions: 39
- Total maintainers: 2
pypi.org: pyorthanc
Orthanc REST API python wrapper with additional utilities
- Homepage: https://gacou54.github.io/pyorthanc/
- Documentation: https://pyorthanc.readthedocs.io/
- License: MIT
-
Latest release: 1.22.1
published 7 months ago
Rankings
Maintainers (2)
Dependencies
- pytest ^7.1.0 develop
- python ^3.7
- requests ^2.27.1
- actions/checkout v2 composite
- actions/cache v3 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- pyorthanc ==1.11.5