slycat.web.client

class slycat.web.client.ArgumentParser(*arguments, **keywords)[source]

Bases: ArgumentParser

Return an instance of argparse.ArgumentParser, pre-configured with arguments to connect to a Slycat server.

Pre-configured options are:

  • --host – the URL of the Slycat server.

  • --port – the port of the Slycat server.

  • --http-proxy – the URL for an http proxy.

  • --https-proxy – the URL for an https proxy.

  • --verify – an SSL certificate to verify https host.

  • --no-verify – disable https verification.

  • --file-slice-size – maximum number of bytes to upload at once.

  • --user – user name.

  • --passowrd – user password.

  • --kerberos – enable kerberos authentication.

  • --log-level – log detail to display.

parse_args(list_input=None)[source]

Overrides argparse parse_args command. Parses slycat.web.client arguments in addition to any arguments added by users of the class. Can also be used to parse a list of arguments passed from a Python function, such as

>>> parser = slycat.web.client.ArgumentParser()
>>> parser.parse_args(["--host", "slycat.sandia.gov", "--kerberos"]).
class slycat.web.client.Connection(host='https://localhost', port=None, kerberos=False, file_slice_size=10000000, **keywords)[source]

Bases: object

Provides a class to facilitate communication with the Slycat web server. To use, open a connection and submit requests. For example:

>>> parser = slycat.web.client.ArgumentParser()
>>> arguments = parser.parse_args()
>>> connection = slycat.web.client.connect(arguments)
>>> projects = connection.get_projects()
delete_model(mid)[source]

Delete an existing model.

Parameters:

mid (string, required) – The unique model identifier.

delete_project(pid)[source]

Delete an existing project.

Parameters:

pid (string, required) – The unique project identifier.

delete_project_cache_object(pid, key)[source]

Delete an existing project cache object.

Parameters:
  • pid (string, required) – The unique project identifier.

  • key (string, required) – Unique cache object key.

delete_reference(rid)[source]

Delete an existing reference.

Parameters:

rid (string, required) – The unique reference identifier.

delete_remote(sid)[source]

Delete an existing remote session.

Parameters:

sid (string, required) – The unique remote session identifier.

delete_upload(uid)[source]

Delete uploaded files from Slycat server

Delete an upload session used to upload files for storage as model artifacts. This function must be called once the client no longer needs the session, whether the upload(s) have been completed successfully or the client is cancelling an incomplete session.

Note that you can examine the return codes to see if the files have been completely parsed by Slycat.

Parameters:

uid (string, required) – Unique file upload session ID.

Returns:

status_code

Http status code:

  • 204 No Content – The upload session and temporary storage has been deleted.

  • 409 Conflict – The upload session cannot be deleted, parsing is in progress.

Return type:

int

find_or_create_project(name, description='')[source]

Return a project identified by name, or newly created.

Parameters:
  • name (string, required) – The name of the project to return (or create).

  • description (string, optional) – Description to use for the new project (if a new project is created).

Returns:

pid – Unique identifier of the matching (or newly created) project.

Return type:

string

Raises:

Exception – If more than one project matches the given name.

See also

post_projects()

find_project(name)[source]

Return a project identified by name.

Parameters:

name (string, required) – The name of the project to return.

Returns:

project

Return type:

The matching project, which is an arbitrary collection of JSON-compatible data.

Raises:

Exception – If a project with a matching name can’t be found, or more than one project matches the name.

get_bookmark(bid)[source]

Retrieve an existing bookmark.

Parameters:

bid (string, required) – The unique bookmark identifier.

Returns:

bookmark – The bookmark object, which is an arbitrary collection of JSON-compatible data.

Return type:

object

get_configuration_markings()[source]

Retrieve marking information from the server.

Returns:

markings

Return type:

server marking information.

get_configuration_parsers()[source]

Retrieve parser plugin information from the server.

Returns:

parsers

Return type:

server parser plugin information.

get_configuration_remote_hosts()[source]

Retrieve remote host information from the server.

Returns:

remote_hosts

Return type:

server remote host information.

get_configuration_support_email()[source]

Retrieve support email information from the server.

Returns:

email

Return type:

server support email information.

get_configuration_version()[source]

Retrieve version information from the server.

Returns:

version

Return type:

server version information.

get_configuration_wizards()[source]

Retrieve wizard plugin information from the server.

Returns:

wizards

Return type:

server wizard plugin information.

get_model(mid)[source]

Retrieve an existing model.

Parameters:

mid (string, required) – The unique model identifier

Returns:

model – The model object, which is an arbitrary collection of JSON-compatible data.

Return type:

object

get_model_arrayset_metadata(mid, aid, arrays=None, statistics=None, unique=None)[source]

Retrieve metadata describing an existing model arrayset artifact.

Parameters:
  • mid (string, required) – The unique model identifier.

  • aid (string, required) – The unique artifact identifier.

  • arrays (string, optional) – A set of arrays, specified using HQL.

  • statistics (string, optional) – A set of attributes, specified using HQL.

  • unique (string, optional) – A set of attributes, specified using HQL.

Returns:

metadata – The arrayset metadata, which is an arbitrary collection of JSON-compatible data.

Return type:

object

get_model_file(mid, aid)[source]

Retrieves the file corresponding to a given model and artifacts.

Parameters:
  • mid (string, required) – Unique model identifier.

  • aid (string, required) – Unique (with the model) artifact id.

Returns:

file

Return type:

File data corresponding to artifact.

get_model_parameter(mid, aid)[source]

Retrieve a model parameter artifact.

Model parameters are JSON objects of arbitrary complexity. They are stored directly within the model as part of its database record, so they should be limited in size (larger data should be stored using arraysets or files).

Parameters:
  • mid (string, required) – Unique model identifier.

  • aid (string, required) – Unique (within the model) artifact id.

Returns:

parameter

Return type:

JSON-compatible object.

get_project(pid)[source]

Retrieve an existing project.

Parameters:

pid (string, required) – Unique project identifier.

Returns:

project

Return type:

Arbitrary collection of JSON-compatible data.

get_project_cache_object(pid, key)[source]

Retrieve an object from a project cache.

Parameters:
  • pid (string, required) – Unique project identifier.

  • key (string, required) – Cache object identifier.

Returns:

content

Return type:

Cached object content.

get_project_models(pid)[source]

Retrieve every model in a oroject.

Parameters:

pid (string, required) – Unique project identifier.

Returns:

models

Return type:

JSON-compatible object.

get_project_references(pid)[source]

Returns every reference in a project.

Parameters:

pid (string, required) – Unique project identifier.

Returns:

references

Return type:

JSON-compatible object.

get_projects()[source]

Retrieve all projects.

Returns:

projects

Return type:

List of projects. Each project is an arbitrary collection of JSON-compatible data.

get_remote_file(sid, path, cache=None, project=None, key=None)[source]

Retrieve a file using a remote session.

Parameters:
  • sid (string, required) – Unique remote session identifier.

  • path (string, required) – Remote filesystem path (must be absolute).

  • cache (string, optional) – Optional server-side cache for the retrieved file. Must be None or “project”.

  • project (string, optional) – If cache is set to “project”, this must specify a unique project identifier.

  • key (string, optional) – if cache is set to “project”, this must specify a unique key for the cached object.

Returns:

file

Return type:

Remote file contents.

get_remote_image(sid, path, cache=None, project=None, key=None)[source]

Retrieve an image using a remote session.

Parameters:
  • sid (string, required) – Unique remote session identifier.

  • path (string, required) – Remote filesystem path (must be absolute).

  • cache (string, optional) – Optional server-side cache for the retrieved image. Must be None or “project”.

  • project (string, optional) – If cache is set to “project”, this must specify a unique project identifier.

  • key (string, optional) – if cache is set to “project”, this must specify a unique key for the cached object.

Returns:

image

Return type:

Remote image contents.

get_user(uid=None)[source]

Retrieve directory information about an existing user.

Parameters:

uid (string, optional) – Unique user identifier. If unspecified, returns information about the user making the call.

Returns:

user

Return type:

Arbitrary collection of JSON-compatible data.

join_model(mid)[source]

Wait for a model to complete before returning.

A Slycat model goes through several distinct phases over its lifetime:

  1. The model is created.

  2. Input artifacts are pushed into the model.

  3. The model is marked “finished”.

  4. Optional one-time computation is performed on the server, storing output artifacts.

  5. The model is complete and ready to be viewed.

Use this function in scripts that have performed steps 1, 2, and 3 and need to wait until step 4 completes.

Parameters:

mid (string, required) – Unique model identifier.

Notes

A model that hasn’t been finished will never complete - you should ensure that post_model_finish() is called successfully before calling join_model().

post_events(path, parameters={})[source]

Post event to be logged on Slycat server.

Parameters:
  • path (string, required) – Path-like URI describing event to be logged.

  • parameters (dictionary, optional) – JSON type object describing event.

post_model_files(mid, aids, files, parser, input=True, parameters={})[source]

Stores model file artifacts.

Parameters:
  • mid (string, required) – Unique model identifier.

  • aids (array, required) – Artifact IDs for model storage.

  • files (array, required) – Local files for upload.

  • parser (string, required) – Name of Slycat parser that will process the files.

  • input (boolean, optional) – Set as true (default) to store as model artifacts.

  • parametrs (dictionary, optional) – Additional data to pass to parser.

post_model_finish(mid)[source]

Notify the server that a model is fully initialized.

When called, the server will perform one-time computation for the given model type.

Parameters:

mid (string, required) – Unique model identifier.

post_project_bookmarks(pid, bookmark)[source]

Store a bookmark.

Parameters:
  • pid (string, required) – Unique project identifier.

  • bookmark (object) – Arbitrary collection of JSON-compatible data.

Returns:

bid – Unique bookmark identifier.

Return type:

string

post_project_models(pid, mtype, name, marking='', description='')[source]

Creates a new model, returning the model ID.

Parameters:
  • pid (string, required) – Unique project identifier.

  • mtype (string, required) – Model type.

  • name (string, required) – Model name.

  • marking (string, optional) – Model marking.

  • description (string, optional) – Description of model.

Returns:

mid – New model identifier.

Return type:

string

post_project_references(pid, name, mtype=None, mid=None, bid=None)[source]

Store a project reference.

Parameters:
  • pid (string, required) – Unique project identifier.

  • name (string, required) – Reference name.

  • mtype (string, optional) – Optional model type.

  • mid (string, optional) – Optional model identifier.

  • bid (string, optional) – Optional bookmark identifier.

Returns:

rid – Unique reference identifier.

Return type:

string

See also

POST /api/projects/(pid)/references

post_projects(name, description='')[source]

Creates a new project, returning the project ID.

Parameters:
  • name (string, required) – Name of project to be created.

  • description (string, optional) – Description of new project.

Returns:

pid – Unique project identifier.

Return type:

string

post_remote_browse(sid, path, file_reject=None, file_allow=None, directory_allow=None, directory_reject=None)[source]

Uses an existing remote session to retrieve remote filesystem information.

Parameters:
  • sid (string, required) – Session ID for connection.

  • path (string, required) – Remote file system path (must be absolute).

  • file_reject (string, optional) – Regular expression for rejecting files.

  • file_allow (string, optional) – Regular expression for retaining files.

  • directory_reject (string, optional) – Regular expression for rejecting directories.

  • directory_allow (string, optional) – Regular expression for retaining directories.

Returns:

response_body

Return type:

JSON like object.

post_remotes(hostname, username, password, agent=None)[source]

Creates a new remote connection from the Slycat server to another host.

Parameters:
  • hostname (string, required) – Name of remote host.

  • username (string, required) – User name for connection.

  • password (string, required) – Password to authenticate connection.

  • agent (boolean, optional) – Create an agent upon establishing connection.

Returns:

sid – Session ID for connection.

Return type:

string

post_upload_finished(uid, file_parts)[source]

Notify Slycat server that file upload is finished

Notify the server that all files have been uploaded for the given upload session, and processing can begin. The request must include the uploaded parameter, which specifies the number of files that were uploaded, and the number of parts in each file. The server uses this information to validate that it received every part of every file that the client sent.

Parameters:
  • uid (string, required) – Unique file upload session ID.

  • file_parts (array, required) – Array of length number of files, with each entry number of slices for that file.

post_uploads(mid, parser, aids, input=True)[source]

Create Slycat file upload session.

Create an upload session used to upload files for storage as model artifacts. Once an upload session has been created, use upload_file put_upload_file_part to upload files directly from the client to the server.

Parameters:
  • mid (string, required) – Unique model identifier.

  • parser (string,) – Name of parser to call after completion of upload.

  • aids (array, required) – Artifact IDs for storage.

  • input (boolean, optional) – True to create input artifacts for the model.

Returns:

uid – Upload session ID.

Return type:

string

put_model(mid, model)[source]

Modify a Slycat model.

Parameters:
  • mid (string, required) – Model identifier.

  • model (dictionary, required) –

    JSON like dictionary with fields to modified model including:

    • name (string, optional)

    • description (string, optional)

    • state (string, optional)

    • progress (float, optional)

    • message (string, optional)

put_model_arrayset(mid, aid, input=True)[source]

Starts a new model array set artifact, ready to receive data.

Parameters:
  • mid (string, required) – Unique model identifier.

  • aid (string, required) – Unique artifact identifier.

  • input (boolean, optional) – Set to true (default) if array set is a model input.

put_model_arrayset_array(mid, aid, array, dimensions, attributes)[source]

Starts a new array set array, ready to receive data.

Parameters:
  • mid (string, required) – Unique model identifier.

  • aid (string, required) – Unique artifact identifier.

  • array (int, required) – Unique array index.

  • dimensions (array, required) – Array dimensions.

  • attributes (array, required) – Array attributes (data types).

put_model_arrayset_data(mid, aid, hyperchunks, data, force_json=False)[source]

Write data to an arrayset artifact on the server.

Parameters:
  • mid (string, required) – Unique model identifier.

  • aid (string, required) – Unique (to the model) arrayset artifact id.

  • hyperchunks (string, required) – Specifies where the data will be stored, in Hyperchunks format.

  • data (iterable, required)) – A collection of numpy.ndarray data chunks to be uploaded. The number of data chunks must match the number implied by the hyperchunks parameter.

  • force_json (bool, optional)) – Force the client to upload data using JSON instead of the binary format.

put_model_inputs(source, target)[source]

Copies the input artifacts from one model to another. Both models must be part of the same project. By default, array artifacts are copied by reference instead of value for efficiency.

Parameters:
  • source (string, required) – Model ID source of artifacts.

  • target (string, required) – Model ID target for artifacts.

put_model_parameter(mid, aid, value, input=True)[source]

Store a model parameter artifact.

Model parameters are JSON objects of arbitrary complexity. They are stored directly within the model as part of its database record, so they should be limited in size (larger data should be stored using arraysets or files).

To get the value of a parameter artifact, use get_model() and read the value directly from the model record. An artifact id foo will be accessible in the record as model[“artifact:foo”].

Parameters:
  • mid (string, required) – Unique model identifier.

  • aid (string, required) – Unique (within the model) artifact id.

  • value (object, required) – An arbitrary collection of JSON-compatible data.

  • input (boolean, optional) – Marks whether this artifact is a model input.

put_project(pid, project)[source]

Modifies a project.

Parameters:
  • pid (string, required) – Unique project identifier.

  • project (dictionary, required) –

    JSON like dictionary with fields to modified model including:

    • name (string, optional)

    • description (string, optional)

    • acl (string, optional) – access control list

put_upload_file_part(uid, pid, fid, file_slice)[source]

Upload a file or part of a file to Slycat.

Upload a file (or part of a file) as part of an upload session created with post_uploads.

Use the “pid” and “fid” parameters to specify that the data being uploaded is for part M of file N. To upload a file from the client, specify the “file” parameter.

Parameters:
  • uid (string, required) – Unique file upload session ID.

  • pid (string, required) – Zero-based part ID of file being uploaded.

  • fid (string, required) – Zero-based file ID for file being uploaded.

  • file (file part in bytes, required) – File part to upload.

request(method, path, **keywords)[source]

Basic request to Slycat server using open session. To make a request provide the HTTP method and path, and this method will return the body of the response. Additional keyword arguments must be compatible with the Python requests library.

Parameters:
  • method (string, required) – The HTTP method to use, e.g. “GET”, “PUT”, etc.

  • path (string, required) – The extension to the URL for the Slycat server, e.g. “/api/models/(mid)”.

Returns:

response

Return type:

the body of the Server response.

update_model(mid, **kwargs)[source]

Update model state.

This function provides a more convenient alternative to put_model().

See also

put_model()

upload_files(mid, file_list, parser, parser_parms, progress=True)[source]

Upload a list of files for a given model to the Slycat server. The files will be parsed by specified parser. This is not a direct call to the API, but rather a convenience call to load/parse a list of files.

Parameters:
  • mid (string, required) – Model ID associated with the files to be uploaded.

  • file_list (string array, required) – Local files to be uploaded to the Slycat server. This can be one file, but it should be passed as an array with one file.

  • parser (string, required) – Name of parser to use on the Slycat server.

  • parser_parms (array, required) – Any parameters to be passed to the parser (passed using aids when the upload session is established).

  • progress (boolean, optional) – Display a download progress indicator using standard out (will not be logged to the log file).

slycat.web.client.connect(arguments, **keywords)[source]

Factory function for client connections that takes an option parser as input.

Parameters:
  • arguments (argument parser object, required) – Parsed command line arguments.

  • keywords (dictionary, optional) – Additional options to pass to requests.

Returns:

connection

Return type:

session for submitting requests to Slycat sever.