Orthanc DICOM服务器的REST客户端
项目描述
beren
beren
为Orthanc(一个开源DICOM服务器)提供了一个REST客户端。
使用优秀的apiron库构建。
安装
使用pip
pip install beren
如何使用
导入客户端并提供服务器详情
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()
有许多其他预配置的端点。
身份验证
许多服务器需要身份验证才能使用它们的API。在定义客户端时简单地提供有效的身份验证对象
from requests.auth import HTTPBasicAuth
auth = HTTPBasicAuth('orthanc', 'orthanc')
orthanc = Orthanc('https://test.server.com', auth=auth)
要覆盖默认身份验证,在调用端点时提供新的身份验证对象
new_auth = HTTPBasicAuth('new_user', 'new_password')
orthanc.get_patients(auth=auth)
高级配置
超时
某些服务器很慢(并且某些方法可能很慢)。例如,请求服务器中的所有实例可能导致在服务器响应之前超时。要修改超时设置,请使用apiron
的Timeout
类
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
如果端点很慢,请增加读取超时。为慢速服务器增加连接超时。
禁用证书检查
要禁用TLS证书检查,请使用会话
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
非HTTPS端点
当使用HTTP端点时,客户端将发出警告。医学数据尤其敏感,因此强烈考虑使用HTTPS。
您可以使用warn_insecure
参数禁用警告
from beren import Orthanc
orthanc = Orthanc('http://insecure.endpoint.com', warn_insecure=False)
示例
将实例文件保存到本地目录
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)
获取一个系列的存档(DCM文件存档为zip文件)
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)
进一步的帮助
未来目标
- 异步请求
- 记录每个函数
- 更好的测试覆盖率
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分发
beren-0.7.1.tar.gz (26.1 kB 查看哈希值)
构建分发
beren-0.7.1-py3-none-any.whl (29.9 kB 查看哈希值)
关闭
beren-0.7.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 50e40cb1d0ce2dc38676f437d050c9d059f0a648cbd91876bd587a7ea88a7077 |
|
MD5 | 3f2c9e48314a755e07189c1648a72136 |
|
BLAKE2b-256 | b46e7287fe9c2dc9583cab45e19d99d0780665883aa95eaaeff3274da8ed0d05 |
关闭
beren-0.7.1-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4822e300cc1c0871971b13f3c5901b1c961e8dba845953fe535683be4f941395 |
|
MD5 | 382c49aa4b2c3b1e3f7dea192f3463b1 |
|
BLAKE2b-256 | 200d1382c7271d219751cbf2dc6a5439177d4791f99fac8db2d49166b7340ce4 |