Skip to main content

(Python) client for the ChRIS API

Project description

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

At time of writing (early 2022), three scripts/modules are in production:

  • 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

General CUBE client usage

Python programmatic interface

Instantiate the client:

from chrisclient import client

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

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-

Project details


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.11.1.tar.gz (29.7 kB view details)

Uploaded Source

Built Distribution

python_chrisclient-2.11.1-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file python-chrisclient-2.11.1.tar.gz.

File metadata

  • Download URL: python-chrisclient-2.11.1.tar.gz
  • Upload date:
  • Size: 29.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.19

File hashes

Hashes for python-chrisclient-2.11.1.tar.gz
Algorithm Hash digest
SHA256 fec717db1d1b3089d19c94e3ee060b2f51809e0dbed88676e14f5e5795839924
MD5 c100ed670d6b7eaf30f5c2398718f15b
BLAKE2b-256 961c5b2241f692b6ca3787be8ce63f7124b8147ff8380283e216e9e1184e0b92

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_chrisclient-2.11.1-py3-none-any.whl
  • Upload date:
  • Size: 31.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.19

File hashes

Hashes for python_chrisclient-2.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 972191f4d32d0fd9206adca32ccc9b0c98106b40425ff4bb85013e66979a6488
MD5 1d66661ac79a84d2c5afa8e61fda790d
BLAKE2b-256 c685fae90767875c1f51b1f12ddff31ad631d9a7ddb62e799fd8b67054a402a1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page