pyxnat is a Python library to communicate with XNAT which is an extensible database system for imaging and related data. pyxnat uses the RESTful Web Services provided by XNAT and aims to ease communications with an XNAT server to plug-in external tools or python scripts by exposing a simple and consistent API.
Setup the connection
>>> from pyxnat import Interface
>>> interface = Interface(
server='https://central.xnat.org',
user='login',
password='pass',
cachedir='/tmp'
)
Traverse the resource tree
>>> interface.select.projects().get()
[u'CENTRAL_OASIS_CS', u'CENTRAL_OASIS_LONG', ...]
Operate the database
>>> project = interface.select.project('my_project').insert()
>>> project.resource('images').file('image.nii').insert('/tmp/image.nii')
Use the search engine
>>> table = interface.select(
'xnat:subjectData',
['xnat:subjectData/PROJECT', 'xnat:subjectData/SUBJECT_ID']
).where([('xnat:subjectData/SUBJECT_ID','LIKE','%'),
('xnat:subjectData/PROJECT', '=', 'my_project'),
'AND'
])
Interface | Main entry point to access a XNAT server. |
Select | Data selection interface. Callable object that indicates the data to be returned to the user. |
SearchManager | Search interface. Handles operations to save and get back searches on the server. |
CacheManager | Management interface for the cache. |
Users | Database user management interface. It is used to retrieve information on users registered on a server. |