[![ci](https://github.com/gacou54/pyorthanc/workflows/Test/badge.svg)](https://github.com/gacou54/pyorthanc/actions?query=workflow%3ATest)
[![documentation](https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat)](https://gacou54.github.io/pyorthanc/)
![PyPI - Version](https://img.shields.io/pypi/v/pyorthanc)
![PyPI - Downloads](https://img.shields.io/pypi/dm/pyorthanc)
# 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:
```bash
pip install pyorthanc
```
---
Then use the client. If Orthanc is running locally, the default URL is `http://localhost:8042`.
```python
import pyorthanc
client = pyorthanc.Orthanc('http://localhost:8042', username='orthanc', password='orthanc')
patient_ids = client.get_patients()
```
Interact with connected modalities
```python
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
```python
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__.
```python
import pyorthanc
orthanc_patient_id = client.get_patients()[0]
patient = pyorthanc.Patient(orthanc_patient_id, client)
```
Waiting the for the anonymization process:
```python
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
```python
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
```python
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](https://github.com/orthanc-server/orthanc-setup-samples/blob/master/python-samples/python-sdk.txt)
## Contributing
You can contribute to this project with the following steps:
1. First, fork the project on Github
2. Clone the project
```shell
git clone https://github.com/<your-github-username>/pyorthanc
cd pyorthanc
```
3. Create a poetry environment
(this project use the [poetry](https://python-poetry.org/) for dependency management)
```shell
peotry install
```
4. Make a new git branch where you will apply the changes
```shell
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
```shell
docker compose run --build test
```
Raw data
{
"_id": null,
"home_page": "https://gacou54.github.io/pyorthanc/",
"name": "pyorthanc",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "Orthanc, DICOM, Medical-Imaging",
"author": "Gabriel Couture",
"author_email": "gacou54@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b9/09/5d830808a5b7c4ad6dd6298484aeb5504f6404db8e951071bc1b9ae359e8/pyorthanc-1.18.0.tar.gz",
"platform": null,
"description": "[![ci](https://github.com/gacou54/pyorthanc/workflows/Test/badge.svg)](https://github.com/gacou54/pyorthanc/actions?query=workflow%3ATest)\n[![documentation](https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat)](https://gacou54.github.io/pyorthanc/)\n![PyPI - Version](https://img.shields.io/pypi/v/pyorthanc)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pyorthanc)\n# PyOrthanc\n**PyOrthanc** is a python client for the Orthanc REST API, which fully wraps all the methods of the REST API.\nAdditionally, it provides many utility functions to interact with an Orthanc instance.\n\nSee the full documentation here https://gacou54.github.io/pyorthanc\n\n---\nInstall PyOrthanc using pip:\n```bash\npip install pyorthanc\n```\n---\nThen use the client. If Orthanc is running locally, the default URL is `http://localhost:8042`.\n```python\nimport pyorthanc\n\nclient = pyorthanc.Orthanc('http://localhost:8042', username='orthanc', password='orthanc')\npatient_ids = client.get_patients()\n```\n\nInteract with connected modalities\n```python\nimport pyorthanc\n\nmodality = pyorthanc.Modality(client, 'MY_MODALITY')\nassert modality.echo()\n\n# C-Find on modality\nresponse = modality.query({'Level': 'Study', 'Query': {'PatientID': '*'}})\n\n# C-Move to target modality\nmodality.move(response['ID'], {'TargetAet': 'target_modality'})\n```\nFind patients\n```python\npatients = pyorthanc.find_patients(client, {'PatientID': '*P001'})\nfor patient in patients:\n patient.labels\n patient.is_stable\n patient.name\n ...\n for study in patient.studies:\n study.labels\n study.date\n ...\n for series in study.series:\n ...\n for instance in series.instances:\n pydicom_ds = instance.get_pydicom()\n```\n\nResources (`Patient`, `Study`, `Series`, `Instance`) can be easily __anonymized__.\n```python\nimport pyorthanc\n\northanc_patient_id = client.get_patients()[0]\npatient = pyorthanc.Patient(orthanc_patient_id, client)\n```\nWaiting the for the anonymization process:\n```python\nnew_patient = patient.anonymize()\nnew_patient_with_given_patient_id = patient.anonymize(\n keep=['PatientName'],\n replace={'PatientID': 'TheNewPatientID'},\n force=True # Needed when changing PatientID/StudyInstanceUID/SeriesInstanceUID/SOPInstanceUID\n)\n```\nFor long-running job (i.e. large patient) or to submit many anonymization jobs at the same time, use\n```python\njob = patient.anonymize_as_job()\njob.state # You can follow the job state\n\njob.wait_until_completion() # Or just wait on its completion\nnew_patient = pyorthanc.Patient(job.content['ID'], client)\n```\n\n## Notes on versioning\n\nThe `Orthanc` and `AsyncOrthanc` classes are generated from https://orthanc.uclouvain.be/api/.\n\nCompatibility of versions between PyOrthanc and the Orthanc REST API are the following.\nNote that recent PyOrthanc versions will likely support older Orthanc version.\n\n| PyOrthanc version | Generated from |\n|-------------------|-----------------------------------------------|\n| \\>= 1.18.0 | Orthanc API 1.12.4 with Python Plugin 4.2 |\n| 1.17.0 | Orthanc API 1.12.3 with Python Plugin 4.2 |\n| 1.13.2 to 1.16.1 | Orthanc API 1.12.1 with Python Plugin 4.1 |\n| 1.13.0, 1.13.1 | Orthanc API 1.12.1 with Python Plugin 4.0 |\n| 1.12.* | Orthanc API 1.12.1 |\n| 1.11.* | Orthanc API 1.11.3 |\n| 0.2.* | Provided Google sheet from Orthanc maintainer |\n\n\nYou can still use the old client implementation with\n```python\nfrom pyorthanc.deprecated.client import Orthanc # Old client wrote by hand\n```\n\nNote that due to automatic generation some method names may be less clear.\nHowever, the automatic generation allows PyOrthanc to cover all the routes of the API of Orthanc.\n\n\n## Citation\nIf you publish using PyOrthanc, we kindly ask that you credit us. PyOrthanc can be found on Zenodo :\nhttps://zenodo.org/record/7086219 .\n\n## Credits\nThe `orthanc_sdk.py` has been generated from the `scripts/data/python-sdk.txt` file,\nwhich is from the [Python Orthanc Plugin](https://github.com/orthanc-server/orthanc-setup-samples/blob/master/python-samples/python-sdk.txt)\n\n## Contributing\nYou can contribute to this project with the following steps:\n1. First, fork the project on Github \n2. Clone the project\n ```shell\n git clone https://github.com/<your-github-username>/pyorthanc\n cd pyorthanc\n ```\n3. Create a poetry environment \n (this project use the [poetry](https://python-poetry.org/) for dependency management)\n ```shell\n peotry install \n ```\n4. Make a new git branch where you will apply the changes\n ```shell\n git checkout -b your-branch-name\n ```\n Now you can make your changes\n5. Once done, `git add`, `git commit` and `git push` the changes.\n6. Make a Pull Request from your branch to the https://github.com/gacou54/pyorthanc.\n\n### Run tests\n```shell\ndocker compose run --build test\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "Orthanc REST API python wrapper with additional utilities",
"version": "1.18.0",
"project_urls": {
"Homepage": "https://gacou54.github.io/pyorthanc/",
"Repository": "https://github.com/gacou54/pyorthanc"
},
"split_keywords": [
"orthanc",
" dicom",
" medical-imaging"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1abc3e54f725818d3129b00d44004044960a5d1c105985fb518ae4dee23619e9",
"md5": "fe05d64499a0c284bf21a46cf5471f95",
"sha256": "fe563cf38f8f0ad4f7ed49d3272d564b70e8e5566d6cdeadeb84322320bcc240"
},
"downloads": -1,
"filename": "pyorthanc-1.18.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fe05d64499a0c284bf21a46cf5471f95",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 114881,
"upload_time": "2024-06-13T13:48:42",
"upload_time_iso_8601": "2024-06-13T13:48:42.681203Z",
"url": "https://files.pythonhosted.org/packages/1a/bc/3e54f725818d3129b00d44004044960a5d1c105985fb518ae4dee23619e9/pyorthanc-1.18.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b9095d830808a5b7c4ad6dd6298484aeb5504f6404db8e951071bc1b9ae359e8",
"md5": "b9829e1901b761fbce3357bf33c406fa",
"sha256": "677913be829743bcc7cead84145ecc93feea304ab697ae2b30c50faea852a3a9"
},
"downloads": -1,
"filename": "pyorthanc-1.18.0.tar.gz",
"has_sig": false,
"md5_digest": "b9829e1901b761fbce3357bf33c406fa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 102380,
"upload_time": "2024-06-13T13:48:44",
"upload_time_iso_8601": "2024-06-13T13:48:44.257077Z",
"url": "https://files.pythonhosted.org/packages/b9/09/5d830808a5b7c4ad6dd6298484aeb5504f6404db8e951071bc1b9ae359e8/pyorthanc-1.18.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-13 13:48:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gacou54",
"github_project": "pyorthanc",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyorthanc"
}