pyxnat: XNAT in Python

Date: Apr 11, 2024 Version: 1.6

Useful links: Binary Installers | Source Repository | Issues & Ideas

Overview

pyxnat is an open source, BSD-licenced library providing a programmatic interface with XNAT which is an extensible management system for imaging data (and related). pyxnat uses the RESTful Web services provided by XNAT and allows easier interaction with an XNAT server through a simple and consistent API using the Python programming language.

Short examples

Setup a connection

>>> from pyxnat import Interface
>>> interface = Interface(server='https://central.xnat.org',
                          user='login',
                          password='pass')

Traverse the resource tree

>>> list(interface.select.projects())
['CENTRAL_OASIS_CS', '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'
                     ])

Module contents

Interface([server, user, password, config, ...])

Main entry point to access an XNAT server.

Select(interface)

Data selection interface.

SearchManager(interface)

Search interface.

Users(interface)

Database user management interface.