weaver.cli

Module Contents

weaver.cli.AnyRequestMethod[source]
weaver.cli.LOGGER[source]
weaver.cli.OPERATION_ARGS_TITLE = Operation Arguments[source]
weaver.cli.OPTIONAL_ARGS_TITLE = Optional Arguments[source]
weaver.cli.REQUIRED_ARGS_TITLE = Required Arguments[source]
class weaver.cli.OperationResult(success: Ellipsis = None, message: Optional[str] = None, body: Optional[Union[str, weaver.typedefs.JSON]] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, text: Optional[str] = None, code: Optional[int] = None, **kwargs)[source]

Data container for any WeaverClient operation results.

Parameters
  • success – Success status of the operation.

  • message – Detail extracted from response content if available.

  • headers – Headers returned by the response for reference.

  • body – Content of JSON response or fallback in plain text.

  • text – Pre-formatted text representation of body.

Initialize self. See help(type(self)) for accurate signature.

success :Optional[bool] = False[source]
message :Optional[str] =[source]
headers :Optional[weaver.typedefs.AnyHeadersContainer][source]
body :Optional[Union[weaver.typedefs.JSON, str]][source]
code :Optional[int][source]
property text str[source]

Obtain HTTP headers sorted in the result that corresponds to any link reference.

Parameters

header_names – Limit link names to be considered. By default, considered headers are Link, Content-Location and Location.

class weaver.cli.AuthHandler(identity: Optional[str] = None, password: Optional[str] = None, url: Optional[str] = None, method: weaver.typedefs.AnyRequestMethod = 'GET', headers: Optional[weaver.typedefs.AnyHeadersContainer] = None)[source]

Base class that all auth implementations derive from

url :Optional[str][source]
method :weaver.typedefs.AnyRequestMethod = GET[source]
headers :Optional[weaver.typedefs.AnyHeadersContainer][source]
identity :Optional[str][source]
password :Optional[str][source]
class weaver.cli.BasicAuthHandler(username: str, password: str, **kwargs: Any)[source]

Adds the Authorization header formed from basic authentication encoding of username and password to the request.

Authentication URL and method are not needed for this handler.

property username str[source]
class weaver.cli.RequestAuthHandler(identity: Optional[str] = None, password: Optional[str] = None, url: Optional[str] = None, method: weaver.typedefs.AnyRequestMethod = 'GET', headers: Optional[weaver.typedefs.AnyHeadersContainer] = None)[source]

Base class to send a request in order to retrieve an authorization token.

property auth_token_name str[source]

Override token name to retrieve in response authentication handler implementation.

Default looks amongst common names: [auth, access_token, token]

abstract auth_header(token: str) weaver.typedefs.AnyHeadersContainer[source]

Obtain the header definition with the provided authorization token.

request_auth() Optional[str][source]

Performs a request using authentication parameters to retrieve the authorization token.

response_parser(response: requests.Response) Optional[str][source]

Parses a valid authentication response to extract the received authorization token.

class weaver.cli.BearerAuthHandler(identity: Optional[str] = None, password: Optional[str] = None, url: Optional[str] = None, method: weaver.typedefs.AnyRequestMethod = 'GET', headers: Optional[weaver.typedefs.AnyHeadersContainer] = None)[source]

Adds the Authorization header formed of the authentication bearer token from the underlying request.

auth_header(token: str) weaver.typedefs.AnyHeadersContainer[source]

Obtain the header definition with the provided authorization token.

class weaver.cli.CookieAuthHandler(identity: Optional[str] = None, password: Optional[str] = None, url: Optional[str] = None, method: weaver.typedefs.AnyRequestMethod = 'GET', headers: Optional[weaver.typedefs.AnyHeadersContainer] = None)[source]

Adds the Authorization header formed of the authentication bearer token from the underlying request.

auth_header(token: str) weaver.typedefs.AnyHeadersContainer[source]

Obtain the header definition with the provided authorization token.

class weaver.cli.WeaverClient(url: Optional[str] = None, auth: Optional[AuthHandler] = None)[source]

Client that handles common HTTP requests with a Weaver or similar OGC API - Processes instance.

Initialize the client with predefined parameters.

Parameters
  • url – Instance URL to employ for each method call. Must be provided each time if not defined here.

  • auth – Instance authentication handler that will be applied for every request. For specific authentication method on per-request basis, parameter should be provided to respective methods. Should perform required adjustments to request to allow access control of protected contents.

monitor_timeout = 60[source]
monitor_interval = 5[source]
auth :AuthHandler[source]
processes[source]

Alias of capabilities() for Process listing.

_request(method: Ellipsis, url: str, *args: Optional[weaver.typedefs.AnyHeadersContainer], headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, x_headers: Optional[int] = None, request_timeout: Optional[int] = None, request_retries=None, **kwargs) weaver.typedefs.AnyResponseType[source]
_get_url(url: Optional[str]) str[source]
static _parse_url(url)[source]
static _parse_result(response: Ellipsis, body: Optional[weaver.typedefs.JSON] = None, message: Optional[str] = None, success: Optional[bool] = None, with_headers: bool = False, with_links: bool = True, nested_links: Optional[str] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None, content_type: Optional[weaver.formats.ContentType] = None) OperationResult[source]
static _parse_deploy_body(body: Optional[Union[weaver.typedefs.JSON, str]], process_id: Optional[str]) OperationResult[source]
static _parse_deploy_package(body: weaver.typedefs.JSON, cwl: Optional[weaver.typedefs.CWL], wps: Optional[str], process_id: Optional[str], headers: weaver.typedefs.HeadersType) OperationResult[source]
_parse_job_ref(job_reference: str, url: Optional[str] = None) Tuple[Optional[str], Optional[str]][source]
static _parse_auth_token(token: Optional[str], username: Optional[str], password: Optional[str]) weaver.typedefs.HeadersType[source]
register(provider_id: Ellipsis, provider_url: str, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Registers a remote Provider using specified references.

Parameters
  • provider_id – Identifier to employ for registering the new Provider.

  • provider_url – Endpoint location to register the new remote Provider.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Results of the operation.

unregister(provider_id: Ellipsis, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Unregisters a remote Provider using the specified identifier.

Parameters
  • provider_id – Identifier to employ for unregistering the Provider.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Results of the operation.

deploy(process_id: Ellipsis = None, body: Optional[Union[weaver.typedefs.JSON, str]] = None, cwl: Optional[Union[weaver.typedefs.CWL, str]] = None, wps: Optional[str] = None, token: Optional[str] = None, username: Optional[str] = None, password: Optional[str] = None, undeploy: bool = False, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Deploy a new Process with specified metadata and reference to an Application Package.

The referenced Application Package must be one of: - CWL body, local file or URL in JSON or YAML format - WPS process URL with XML response - WPS-REST process URL with JSON response - OGC API - Processes process URL with JSON response

If the reference is resolved to be a Workflow, all its underlying Process steps must be available under the same URL that this client was initialized with.

Parameters
  • process_id – Desired process identifier. Can be omitted if already provided in body contents or file.

  • body – Literal JSON contents, either using string representation of actual Python objects forming the request body, or file path/URL to YAML or JSON contents of the request body. Other parameters (process_id, cwl) can override corresponding fields within the provided body.

  • cwl – Literal JSON or YAML contents, either using string representation of actual Python objects, or file path/URL with contents of the CWL definition of the Application package to be inserted into the body.

  • wps – URL to an existing WPS process (WPS-1/2 or WPS-REST/OGC-API).

  • token – Authentication token for accessing private Docker registry if CWL refers to such image.

  • username – Username to form the authentication token to a private Docker registry.

  • password – Password to form the authentication token to a private Docker registry.

  • undeploy – Perform undeploy as necessary before deployment to avoid conflict with exiting Process.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Results of the operation.

undeploy(process_id: Ellipsis, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Undeploy an existing Process.

Parameters
  • process_id – Identifier of the process to undeploy.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Results of the operation.

capabilities(url: Ellipsis = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, with_providers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None, sort: Optional[weaver.sort.Sort] = None, page: Optional[int] = None, limit: Optional[int] = None, detail: bool = False) OperationResult[source]

List all available Process on the instance.

Parameters
  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • with_providers – Indicate if remote providers should be listed as well along with local processes.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

  • sort – Sorting field to list processes. Name must be one of the fields supported by process objects.

  • page – Paging index to list processes.

  • limit – Amount of processes to list per page.

  • detail – Obtain detailed process descriptions.

Returns

Results of the operation.

describe(process_id: Ellipsis, provider_id: Optional[str] = None, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, schema: Optional[weaver.processes.constants.ProcessSchemaType] = ProcessSchema.OGC, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Describe the specified Process.

Parameters
  • process_id – Identifier of the local or remote process to describe.

  • provider_id – Identifier of the provider from which to locate a remote process to describe.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • schema – Representation schema of the returned process description.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Results of the operation.

_get_process_url(url: str, process_id: str, provider_id: Optional[str] = None) str[source]
static _parse_inputs(inputs: Optional[Union[str, weaver.typedefs.JSON]]) Union[OperationResult, weaver.typedefs.ExecutionInputsMap][source]

Parse multiple different representation formats and input sources into standard OGC inputs.

Schema OGC is selected to increase compatibility coverage with potential non-Weaver servers only conforming to standard OGC API - Processes.

Inputs can be represented as CLI option string arguments, file path to load contents from, or directly supported list or mapping of execution inputs definitions.

_update_files(inputs: weaver.typedefs.ExecutionInputsMap, url: Optional[str] = None) Union[Tuple[weaver.typedefs.ExecutionInputsMap, weaver.typedefs.HeadersType], OperationResult][source]

Replaces local file paths by references uploaded to the Vault.

See also

Parameters

inputs – Input values for submission of Process execution.

Returns

Updated inputs or the result of a failing intermediate request.

execute(process_id: Ellipsis, provider_id: Optional[str] = None, inputs: Optional[Union[str, weaver.typedefs.JSON]] = None, monitor: bool = False, timeout: Optional[int] = None, interval: Optional[int] = None, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None, output_refs: Optional[Iterable[str]] = None) OperationResult[source]

Execute a Job for the specified Process with provided inputs.

When submitting inputs with OGC API - Processes schema, top-level inputs field is expected. Under this field, either the OGC mapping (key-value) or listing (id,value) representations are accepted.

If the top-level inputs field is not found, the alternative CWL representation will be assumed. When submitting inputs with CWL job schema, plain key-value(s) pairs are expected. All values should be provided directly under the key (including arrays), except for File type that must include details as the class: File and path with location.

Note

Execution requests are always accomplished asynchronously. To obtain the final Job status as if they were executed synchronously, provide the monitor argument. This offers more flexibility over servers that could decide to ignore sync/async preferences, and avoids closing/timeout connection errors that could occur for long running processes, since status is pooled iteratively rather than waiting.

Parameters
  • process_id – Identifier of the local or remote process to execute.

  • provider_id – Identifier of the provider from which to locate a remote process to execute.

  • inputs – Literal JSON or YAML contents of the inputs submitted and inserted into the execution body, using either the OGC API - Processes or CWL format, or a file path/URL referring to them.

  • monitor – Automatically perform Job execution monitoring until completion or timeout to obtain final results. If requested, this operation will become blocking until either the completed status or timeout is reached.

  • timeout – Monitoring timeout (seconds) if requested.

  • interval – Monitoring interval (seconds) between job status polling requests.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

  • output_refs – Indicates which outputs by ID to be returned as HTTP Link header reference instead of body content value. With reference transmission mode, outputs that contain literal data will be linked by text/plain file containing the data. outputs that refer to a file reference will simply contain that URL reference as link. With value transmission mode (default behavior when outputs are not specified in this list), outputs are returned as direct values (literal or href) within the response content body.

Returns

Results of the operation.

upload(file_path: Ellipsis, content_type: Optional[str] = None, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Upload a local file to the Vault.

Note

Feature only available for Weaver instances. Not available for standard OGC API - Processes.

See also

More details about formats and operations related to Vault are provided in File Vault Inputs and vault chapters.

Parameters
  • file_path – Location of the file to be uploaded.

  • content_type – Explicit Content-Type of the file. This should be an IANA Media-Type, optionally with additional parameters such as charset. If not provided, attempts to guess it based on the file extension.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Results of the operation.

jobs(url: Ellipsis = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None, sort: Optional[weaver.sort.Sort] = None, page: Optional[int] = None, limit: Optional[int] = None, status: Optional[weaver.status.StatusType] = None, detail: bool = False, groups: bool = False) OperationResult[source]

Obtain a listing of Job.

Parameters
  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

  • sort – Sorting field to list jobs. Name must be one of the fields supported by job objects.

  • page – Paging index to list jobs.

  • limit – Amount of jobs to list per page.

  • status – Filter job listing only to matching status.

  • detail – Obtain detailed job descriptions.

  • groups – Obtain grouped representation of jobs per provider and process categories.

Returns

Retrieved status of the job.

status(job_reference: Ellipsis, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Obtain the status of a Job.

Parameters
  • job_reference – Either the full Job status URL or only its UUID.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Retrieved status of the job.

monitor(job_reference: Ellipsis, timeout: Optional[int] = None, interval: Optional[int] = None, wait_for_status: str = Status.SUCCEEDED, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Monitor the execution of a Job until completion.

Parameters
  • job_reference – Either the full Job status URL or only its UUID.

  • timeout – timeout (seconds) of maximum wait time for monitoring if completion is not reached.

  • interval – wait interval (seconds) between polling monitor requests.

  • wait_for_status – monitor until the requested status is reached (default: job failed or succeeded).

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Result of the successful or failed job, or timeout of monitoring process.

_download_references(outputs: weaver.typedefs.ExecutionResults, out_links: weaver.typedefs.AnyHeadersContainer, out_dir: str, job_id: str, auth: Optional[AuthHandler] = None) weaver.typedefs.ExecutionResults[source]

Download file references from results response contents and link headers.

Downloaded files extend the results contents with path and source fields to indicate where the retrieved files have been saved and where they came from. When files are found by HTTP header links, they are added to the output contents to generate a combined representation in the operation result.

results(job_reference: Ellipsis, out_dir: Optional[str] = None, download: bool = False, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Obtain the results of a successful Job execution.

Parameters
  • job_reference – Either the full Job status URL or only its UUID.

  • out_dir – Output directory where to store downloaded files if requested (default: CURDIR/JobID/<outputs>).

  • download – Download any file reference found within results (CAUTION: could transfer lots of data!).

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Result details and local paths if downloaded.

dismiss(job_reference: Ellipsis, url: Optional[str] = None, auth: Optional[AuthHandler] = None, headers: Optional[weaver.typedefs.AnyHeadersContainer] = None, with_links: bool = True, with_headers: bool = False, request_timeout: Optional[int] = None, request_retries: Optional[int] = None, output_format: Optional[weaver.formats.AnyOutputFormat] = None) OperationResult[source]

Dismiss pending or running Job, or clear result artifacts from a completed Job.

Parameters
  • job_reference – Either the full Job status URL or only its UUID.

  • url – Instance URL if not already provided during client creation.

  • auth – Instance authentication handler if not already created during client creation. Should perform required adjustments to request to allow access control of protected contents.

  • headers – Additional headers to employ when sending request. Note that this can break functionalities if expected headers are overridden. Use with care.

  • with_links – Indicate if links section should be preserved in returned result body.

  • with_headers – Indicate if response headers should be returned in result output.

  • request_timeout – Maximum timout duration (seconds) to wait for a response when performing HTTP requests.

  • request_retries – Amount of attempt to retry HTTP requests in case of failure.

  • output_format – Select an alternate output representation of the result body contents.

Returns

Obtained result from the operation.

weaver.cli.setup_logger_from_options(logger: logging.Logger, args: argparse.Namespace) None[source]

Uses argument parser options to setup logging level from specified flags.

Setup both the specific CLI logger that is provided and the top-level package logger.

weaver.cli.make_logging_options(parser: argparse.ArgumentParser) None[source]

Defines argument parser options for logging operations.

weaver.cli.add_url_param(parser: argparse.ArgumentParser, required: bool = True) None[source]
weaver.cli.add_shared_options(parser: argparse.ArgumentParser) None[source]
weaver.cli.add_listing_options(parser: argparse.ArgumentParser, item: str) None[source]
weaver.cli.parse_auth(kwargs: Dict[str, Union[Type[AuthHandler], str, None]]) Optional[AuthHandler][source]

Parses arguments that can define an authentication handler and remove them from dictionary for following calls.

weaver.cli.add_provider_param(parser: argparse.ArgumentParser, description: Optional[str] = None, required: bool = True) None[source]
weaver.cli.add_process_param(parser: argparse.ArgumentParser, description: Optional[str] = None, required: bool = True) None[source]
weaver.cli.add_job_ref_param(parser: argparse.ArgumentParser) None[source]
weaver.cli.add_timeout_param(parser: argparse.ArgumentParser) None[source]
weaver.cli.set_parser_sections(parser: argparse.ArgumentParser) None[source]
class weaver.cli.ValidateAuthHandlerAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Information about how to convert command line strings to Python objects.

Action objects are used by an ArgumentParser to represent the information needed to parse a single argument from one or more strings from the command line. The keyword arguments to the Action constructor are also all attributes of Action instances.

Keyword Arguments:

  • option_strings – A list of command-line option strings which

    should be associated with this action.

  • dest – The name of the attribute to hold the created object(s)

  • nargs – The number of command-line arguments that should be

    consumed. By default, one argument will be consumed and a single value will be produced. Other values include:

    • N (an integer) consumes N arguments (and produces a list)

    • ‘?’ consumes zero or one arguments

    • ‘*’ consumes zero or more arguments (and produces a list)

    • ‘+’ consumes one or more arguments (and produces a list)

    Note that the difference between the default and nargs=1 is that with the default, a single value will be produced, while with nargs=1, a list containing a single value will be produced.

  • const – The value to be produced if the option is specified and the

    option uses an action that takes no values.

  • default – The value to be produced if the option is not specified.

  • type – A callable that accepts a single string argument, and

    returns the converted value. The standard Python types str, int, float, and complex are useful examples of such callables. If None, str is used.

  • choices – A container of values that should be allowed. If not None,

    after a command-line argument has been converted to the appropriate type, an exception will be raised if it is not a member of this collection.

  • required – True if the action must always be specified at the

    command line. This is only meaningful for optional command-line arguments.

  • help – The help string describing the argument.

  • metavar – The name to be used for the option’s argument with the

    help string. If None, the ‘dest’ value will be used as the name.

class weaver.cli.ValidateMethodAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Information about how to convert command line strings to Python objects.

Action objects are used by an ArgumentParser to represent the information needed to parse a single argument from one or more strings from the command line. The keyword arguments to the Action constructor are also all attributes of Action instances.

Keyword Arguments:

  • option_strings – A list of command-line option strings which

    should be associated with this action.

  • dest – The name of the attribute to hold the created object(s)

  • nargs – The number of command-line arguments that should be

    consumed. By default, one argument will be consumed and a single value will be produced. Other values include:

    • N (an integer) consumes N arguments (and produces a list)

    • ‘?’ consumes zero or one arguments

    • ‘*’ consumes zero or more arguments (and produces a list)

    • ‘+’ consumes one or more arguments (and produces a list)

    Note that the difference between the default and nargs=1 is that with the default, a single value will be produced, while with nargs=1, a list containing a single value will be produced.

  • const – The value to be produced if the option is specified and the

    option uses an action that takes no values.

  • default – The value to be produced if the option is not specified.

  • type – A callable that accepts a single string argument, and

    returns the converted value. The standard Python types str, int, float, and complex are useful examples of such callables. If None, str is used.

  • choices – A container of values that should be allowed. If not None,

    after a command-line argument has been converted to the appropriate type, an exception will be raised if it is not a member of this collection.

  • required – True if the action must always be specified at the

    command line. This is only meaningful for optional command-line arguments.

  • help – The help string describing the argument.

  • metavar – The name to be used for the option’s argument with the

    help string. If None, the ‘dest’ value will be used as the name.

methods = ['GET', 'HEAD', 'POST', 'PUT', 'DELETE'][source]
class weaver.cli.ValidateHeaderAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Information about how to convert command line strings to Python objects.

Action objects are used by an ArgumentParser to represent the information needed to parse a single argument from one or more strings from the command line. The keyword arguments to the Action constructor are also all attributes of Action instances.

Keyword Arguments:

  • option_strings – A list of command-line option strings which

    should be associated with this action.

  • dest – The name of the attribute to hold the created object(s)

  • nargs – The number of command-line arguments that should be

    consumed. By default, one argument will be consumed and a single value will be produced. Other values include:

    • N (an integer) consumes N arguments (and produces a list)

    • ‘?’ consumes zero or one arguments

    • ‘*’ consumes zero or more arguments (and produces a list)

    • ‘+’ consumes one or more arguments (and produces a list)

    Note that the difference between the default and nargs=1 is that with the default, a single value will be produced, while with nargs=1, a list containing a single value will be produced.

  • const – The value to be produced if the option is specified and the

    option uses an action that takes no values.

  • default – The value to be produced if the option is not specified.

  • type – A callable that accepts a single string argument, and

    returns the converted value. The standard Python types str, int, float, and complex are useful examples of such callables. If None, str is used.

  • choices – A container of values that should be allowed. If not None,

    after a command-line argument has been converted to the appropriate type, an exception will be raised if it is not a member of this collection.

  • required – True if the action must always be specified at the

    command line. This is only meaningful for optional command-line arguments.

  • help – The help string describing the argument.

  • metavar – The name to be used for the option’s argument with the

    help string. If None, the ‘dest’ value will be used as the name.

class weaver.cli.ValidateNonZeroPositiveNumberAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Information about how to convert command line strings to Python objects.

Action objects are used by an ArgumentParser to represent the information needed to parse a single argument from one or more strings from the command line. The keyword arguments to the Action constructor are also all attributes of Action instances.

Keyword Arguments:

  • option_strings – A list of command-line option strings which

    should be associated with this action.

  • dest – The name of the attribute to hold the created object(s)

  • nargs – The number of command-line arguments that should be

    consumed. By default, one argument will be consumed and a single value will be produced. Other values include:

    • N (an integer) consumes N arguments (and produces a list)

    • ‘?’ consumes zero or one arguments

    • ‘*’ consumes zero or more arguments (and produces a list)

    • ‘+’ consumes one or more arguments (and produces a list)

    Note that the difference between the default and nargs=1 is that with the default, a single value will be produced, while with nargs=1, a list containing a single value will be produced.

  • const – The value to be produced if the option is specified and the

    option uses an action that takes no values.

  • default – The value to be produced if the option is not specified.

  • type – A callable that accepts a single string argument, and

    returns the converted value. The standard Python types str, int, float, and complex are useful examples of such callables. If None, str is used.

  • choices – A container of values that should be allowed. If not None,

    after a command-line argument has been converted to the appropriate type, an exception will be raised if it is not a member of this collection.

  • required – True if the action must always be specified at the

    command line. This is only meaningful for optional command-line arguments.

  • help – The help string describing the argument.

  • metavar – The name to be used for the option’s argument with the

    help string. If None, the ‘dest’ value will be used as the name.

class weaver.cli.ParagraphFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]

Formatter for generating usage messages and argument help strings.

Only the name of this class is considered a public API. All the methods provided by the class are considered an implementation detail.

property help_mode[source]
format_help() str[source]
_format_usage(*args, **kwargs)[source]
_format_action(action: argparse.Action) str[source]

Override the returned help message with available options and shortcuts for description paragraphs.

This ensures that paragraphs defined the argument’s help remain separated and properly formatted.

class weaver.cli.SubArgumentParserFixedMutexGroups(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)[source]

Patch incorrectly handled mutually exclusive groups sections in subparsers.

_add_container_actions(container)[source]
class weaver.cli.ArgumentParserFixedRequiredArgs(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True)[source]

Override action grouping under ‘required’ section to consider explicit flag even if action has option prefix.

Default behaviour places option prefixed (-, --) arguments into optionals even if required is defined. Help string correctly considers this flag and doesn’t place those arguments in brackets ([--<optional-arg>]).

_add_action(action)[source]
class weaver.cli.WeaverSubParserAction(option_strings, prog, parser_class, dest=SUPPRESS, required=False, help=None, metavar=None)[source]

Information about how to convert command line strings to Python objects.

Action objects are used by an ArgumentParser to represent the information needed to parse a single argument from one or more strings from the command line. The keyword arguments to the Action constructor are also all attributes of Action instances.

Keyword Arguments:

  • option_strings – A list of command-line option strings which

    should be associated with this action.

  • dest – The name of the attribute to hold the created object(s)

  • nargs – The number of command-line arguments that should be

    consumed. By default, one argument will be consumed and a single value will be produced. Other values include:

    • N (an integer) consumes N arguments (and produces a list)

    • ‘?’ consumes zero or one arguments

    • ‘*’ consumes zero or more arguments (and produces a list)

    • ‘+’ consumes one or more arguments (and produces a list)

    Note that the difference between the default and nargs=1 is that with the default, a single value will be produced, while with nargs=1, a list containing a single value will be produced.

  • const – The value to be produced if the option is specified and the

    option uses an action that takes no values.

  • default – The value to be produced if the option is not specified.

  • type – A callable that accepts a single string argument, and

    returns the converted value. The standard Python types str, int, float, and complex are useful examples of such callables. If None, str is used.

  • choices – A container of values that should be allowed. If not None,

    after a command-line argument has been converted to the appropriate type, an exception will be raised if it is not a member of this collection.

  • required – True if the action must always be specified at the

    command line. This is only meaningful for optional command-line arguments.

  • help – The help string describing the argument.

  • metavar – The name to be used for the option’s argument with the

    help string. If None, the ‘dest’ value will be used as the name.

add_parser(*args, **kwargs)[source]
class weaver.cli.WeaverArgumentParser(*args: Any, **kwargs: Any)[source]

Parser that provides fixes for proper representation of Weaver CLI arguments.

add_subparsers(*args, **kwargs)[source]
property help_mode[source]

Option enabled only during help formatting to generate different conditional evaluations.

add_help_conditional(container: argparse._ActionsContainer, help_required: bool = True, use_required: bool = False) argparse._ActionsContainer[source]
add_formatter(formatter: Callable[[str], str]) None[source]

Define a POST-help formatter.

_get_formatter() argparse.HelpFormatter[source]
format_help() str[source]
add_rule(rule: Callable[[argparse.Namespace], Optional[bool]], failure: str) None[source]
parse_known_args(args: Optional[Sequence[str]] = None, namespace: Optional[argparse.Namespace] = None) Tuple[argparse.Namespace, Sequence[str]][source]

Parse argument actions with handling of additional rules if any were defined.

Note

It is important to derive and call parse_known_args() rather than parse_args() to ensure nested subparsers rules validation can also be invoked.

weaver.cli.make_parser() argparse.ArgumentParser[source]

Generate the CLI parser.

Note

Instead of employing argparse.ArgumentParser instances returned by argparse._SubParsersAction.add_parser(), distinct argparse.ArgumentParser instances are created for each operation and then merged back by ourselves as subparsers under the main parser. This provides more flexibility in arguments passed down and resolves, amongst other things, incorrect handling of exclusive argument groups and their grouping under corresponding section titles.

weaver.cli.main(*args: str) int[source]