Command-line interface

We offer a command-line client for XNAT together with this library. Many of the commands have arguments for the hostname and login information. This would make each command have a lot parameters, e.g.:

$ xnat --hostname https://xnat.example.com --user username list project

To avoid having to give all these arguments for every single call, it is possible to set the hostname with an environment variable. Furthermore, you can login once and reuse the session. For example:

$ XNATPY_HOST=https://xnat.example.com
$ XNATPY_JSESSION=`xnat login --user username`
$ xnat list project
$ xnat logout

Between the login and logout all commands will automatically use the host and login specified. This avoids the need to login for every single command.

Command-line interface reference

xnat

xnat [OPTIONS] COMMAND [ARGS]...

Options

--version

Show the version and exit.

--jsession <jsession>

JSESSION value

-u, --user <user>

Username to connect to XNAT with.

-h, --host <host>

XNAT host to connect to.

-n, --netrc <netrc>

.netrc file location.

--loglevel <loglevel>

Logging verbosity level.

--output-format <output_format>

Output format

Options

raw | csv | human

--timeout <timeout>

Timeout for the command in ms.

Environment variables

XNATPY_JSESSION

Provide a default for --jsession

XNATPY_HOST

Provide a default for --host

XNATPY_LOGLEVEL

Provide a default for --loglevel

XNATPY_OUTPUT

Provide a default for --output-format

XNATPY_TIMEOUT

Provide a default for --timeout

download

Commands to download XNAT objects to your machine.

xnat download [OPTIONS] COMMAND [ARGS]...
project

Download XNAT project to the target directory.

xnat download project [OPTIONS] PROJECT TARGETDIR

Arguments

PROJECT

Required argument

TARGETDIR

Required argument

import

Commands to import data from your machine into XNAT

xnat import [OPTIONS] COMMAND [ARGS]...
experiment

Import experiment from the target folder to XNAT

xnat import experiment [OPTIONS] FOLDER

Options

--destination <destination>

The destination to upload the scan to.

--project <project>

The project in the archive to assign the session to (only accepts project ID, not a label).

--subject <subject>

The subject in the archive to assign the session to.

--experiment <experiment>

The experiment in the archive to assign the session content to.

--import_handler <import_handler>
--quarantine

Flag to indicate session should be quarantined.

--trigger_pipelines

Indicate that importing should trigger pipelines.

Arguments

FOLDER

Required argument

list

Commands to list different XNAT objects either in machine- or human-readable formats.

xnat list [OPTIONS] COMMAND [ARGS]...
projects

List projects in the target XNAT.

xnat list projects [OPTIONS]

Options

--filter <filter>

Filter criteria to select projects.

--header, --no-header

Include header in the listing or not.

--column <column>

Columns to include in the listing.

subjects

List subjects in the target XNAT.

xnat list subjects [OPTIONS]

Options

--project <project>

Project id to list subjects from.

--filter <filter>

Filter criteria to select subjects.

--header, --no-header

Include header in the listing or not.

--column <column>

Columns to include in the listing.

login

Establish a connection to XNAT and print the JSESSIONID so it can be used in sequent calls. The session is purposefully not closed so will live for next commands to use until it will time-out.

xnat login [OPTIONS]

logout

Close your current connection to XNAT.

xnat logout [OPTIONS]

prearchive

Commands for prearchive management.

xnat prearchive [OPTIONS] COMMAND [ARGS]...
archive

Archive selected prearchive session.

xnat prearchive archive [OPTIONS] __SESSIONID __PROJECT

Options

--subject <subject>

The subject in the archive to assign the content to.

--experiment <experiment>

The experiment in the archive to assign the session content to.

--overwrite <overwrite>

Action to take in case data already exists. Possible values: none, append, delete.

--quarantine

Indicate whether the session should be quarantined.

--trigger-pipelines

Indicate whether archiving should trigger pipelines.

Arguments

__SESSIONID

Required argument

__PROJECT

Required argument

delete

Delete selected prearchive sessions.

xnat prearchive delete [OPTIONS]

Options

-p, --project <project>

Project the session belongs to.

-l, --label <label>

Session label.

-s, --subject <subject>

Session subject.

--status <status>

Session status.

list

List all sessions currently in prearchive.

xnat prearchive list [OPTIONS]
move

Move selected prearchive sessions.

xnat prearchive move [OPTIONS]

Options

-p, --project <project>

Project the sessions currently belong to.

--dest-project <dest_project>

Destination project.

Session label., -l, --label <label>
Session subject., -s, --subject <subject>
Session status., --status <status>

rest

Perform various REST requests to the target XNAT.

xnat rest [OPTIONS] COMMAND [ARGS]...
delete

Perform DELETE request to the target XNAT.

xnat rest delete [OPTIONS] PATH

Options

--query <query>

The values to be added to the query string in the URI.

--headers <headers>

HTTP headers to include.

Arguments

PATH

Required argument

get

Perform GET request to the target XNAT.

xnat rest get [OPTIONS] PATH

Options

--query <query>

The values to be added to the query string in the URI.

--headers <headers>

HTTP headers to include.

Arguments

PATH

Required argument

head

Perform HEAD request to the target XNAT.

xnat rest head [OPTIONS] PATH

Options

--query <query>

The values to be added to the query string in the URI.

--headers <headers>

HTTP headers to include.

Arguments

PATH

Required argument

post

Perform POST request to the target XNAT.

xnat rest post [OPTIONS] PATH

Options

-j, --jsonpath <jsonpath>

JSON payload file location.

-d, --datapath <datapath>

Data payload file location.

--query <query>

The values to be added to the query string in the URI.

--headers <headers>

HTTP headers to include.

Arguments

PATH

Required argument

put

Perform PUT request to the target XNAT.

xnat rest put [OPTIONS] PATH

Options

-j, --jsonpath <jsonpath>

JSON payload file location.

-d, --datapath <datapath>

Data payload file location.

--query <query>

The values to be added to the query string in the URI.

--headers <headers>

HTTP headers to include.

Arguments

PATH

Required argument

script

Collection of various XNAT-related scripts.

xnat script [OPTIONS] COMMAND [ARGS]...
copy-project

Copy all data from source project to destination project. Source and destination projects can be located in different XNAT instances.

xnat script copy-project [OPTIONS]

Options

--source-host <source_host>

Required Source XNAT URL

--source-project <source_project>

Required Source XNAT project

--dest-host <dest_host>

Required Destination XNAT URL

--dest-project <dest_project>

Required Destination XNAT project

data-integrity-check

Perform data integrity check.

xnat script data-integrity-check [OPTIONS]

Options

--host <host>

Required XNAT URL

--xnat-home-dir <xnat_home_dir>

Required Path to XNAT home directory

--report <report>

Required Path to report file