kes package

Subpackages

Submodules

kes.client module

Client module.

This module is the starting point for wrting a Kes Python script. Scripts typically start by configuring and creating a client, after which this client can be used to open projects.

Usage example:

config = Config(kes_service_address='localhost:50051')
client = Client(config)
project = client.open_project("Preview Python client example")
class kes.client.Client(config: kes.client.Config)

Bases: object

Kes client.

Starting point of a kes script. After creating a client instance, kes projects can be opened using open_project.

open_project_by_id(project_id: uuid.UUID) kes.project.Project

Open a Kes project by id

Parameters

project_id (UUID) – uuid of the project to open.

Returns

An instance representing the requested Kes project.

open_project_by_master_id(master_id: str) kes.project.Project

Open a Kes project by master project id.

Parameters

project_name (str) – Name of the project to open.

Returns

An instance representing the requested Kes project.

Raises

ProjectNotFound – The requested project could not be found.

class kes.client.Config(access_token: str, kes_service_address: str = 'kes-table-service-production.bluebush-b51cfb01.westeurope.azurecontainerapps.io:443', root_certificates_path: Optional[str] = None)

Bases: object

Holds configuration of the client.

kes_service_address

Address of the service which interacts with the Kes database. Defaults to the production instance. Example: kes-table-service-production.bluebush-b51cfb01.westeurope.azurecontainerapps.io:443

Type

str

access_token

Access token. Can be obtained from the Kes project manager.

Type

str

root_certificates_path

Path to the file containing the root certificates. Defaults to None. Can be left blank unless connecting to a custom KES instance.

Type

Optional[str]

exception kes.client.ProjectNotFound

Bases: Exception

Exception indicating when a project could not be found.

kes.project module

Project module.

This module contains classes for manipulating Kes projects and activities.

class kes.project.Activity(stub: kes.proto.table_pb2_grpc.TableStub, id: uuid.UUID, description: str)

Bases: object

A Kes activity.

An activity is the execution of a template. This class is a factory to build tables for this activity.

build_table(table_def: kes.table.TableDef[kes.table.RowType]) kes.table.Table[kes.table.RowType]

Create a table for this activity.

Parameters

table_def (TableDef) – A definition of the table to create. Table definitions are generated by the script scaffolder.

Returns

A table.

property description: str

description of the activity.

Type

str

property id: uuid.UUID

id of the activity.

Type

uuid

class kes.project.Project(project_id: uuid.UUID, table_stub: kes.proto.table_pb2_grpc.TableStub, project_stub: kes.proto.project_pb2_grpc.ProjectStub)

Bases: object

A Kes project.

An project can contain multiple activities.

property activities: List[kes.project.Activity]

The activities of the project.

Type

List

kes.table module

Table module.

This module offers functionality for accessing assets and properties through the abstraction provided by the table class.

Classes:

Table: Rows represent assets and columns properties. RowReference: Reference which can be assigned to relationship fields. FieldDef: Definition of a field. TableDef: Definition of a table.

class kes.table.FieldDef(property_id: uuid.UUID, flag_type: Optional[Type[enum.Flag]])

Bases: object

Defines a field.

This class is used by the script scaffolder to define fields.

property_id

Id of the property corresponsing with the field

Type

uuid.UUID

flag_constructor

Holds the type of the flag field if applicable.

class kes.table.RowElement(row: RowType, asset_id: uuid.UUID)

Bases: Generic[kes.table.RowType]

class kes.table.RowReference(asset_type_id: uuid.UUID, asset_id: uuid.UUID)

Bases: Generic[kes.table.ParticipantType]

Opaque class which represents a reference to a table row

class kes.table.Table(stub: kes.proto.table_pb2_grpc.TableStub, inspection_id: uuid.UUID, row_type: Type[kes.table.RowType], asset_type_id: uuid.UUID, property_map: Mapping[str, kes.table.FieldDef])

Bases: Generic[kes.table.RowType]

Tables are the primary abstraction for manipulating Kes activities. This class acts as a container for rows. A table corresponds to a asset type, with rows corresponding to assets.

Operations such as adding rows and deleting rows are executed immediately. For example, after executing append_row, the corresponding asset is immediately visible in Kes.

Note that modifying a row is not yet supported. To work around this, delete the row and reinsert it.

Type parameters:

RowType: The type of rows hold by this class.

append_row(value: kes.table.RowType)

Adds the row to the end of the table.

Parameters

value (RowType) – the row to insert.

Returns: A row reference which can be assigned to relationship fields.

Raises

TableFull – Indicates table cannot hold any more rows.

clear()

Delete all the rows of the table.

get_reference_by_row_index(rowIndex: int)

Get a reference to the specified row.

Parameters

rowIndex (int) – Index of row to get a reference to.

load()

Load the rows of this table.

After instantiating a table, it is empty. Call this method to load assets from the Kes activity.

load_image(image: kes.fields.imagefield.ImageField) Optional[ByteString]

Load image data.

If the image field has an image, return the image data. The resulting bytestream can for example be written to a file. If there is no image, return None.

Parameters

image (ImageField) – The image field whose image data should be read.

Returns

The image data, or None if there is no image

Return type

Optional[ByteString]

save_image(image: kes.fields.imagefield.ImageField, name: str, data: bytes)

Save image data and associated name to an image field.

Parameters
  • image (ImageField) – Image field to write to.

  • name (str) – The name of the image as visible in Kes.

  • data (bytes) – Contents of the image file.

class kes.table.TableDef(row_type: Type[kes.table.RowType], asset_type_id: uuid.UUID, property_map: Mapping[str, kes.table.FieldDef])

Bases: Generic[kes.table.RowType]

Defines a table.

This class is used by the script scaffolder to define tables.

row_type

Row type of this table.

Type

Type[kes.table.RowType]

asset_type_id

UUID of the asset type associated with this table.

Type

uuid.UUID

property_map

Mapping from property names to property ids.

Type

Mapping[str, kes.table.FieldDef]

exception kes.table.TableFull

Bases: Exception

Exception indication when a row could not be inserted because the table is full.