beren
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
Future goals
- Asynchronous requests
- Document every function
- Better test coverage
Metadata
Release files for beren 0.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| beren-0.7.1.tar.gz | 26.1 kB | Without provenance | Details for beren-0.7.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| beren-0.7.1-py3-none-any.whl | Python 3 | none | any | Details for beren-0.7.1-py3-none-any.whl |
Total release size: 56.0 kB
Release files / beren-0.7.1.tar.gz
| Download URL | beren-0.7.1.tar.gz |
|---|---|
| Size | 26.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50e40cb1d0ce2dc38676f437d050c9d059f0a648cbd91876bd587a7ea88a7077
|
|
BLAKE2b-256 checksum How to use checksums |
b46e7287fe9c2dc9583cab45e19d99d0780665883aa95eaaeff3274da8ed0d05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
|
Release files / beren-0.7.1-py3-none-any.whl
| Download URL | beren-0.7.1-py3-none-any.whl |
|---|---|
| Size | 29.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4822e300cc1c0871971b13f3c5901b1c961e8dba845953fe535683be4f941395
|
|
BLAKE2b-256 checksum How to use checksums |
200d1382c7271d219751cbf2dc6a5439177d4791f99fac8db2d49166b7340ce4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
|
Security for beren 0.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.