Ingescape in Python
Ingescape in Python
Ingescape in Python requires the installation of the Ingescape open source library, which is distributed with the Ingescape Circle installer or can be compiled from our Github repository.
To install Ingescape in Python, please refer to our dedicated pages in our Github repository.
If Python and Ingescape are already installed on your system, just type :
python3 -m pip install ingescape
Cheatsheet
Fully-fledged examples can be found here. And Ingescape Circle code generation helps you bootstrap agents in many languages.
All declared ingescape functions in Python may also be found here
Observe an input with a callback function
igs.observe_input("input", input_callback, None)
Code language: JavaScript (javascript)
The last argument is an optional user data that is passed to the callback every time the input is written.
Handle a written input with a callback function
def input_callback(iop_type, name, value_type, value, my_data):
igs.info(f"Input {name} of type {value_type} has been written with value '{value}' and user data '{my_data}'")
Code language: JavaScript (javascript)
The ‘iop_type’ callback parameter designates if we are dealing with an input/output/parameter. In our example, it will designate an input.
Get the value of an input
integerinput_value = igs.input_get_int("integerinput_name")
doubleinput_value = igs.input_get_double("doubleinput_name")
booleaninput_value = igs.input_get_bool("booleaninput_name")
impulsioninput_value = igs.input_get_impulsion("impulsioninput_name")
stringinput_value = igs.input_get_string("stringinput_name")
datainput_value = igs.input_get_data("datainput_name")
Code language: JavaScript (javascript)
Write and publish an output
igs.output_set_int("integeroutput_name", 1)
igs.output_set_double("doubleoutput_name", 1.1)
igs.output_set_bool("booleanoutput_name", True)
igs.output_set_impulsion("impulsionoutput_name")
igs.output_set_string("stringoutput_name", "somestring")
igs.output_set_data("dataoutput_name", b'\x00')
Code language: PHP (php)
Create a service and set its associated callback function
igs.service_init("service_name", service_callback, None)
Code language: JavaScript (javascript)
The last argument is an optional user data that is passed to the callback every time the input is written.
Handle a service call with its associated callback
def service_callback(sender_agent_name, sender_agent_uuid, service_name, arguments, token, my_data):
igs.info(f"Service {service_name} was called by {sender_agent_name} ({sender_agent_uuid}) with arguments : {''.join(f'arg={argument} ' for argument in arguments)}")
Code language: JavaScript (javascript)
Call a service on another agent
arguments_list = (2.0, "anystring", True, 24, b'\x00')
igs.service_call("other_agent_name", "called_service_name", arguments_list, "")
Code language: PHP (php)
The last argument is an optional string that is returned if the requested service call triggers a reply service call from the callee, so that each individual service call can be identified precisely.
Detect agent events
igs.observe_agent_events(on_agent_event_callback, None)
Code language: CSS (css)
The last argument is an optional user data that is passed to the callback every time an agent event is detected.
Handle agent events
def on_agent_event_callback(event, uuid, name, event_data, my_data):
igs.info(f"Agent event {event} from agent {name} with uuid {uuid} received : event data {event_data}, agent object {my_data}")
igs.info(f"Possible event types : peer entered {igs.PEER_ENTERED} / peer exited {igs.PEER_EXITED} / agent entered {igs.AGENT_ENTERED} / agent definition update {igs.AGENT_UPDATED_DEFINITION} / agent now knows us {igs.AGENT_KNOWS_US} / agent exited {igs.AGENT_EXITED} / agent mapping updated {igs.AGENT_UPDATED_MAPPING} / agent election won {igs.AGENT_WON_ELECTION} / agent election lost {igs.AGENT_LOST_ELECTION}")
Code language: JavaScript (javascript)