pyxnat is an open source, BSD-licenced library providing a programmatic interface with XNAT, an extensible management system for imaging data and related information. It uses the RESTful Web services provided by XNAT to enable easier interaction through a simple and consistent API using Python. The library is actively maintained, with the latest version 1.6.4 released as a maintenance and compatibility update, typically seeing several minor releases per year.
pip install pyxnatVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to establish a connection to an XNAT server using the `Interface` class and then retrieve a list of available projects. It uses environment variables for secure credential handling.
Ensure your environment uses Python 3.9 or 3.10. Newer Python versions (e.g., 3.11, 3.12, 3.13) may work but are not officially tested until explicitly stated in release notes.
Use environment variables (as in the quickstart), an `.xnatPass` configuration file (e.g., `~/.xnatPass`), or let `Interface` prompt for credentials interactively. Use `interface.save_config()` to create config files.
Migrate testing setup from `nose` to `pytest` for `pyxnat`-related test cases.
Use a different public XNAT instance (like NITRC/IR) or a locally deployed XNAT instance (e.g., via Docker) for testing and development.
Verify that the resource (project, subject, experiment, scan, resource label) you are targeting actually exists on the XNAT server. For file uploads, ensure the local file path is correct and the file exists, and that the server-side resource structure is correctly specified.
Double-check your `XNAT_USER` and `XNAT_PASSWORD` (or other credential sources) for typos. Ensure the user has the appropriate permissions on the XNAT server to access the requested data (e.g., list projects).
Add `from pyxnat import Interface` at the top of your Python script or interactive session before attempting to use `Interface`.
Ensure the `server` argument to `Interface` is a complete and correct URL, including the protocol (e.g., `https://my.xnat.org:8443/xnat`). Consult your XNAT administrator for the exact URL.