copyxnat.xnat_backend.xnat_session module

Wrappers for communicating between copyxnat items and pyXNAT backend items

class copyxnat.xnat_backend.xnat_session.RestWrapper(params)[source]

Bases: object

Wrapper around the XNAT REST API which automatically assembles the URL from the server name in the provided params and REST API URI

get_url(uri)[source]

Return full REST URL for the given URI

class copyxnat.xnat_backend.xnat_session.SessionId[source]

Bases: object

Wrapper around an XNAT session ID cookie

exists()[source]

Return True if there is an existing session ID

reset()[source]

Indicate the current session IF is no longer valid

session_header()[source]

Return XNAT session ID header for REST authentication

set(new_id)[source]

Set a new session ID

class copyxnat.xnat_backend.xnat_session.XnatSession(params, read_only=False)[source]

Bases: object

Wrapper around the XNAT REST API which automatically handles session authentication and tokens using the provided credentials

login()[source]

Create this XNAT session if it does not already exist

logout()[source]

End this XNAT session

request(method, uri, qs_params=None, body=None, headers=None, stream=None)[source]

Send a REST call to an XNAT server. The call will be authenticated automatically by adding the XNAT JSESSION ID to the REST headers. If the JSESSION ID does not already exist, it will be created by authenticating with the server using the user credentials.

Parameters
  • method – Request method (eg get, put, post)

  • uri – XNAT REST API string (excluding https://server/data/)

  • qs_params – dictionary of querystring parameters for the request

  • body – request body

  • headers – dictionary of headers for the request

  • stream – True if content is streamed

Returns

requests.Response