pyxnat: XNAT in Python

Overview

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.

Installing pyxnat
Instructions on how to get the distribution.
Tutorial
Start here for a quick overview.
Documentation
Detailed documentation and examples.
External Resources
References to related projects and external resources.
About
Contributors and funding.
Latest changes
See changes from the latest version.

Short examples

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'
                     ])

Module contents

Interface([server, user, password, …]) Main entry point to access a XNAT server.
Select(interface) Data selection interface.
SearchManager(interface) Search interface.
CacheManager(interface) Management interface for the cache.
Users(interface) Database user management interface.