Skip to main content

Running an entity computation

New in v14.12.0

Besides handling entity data, the SDK API can be used to run a computation on an entity. This can be used to, for example, utilize the entity as a calculation tool in other apps by remotely running the logic on the entity's Controller.

api.entity_compute(workspace_id=1, entity_id=2, method_name="my_calculation", params={...})
workspace = api.get_workspace(1)
workspace.entity_compute(entity_id=2, method_name="my_calculation", params={...})
entity = api.get_entity(2)
entity.compute(method_name="my_calculation", params={...})
  • Not all methods on an entity can be called over the API. Currently, only view methods and button methods are supported
  • It is not possible to use compute on an entity within your own development workspace (it will return a TimeoutError)


The example below shows how to replicate a geometry-view from another entity (from another workspace) in the current entity, without copying any logic. For more information on how to set up the API for cross-workspace access, see here.

from viktor.api_v1 import API

class Controller(ViktorController):

@GeometryView("Geometry", duration_guess=5)
def geometry_view_from_other_entity(self, params, **kwargs):
api = API(token=os.environ["TOKEN"])
entity = api.get_entity(other_entity_id, workspace_id=other_workspace_id)
result = entity.compute("geometry_view", params=entity.last_saved_params)
return GeometryResult(**result['geometry'])