Using SentiUtils with Python
Before you start integrating SentiUtil's data stream into Python, please make sure your system has SentiUtils and the Protobuf compiler installed.
To work with SentiUtil's Protobuf message definitions, please clone or download the SentiSystems senti-proto repository.
git clone https://gitlab.senti.no/senti/senti-proto.git
To generate the needed Python file, proceed to run the following command
protoc --python_out=<insert location for output file> senti.proto
This should generate a
senti_pb2.py file, which should be placed in the same folder as your Python software.
For the newest versions of Protobuf you need to run
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python in your environment (e.g from the terminal used to start the python software) to use Python to receive SentiUtil's Protobuf messages.
SentiMessageParser for Python
scripts/sentipy.py contains the class
SentiMessageParser, which will read and parse the SentiUtil's data stream.
Example usage is described in
scripts/udp_message_receiver.py, but in short works as follows:
import senti_pb2 as senti
# Please make sure senti_pb2.py and sentipy.py
# is located in the same folder as this code
UDP_IP = ""
UDP_PORT = 21314
parser = sentipy.SentiMessageParser(UDP_IP, UDP_PORT)
# Register callbacks based on MessageID
# create your own functions to decide what should happen with the data
The callback functions are functions which takes a Protobuf message of MessageID type as input.
See the SentiSystems Protobuf Documentation for message IDs and message descriptions.