Does anyone have any experience of communicating with IPython kernels from outside of Python?
If I were trying to send messages from a Python app to an IPython kernel, I'd use the zmq.kernelmanager
API. As it is, I'll obviously need to write my own kernel manager in another language, but I can't find the information that I'm looking for about the low-level messaging protocols.
Is there an official spec or a 'cheat sheet' that documents the structure of the actual messages that get sent over 0MQ? This page describes a higher-level protocol than what I'm looking for... Will I have to manually pull apart the implementation to find what I want?
This is a document that desparately needs to exist, but the implementation of the wire protocol is implemented in a single object, so it shouldn't be too hard to grok from there. The message spec doc you linked covers the application-level content of each field, but not how it's actually serialized over zeromq. Assuming you have a mesage, as described in that doc, the wire format is pretty simple. It is a multipart zeromq message of at least six parts:
<IDS|MSG>
digest
of the message (an empty string''
if authentication is disabled)header
parent_header
metadata
content
header
,parent_header
,metadata
, andcontent
are all described in the messaging doc - these are dictionaries, and serialized to bytes with whatever serialization is currently used. The default in IPython is utf8-encoded JSON, but arbitrary serialization is allowed (msgpack being the most common non-default). Not yet described in the docs is thedigest
, used for authentication. This is an MD5 HMAC Digest of the message. The key for the digest is found in thekey
field of the connection file. The 'message' used by the HMAC digest is the concatenation of the bytes of the serialized header, parent_header, metadata, and content, in the same order sent over the wire.You can disable message signing by specifying the config value
to the IPython-related parts of your code, in which case the digest field will always be an empty string
''
. I would recommend doing this while getting started, so you can work out the more interesting parts of the implementation first.Here are a sample execute request and its reply actually sent by IPython.
The request:
and its reply: