models.Service and ServiceExecution

class Service(json, **kwargs)[source]

A virtual object representing a KE-chain Service.

New in version 1.13.

Variables:
  • id – id of the service

  • name – name of the service

  • description – description of the service

  • version – version number of the service, as provided by uploaded

  • type – type of the service. One of the ServiceType

  • filename – filename of the service

  • environment – environment in which the service will execute. One of ServiceEnvironmentVersion

  • updated_at – datetime in UTC timezone when the Service was last updated

New in version 3.0.

Variables:
  • trusted – Trusted flag. If the kecpkg is trusted.

  • run_as – User to run the script as. One of ServiceScriptUser.

  • verified_on – Date when the kecpkg was verified by KE-chain (if verification pipeline is enabled)

  • verification_results – Results of the verification (if verification pipeline is enabled)

Construct a service from provided json data.

execute(interactive: bool | None = False, **kwargs) ServiceExecution[source]

Execute the service.

For interactive (notebook) service execution, set interactive to True, defaults to False.

New in version 1.13.

Parameters:

interactive (bool or None) – (optional) True if the notebook service should execute in interactive mode.

Returns:

ServiceExecution when successful.

Raises:

APIError – when unable to execute

edit(name: str | ~pykechain.utils.Empty | None = <pykechain.utils.Empty object>, description: str | ~pykechain.utils.Empty | None = <pykechain.utils.Empty object>, version: str | ~pykechain.utils.Empty | None = <pykechain.utils.Empty object>, type: ~pykechain.enums.ServiceType | ~pykechain.utils.Empty | None = <pykechain.utils.Empty object>, environment_version: ~pykechain.enums.ServiceEnvironmentVersion | ~pykechain.utils.Empty | None = <pykechain.utils.Empty object>, run_as: ~pykechain.enums.ServiceScriptUser | ~pykechain.utils.Empty | None = <pykechain.utils.Empty object>, trusted: bool | ~pykechain.utils.Empty | None = <pykechain.utils.Empty object>, **kwargs) None[source]

Edit Service details.

Setting an input to None will clear out the value (exception being name).

New in version 1.13.

Parameters:
  • name (basestring or None or Empty) – (optional) name of the service to change. Cannot be cleared.

  • description (basestring or None or Empty) – (optional) description of the service. Can be cleared.

  • version (basestring or None or Empty) – (optional) version number of the service. Can be cleared.

  • type (ServiceType or None or Empty) – (optional) script type (Python or Notebook). Cannot be cleared.

  • environment_version (ServiceEnvironmentVersion or None or Empty) – (optional) environment version of the service. Cannot be cleared.

  • run_as (ServiceScriptUser or None or Empty) – (optional) user to run the service as. Defaults to kenode user (bound to scope). Cannot be cleared.

  • trusted (bool or None or Empty) – (optional) flag whether the service is trusted, default if False. Cannot be cleared.

Raises:

Example

>>> service.edit(name='Car service',version='203')

Not mentioning an input parameter in the function will leave it unchanged. Setting a parameter as None will clear its value (where that is possible). The example below will clear the description and edit the name.

>>> service.edit(name="Plane service",description=None)
delete() None[source]

Delete this service.

Raises:

APIError – if delete was not successful.

upload(pkg_path)[source]

Upload a python script (or kecpkg) to the service.

New in version 1.13.

Parameters:

pkg_path (basestring) – path to the python script or kecpkg to upload.

Raises:
  • APIError – if the python package could not be uploaded.

  • OSError – if the python package could not be located on disk.

save_as(target_dir=None)[source]

Save the kecpkg service script to an (optional) target dir.

Retains the filename of the service as known in KE-chain.

New in version 1.13.

Parameters:

target_dir (basestring or None) – (optional) target dir. If not provided will save to current working directory.

Raises:
  • APIError – if unable to download the service.

  • OSError – if unable to save the service kecpkg file to disk.

get_executions(**kwargs)[source]

Retrieve the executions related to the current service.

New in version 1.13.

Parameters:

kwargs (dict) – (optional) additional search keyword arguments to limit the search even further.

Returns:

list of ServiceExecutions associated to the current service.

class ServiceExecution(json, **kwargs)[source]

A virtual object representing a KE-chain Service Execution.

New in version 1.13.

Variables:
  • id – id of the service execution

  • name – name of the service to which the execution is associated

  • status – status of the service. One of ServiceExecutionStatus

  • service – the Service object associated to this service execution

  • service_id – the uuid of the associated Service object

  • user – (optional) username of the user that executed the service

  • activity_id – (optional) the uuid of the activity where the service was executed from

Construct a scope from provided json data.

property service: Service

Retrieve the Service object to which this execution is associated.

terminate()[source]

Terminate the Service execution.

New in version 1.13.

Returns:

None if the termination request was successful

Raises:

APIError – When the service execution could not be terminated.

get_log(target_dir=None, log_filename='log.txt')[source]

Retrieve the log of the service execution.

New in version 1.13.

Parameters:
  • target_dir (basestring or None) – (optional) directory path name where the store the log.txt to.

  • log_filename (basestring or None) – (optional) log filename to write the log to, defaults to log.txt.

Raises:
  • APIError – if the logfile could not be found.

  • OSError – if the file could not be written.

get_notebook_url()[source]

Get the url of the notebook, if the notebook is executed in interactive mode.

New in version 1.13.

Returns:

full url to the interactive running notebook as basestring

Raises:

APIError – when the url cannot be retrieved.