bokeh.protocol¶
Implement and provide message protocols for communication between Bokeh Servers and clients.
-
class
Protocol
[source]¶ Provide a message factory for the Bokeh Server message protocol.
bokeh.protocol.exceptions¶
Provide named exceptions having to do with handling Bokeh Protocol messages.
-
exception
MessageError
[source]¶ Indicate an error in constructing a Bokeh Message object.
This exception usually indicates that the JSON fragments of a message cannot be decoded at all.
bokeh.protocol.message¶
Provide a base class for all Bokeh Server Protocol message types.
Boker messages are comprised of a sequence of JSON fragments. Specified as Python JSON-like data, messages have the general form:
[
# these are required
b'{header}', # serialized header dict
b'{metadata}', # serialized metadata dict
b'{content}, # serialized content dict
# these are optional, and come in pairs; header contains num_buffers
b'{buf_header}', # serialized buffer header dict
b'array' # raw buffer payload data
...
]
The header
fragment will have the form:
header = {
# these are required
'msgid' : <str> # a unique id for the message
'msgtype' : <str> # a message type, e.g. 'ACK', 'PATCH-DOC', etc
# these are optional
'num_buffers' : <int> # the number of additional buffers, if any
}
The metadata
fragment may contain any arbitrary information. It is not
processed by Bokeh for any purpose, but may be useful for external
monitoring or instrumentation tools.
The content
fragment is defined by the specific message type.
-
class
Message
(header, metadata, content)[source]¶ The Message base class encapsulates creating, assembling, and validating the integrity of Bokeh Server messages. Additionally, it provide hooks
-
__init__
(header, metadata, content)[source]¶ Initialize a new message from header, metadata, and content dictionaries.
To assemble a message from existing JSON fragments, use the
assemble
method.To create new messages with automatically generated headers, use subclass
create
methods.- Parameters
header (JSON-like) –
metadata (JSON-like) –
content (JSON-like) –
-
add_buffer
(buf_header, buf_payload)[source]¶ Associate a buffer header and payload with this message.
- Parameters
buf_header (
JSON
) – a buffer headerbuf_payload (
JSON
or bytes) – a buffer payload
- Returns
None
- Raises
-
classmethod
assemble
(header_json, metadata_json, content_json)[source]¶ Creates a new message, assembled from JSON fragments.
- Parameters
header_json (
JSON
) –metadata_json (
JSON
) –content_json (
JSON
) –
- Returns
Message subclass
- Raises
-
assemble_buffer
(buf_header, buf_payload)[source]¶ Add a buffer header and payload that we read from the socket.
This differs from add_buffer() because we’re validating vs. the header’s num_buffers, instead of filling in the header.
- Parameters
buf_header (
JSON
) – a buffer headerbuf_payload (
JSON
or bytes) – a buffer payload
- Returns
None
- Raises
-
async
send
(conn)[source]¶ Send the message on the given connection.
- Parameters
conn (WebSocketHandler) – a WebSocketHandler to send messages
- Returns
number of bytes sent
- Return type
-
bokeh.protocol.messages¶
ACK
¶
ERROR
¶
-
class
error
(header, metadata, content)[source]¶ Define the
ERROR
message for reporting error conditions back to a Bokeh server.The
content
fragment of for this message is has the form:{ 'text' : <error message text> # this is optional 'traceback' : <traceback text> }
OK
¶
PATCH-DOC
¶
-
class
patch_doc
(header, metadata, content)[source]¶ Define the
PATCH-DOC
message for sending Document patch events between remote documents.The
content
fragment of for this message is has the form:{ 'events' : <protocol document events> 'references' : <model references> }
PULL-DOC-REPLY
¶
-
class
pull_doc_reply
(header, metadata, content)[source]¶ Define the
PULL-DOC-REPLY
message for replying to Document pull requests from clientsThe
content
fragment of for this message is has the form:{ 'doc' : <Document JSON> }
PULL-DOC-REQ
¶
PUSH-DOC
¶
SERVER-INFO-REPLY
¶
bokeh.protocol.receiver¶
Assemble WebSocket wire message fragments into complete Bokeh Server message objects that can be processed.
-
class
Receiver
(protocol)[source]¶ Receive wire message fragments and assemble complete Bokeh server message objects.
On
MessageError
orValidationError
, the receiver will reset its state and attempt to consume a new message.The fragment received can be either bytes or unicode, depending on the transport’s semantics (WebSocket allows both).
[ # these are required b'{header}', # serialized header dict b'{metadata}', # serialized metadata dict b'{content}, # serialized content dict # these are optional, and come in pairs; header contains num_buffers b'{buf_header}', # serialized buffer header dict b'array' # raw buffer payload data ... ]
The
header
fragment will have the form:header = { # these are required 'msgid' : <str> # a unique id for the message 'msgtype' : <str> # a message type, e.g. 'ACK', 'PATCH-DOC', etc # these are optional 'num_buffers' : <int> # the number of additional buffers, if any }
The
metadata
fragment may contain any arbitrary information. It is not processed by Bokeh for any purpose, but may be useful for external monitoring or instrumentation tools.The
content
fragment is defined by the specific message type.