Skip to main content

REST client for Orthanc DICOM servers

Project description

beren

Build Status PyPI version

beren provides a REST client for Orthanc, an open-source DICOM server.

Built using the excellent apiron library.

Install

Use pip:

pip install beren

How to use

Import the client and provide the server details

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')

# Patient endpoints
orthanc.get_patients()
orthanc.get_patient(id)
...and so on

# Study endpoints
orthanc.get_studies()
orthanc.get_study(id)
...and so on

# Series endpoints
orthanc.get_series()
orthanc.get_one_series(id)
...and so on

# Instance endpoints
orthanc.get_instances()
orthanc.get_instance(id)
...and so on

# Get changes
orthanc.get_changes()

# Find objects by query
query = {'PatientName': 'Jon*'}
orthanc.find(query, level='Patient', expand=False, limit=2)

# Get previous queries
orthanc.get_queries()

There are many other preconfigured endpoints.

Authentication

Many servers require authentication to utilize their API. Simply provide a valid authentication object when defining the client:

from requests.auth import HTTPBasicAuth
auth = HTTPBasicAuth('orthanc', 'orthanc')
orthanc = Orthanc('https://test.server.com', auth=auth)

To override the default authentication, provide a new authentication object when calling the endpoint:

new_auth = HTTPBasicAuth('new_user', 'new_password')
orthanc.get_patients(auth=auth)

Advanced Configuration

Timeouts

Some servers are slow (and some methods can be slow). For example, asking for all instances from a server can cause a timeout before the server responds. To modify the timeout settings, use apiron's Timeout class:

from apiron import Timeout
t = Timeout(read_timeout=6, connection_timeout=1)   # Modify the timeout

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')
orthanc.get_instances(timeout_spec=t)               # Use new timeout

Increase the read timeout if the endpoint is slow. Increase the connection timeout for slow servers.

Disable Certificate Checks

To disable TLS certificate checking, use sessions:

import requests
session = requests.sessions.Session()       # New session
session.verify = False                      # Disable certificate checking

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')
orthanc.get_patients(session=session)       # Use session

Non-HTTPS endpoints

The client will warn when using HTTP endpoints. Medical data is particularly sensitive, consequently, strongly consider using HTTPS.

You can disable the warning using the warn_insecure argument:

from beren import Orthanc
orthanc = Orthanc('http://insecure.endpoint.com', warn_insecure=False)

Examples

To save an instance file to the local directory:

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')

with open('test_file.dcm', 'wb') as dcm:
    for chunk in orthanc.get_instance_file(<instance_id>):
        dcm.write(chunk)

To get an archive of a series (DCM files in a zip file):

from beren import Orthanc
orthanc = Orthanc('https://example-orthanc-server.com')

with open('test.zip', 'wb') as z:
    for chunk in orthanc.get_series_archive(<instance_id>):
        z.write(chunk)

Further help

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

beren-0.7.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

beren-0.7.0-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file beren-0.7.0.tar.gz.

File metadata

  • Download URL: beren-0.7.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for beren-0.7.0.tar.gz
Algorithm Hash digest
SHA256 eeb13ec419394ac71ba1679922c3b373059eaa2722e8fd4542ea7b8d1d6f75ec
MD5 fc05cbf8e9b321e9fc45b9310b8ce8c6
BLAKE2b-256 cfd95dd489546699c15dd6bbd4439a8175b6dd49c3c77d6f623e60eba86da705

See more details on using hashes here.

File details

Details for the file beren-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: beren-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for beren-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 848d93357795dc569cfab0f0001d1556c8edc7b4f69708986922bc4044cd1ad7
MD5 d1c55115a33cba011070621091b85c10
BLAKE2b-256 0f531c3b4219075ba8fc5e9744183741028514401237210d3e2337cb22734a50

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