Skip to main content

A python client for the ChRIS API.

https://travis-ci.org/FNNDSC/python-chrisclient.svg?branch=master

Quick Overview

This repository contains various python scripts and modules that provide a rich client experience for interacting with a CUBE backend instance. Interaction is either via the command line interface (CLI) or through a Python programmatic interface using relevant modules.

Overview

Three scripts/modules are included in this repository:

  • a general CUBE client

  • a more specific plugin search utility

  • a more specific plugin run schedule utility

Installation

Use the PyPI, Luke!

pip install -U python-chrisclient

ChRIS server preconditions

These preconditions are only necessary to be able to test the client against an actual instance of a ChRIS server both during development and for the automated tests.

Install latest just command runner.

Fire up the full set of ChRIS services:

Open a terminal and run the following commands in any working directory:

$> git clone https://github.com/FNNDSC/ChRIS_ultron_backEnd.git
$> cd ChRIS_ultron_backEnd
$> just

Create a test feed and two pipelines:

Run the following shell script on the directory of this README file. NOTE: The script depends on the popular curl and jq command line tools.

$> ./pre_test.sh

Run the automated tests:

Optionally create a virtual environment and activate it and then run the automated tests.

$> pip install -e ".[dev]"
$> pytest

Tear down the full set of ChRIS services:

You can later remove all the backend containers and release storage volumes with:

$> cd ChRIS_ultron_backEnd
$> just nuke

General CUBE client usage

Python programmatic interface

Instantiate the client:

from chrisclient import client

cl = client.Client('http://localhost:8000/api/v1/', 'cube', 'cube1234')

Alternatively get a valid token for the user and instantiate the client:

token = client.Client.get_auth_token('http://localhost:8000/api/v1/auth-token/', 'cube', 'cube1234' )
cl = client.Client('http://localhost:8000/api/v1/', token=token)

Upload and create a new plugin (only works for ChRIS admins):

cl_admin = client.Client('http://localhost:8000/api/v1/', 'chris', 'chris1234')
response = cl_admin.admin_upload_plugin('host,moc', '~/simpledsapp.json')

Get plugins given search parameters:

search_params = {'name': 'pl-dircopy'}
response = cl.get_plugins(search_params)

Get a plugin by id:

plugin_id = 1
response = cl.get_plugin_by_id(plugin_id)

Get a plugin’s parameters:

plugin_id = 1
response = cl.get_plugin_parameters(plugin_id, {'limit': 50, 'offset':0})

These retrieving operations are supported for all other high level resources such as feeds, pipelines, plugin instances and workflows.

Get a pipeline’s default parameters and nodes data structure and then run a workflow from the pipeline:

pipeline_id = 2
# attempt to fetch all parameters in a single request by setting a very high limit
response = cl.get_pipeline_default_parameters(pipeline_id, {'limit': 100, 'offset':0})
nodes = cl.compute_workflow_nodes_info(response['data'])
response = cl.create_workflow(pipeline_id, {'previous_plugin_inst_id': 1, 'nodes_info': json.dumps(nodes)})

Please visit the wiki for more information about the client’s API and examples.

Standalone CLI client tool

List plugins:

chrisclient -u cube -p cube1234 http://localhost:8000/api/v1/ list plugin offset==0 limit==2 --verbose

List pipelines:

chrisclient -u cube -p cube1234 http://localhost:8000/api/v1/ list pipeline --verbose

List plugin instances:

chrisclient -u cube -p cube1234 http://localhost:8000/api/v1/ list plugininstance offset==0 limit==1

Upload and create plugin (only works for ChRIS admins):

chrisclient -u chris -p chris1234 http://localhost:8000/api/v1/ add plugin --computenames host,moc --fname ~/simpledsapp.json

Create plugin instance (run plugin):

chrisclient -u cube -p cube1234 http://localhost:8000/api/v1/ add plugininstance
 --pluginid 3 --instancedata '{"previous_id": 1, "dir": "home/cube/uploads"}'

Create pipeline:

chrisclient -u cube -p cube1234 http://localhost:8000/api/v1/ add pipeline --pipelinedata '{"name": "Pipeline1", "plugin_tree": "[{\"plugin_id\": 2, \"previous_index\": null}, {\"plugin_id\": 2, \"previous_index\": 0}]"}'

Create workflow (run pipeline):

chrisclient -u cube -p cube1234 http://localhost:8000/api/v1/ add workflow --pipelineid 2 --workflowdata '{"previous_plugin_inst_id": 1, "nodes_info": "[{\"piping_id\": 3, \"compute_resource_name\": \"host\"}, {\"piping_id\": 4, \"compute_resource_name\": \"host\"}, {\"piping_id\": 5, \"compute_resource_name\": \"host\"}]"}'

Run

Plugins can be run/scheduled on a CUBE instance using the chrispl-run script. The CLI parameters are broadly similar to chrispl-search with some semantic changes more pertinent to the run call – the for search is fixed to the plugin id and the search --pluginSpec becomes the --using CLI.

Run Examples

Run an FS plugin, pl-mri10yr06mo01da_normal

chrispl-run --plugin name=pl-mri10yr06mo01da_normal \
            --onCUBE '{
                "protocol":     "http",
                "port":         "8000",
                "address":      "%HOSTIP",
                "user":         "chris",
                "password":     "chris1234"}'

This plugin does not require any specific CLI args when run in the default state. Once posted to CUBE, a string is returned to the shell:

(name=pl-mri10yr06mo01da_normal) id 14

Indicating that the plugin instance ID of the plugin in CUBE is 14 (for example).

For convenience, let’s set:

CUBE='{
    "protocol":     "http",
    "port":         "8000",
    "address":      "%HOSTIP",
    "user":         "chris",
    "password":     "chris1234"
}'

This return construct lends itself easily to scripting:

ROOTNODE=$(./chrispl-run --plugin name=pl-mri10yr06mo01da_normal --onCUBE "$CUBE" | awk '{print $3}')

or with some formatting:

ROOTNODE=$(
    chrispl-run --plugin name=pl-mri10yr06mo01da_normal     \
                --onCUBE="$CUBE"                            |
                     awk '{print $3}'
)

Run a DS plugin, pl-freesurfer_pp, that builds on the previous node

In this manner, a workflow can be constructed. First construct the arguments for the next plugin:

ARGS="                              \
--ageSpec=10-06-01;                 \
--copySpec=sag,cor,tra,stats,3D;    \
--previous_id=$ROOTNODE             \
"

and now schedule the run:

chrispl-run --plugin name="pl-freesurfer_pp"    \
            --args="$ARGS"                      \
            --onCUBE="$CUBE"

which will return:

(name=pl-freesurfer_pp)        id 19

As before, this can be captured and used for subsequent chaining:

FSNODE=$(
    chrispl-run --plugin name=pl-freesurfer_pp  \
                --args="$ARGS"                  \
                --onCUBE="$CUBE"                |
                     awk '{print $3}'
)

Additional Reading

Consult the ChRIS_docs workflow directory for examples of workflows built using these tools.

-30-

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_chrisclient-2.15.0.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_chrisclient-2.15.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file python_chrisclient-2.15.0.tar.gz.

File metadata

  • Download URL: python_chrisclient-2.15.0.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for python_chrisclient-2.15.0.tar.gz
Algorithm Hash digest
SHA256 b5c51f4c34cccc63bb43c854a4dccd6f44ef70bb815972dd5167b450a7892ddd
MD5 0593d5245de54531d286e2fa147153a9
BLAKE2b-256 ddcdccdc92eb5afca9afcab45bfaf7d62251157c2d1577c4fbb1a5bba7385da0

See more details on using hashes here.

File details

Details for the file python_chrisclient-2.15.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_chrisclient-2.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 441240387c2b85ae9ba3d1ce69c368922b8d51f2a1842137d938079c5afd95ba
MD5 cacb3bf7ece94189a23330fbf84c4def
BLAKE2b-256 21281349d4d49fd83e484a1eb5161c6254c237efe3d159dff44ed2137122bef3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.15.0 This release

2 files

2.14.0

2 files

2.13.0

2 files

2.12.0

2 files

2.11.1

2 files

2.11.0

2 files

2.10.0

2 files

2.9.1

2 files

2.8.2

1 file

2.8.0

2 files

2.7.0

2 files

2.6.0

2 files

2.5.0

2 files

2.4.0

2 files

2.3.2

1 file

2.3.0

2 files

2.2.10

1 file

2.2.8

1 file

2.2.6

1 file

2.2.4

1 file

2.2.2

1 file

2.2.0

1 file

2.0.4

1 file

2.0.2

1 file

2.0.0

1 file

1.2.8

1 file

1.2.6

1 file

1.2.4

1 file

1.2.2

1 file

1.2.0

1 file

1.0.10

1 file

1.0.8

1 file

1.0.6

1 file

1.0.4

1 file

1.0.2

1 file

1.0.0

1 file

0.0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page