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.
- assemble(header_json: str, metadata_json: str, content_json: str) Message[Any][source]#
Create a Message instance assembled from json fragments.
- Parameters:
header_json (
JSON) –metadata_json (
JSON) –content_json (
JSON) –
- Returns:
message
- create(msgtype: Literal['ACK'], **metadata: Any) ack[source]#
- create(msgtype: Literal['ERROR'], request_id: ID, text: str, **metadata: Any) error
- create(msgtype: Literal['OK'], request_id: ID, **metadata: Any) ok
- create(msgtype: Literal['PATCH-DOC'], events: list[DocumentPatchedEvent], **metadata: Any) patch_doc
- create(msgtype: Literal['PULL-DOC-REPLY'], request_id: ID, document: Document, **metadata: Any) pull_doc_reply
- create(msgtype: Literal['PULL-DOC-REQ'], **metadata: Any) pull_doc_req
- create(msgtype: Literal['PUSH-DOC'], document: Document, **metadata: Any) push_doc
- create(msgtype: Literal['SERVER-INFO-REPLY'], request_id: ID, **metadata: Any) server_info_reply
- create(msgtype: Literal['SERVER-INFO-REQ'], **metadata: Any) server_info_req
Create a new Message instance for the given type.
- Parameters:
msgtype (str) –
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: Header, metadata: dict[str, Any], content: Content)[source]#
The Message base class encapsulates creating, assembling, and validating the integrity of Bokeh Server messages. Additionally, it provide hooks
- __init__(header: Header, metadata: dict[str, Any], content: Content) None[source]#
Initialize a new message from header, metadata, and content dictionaries.
To assemble a message from existing JSON fragments, use the
assemblemethod.To create new messages with automatically generated headers, use subclass
createmethods.- Parameters:
header (JSON-like) –
metadata (JSON-like) –
content (JSON-like) –
- add_buffer(buffer: Buffer) None[source]#
Associate a buffer header and payload with this message.
- Parameters:
buf_header (
JSON) – a buffer headerbuf_payload (
JSONor bytes) – a buffer payload
- Returns:
None
- Raises:
- classmethod assemble(header_json: str, metadata_json: str, content_json: str) Message[Content][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: BufferHeader, buf_payload: bytes) None[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 (
JSONor bytes) – a buffer payload
- Returns:
None
- Raises:
- classmethod create_header(request_id: ID | None = None) Header[source]#
Return a message header fragment dict.
- async send(conn: WebSocketClientConnectionWrapper) int[source]#
Send the message on the given connection.
- Parameters:
conn (WebSocketHandler) – a WebSocketHandler to send messages
- Returns:
number of bytes sent
- Return type:
- async write_buffers(conn: WebSocketClientConnectionWrapper, locked: bool = True) int[source]#
Write any buffer headers and payloads to the given connection.
bokeh.protocol.messages#
- class ack(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
ACKmessage for acknowledging successful client connection to a Bokeh server.The
contentfragment of for this message is empty.
- class error(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
ERRORmessage for reporting error conditions back to a Bokeh server.The
contentfragment of for this message is has the form:{ 'text' : <error message text> # this is optional 'traceback' : <traceback text> }
- class ok(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
OKmessage for acknowledging successful handling of a previous message.The
contentfragment of for this message is empty.
- class patch_doc(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
PATCH-DOCmessage for sending Document patch events between remote documents.The
contentfragment of for this message is has the form:{ 'events' : <protocol document events> 'references' : <model references> }
- class pull_doc_reply(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
PULL-DOC-REPLYmessage for replying to Document pull requests from clientsThe
contentfragment of for this message is has the form:{ 'doc' : <Document JSON> }
- classmethod create(request_id: ID, document: Document, **metadata: Any) pull_doc_reply[source]#
Create an
PULL-DOC-REPLYmessage- Parameters:
Any additional keyword arguments will be put into the message
metadatafragment as-is.
- class pull_doc_req(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
PULL-DOC-REQmessage for requesting a Bokeh server reply with a new Bokeh Document.The
contentfragment of for this message is empty.- classmethod create(**metadata: Any) pull_doc_req[source]#
Create an
PULL-DOC-REQmessageAny keyword arguments will be put into the message
metadatafragment as-is.
- class push_doc(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
PUSH-DOCmessage for pushing Documents from clients to a Bokeh server.The
contentfragment of for this message is has the form:{ 'doc' : <Document JSON> }
- class server_info_reply(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
SERVER-INFO-REPLYmessage for replying to Server info requests from clients.The
contentfragment of for this message is has the form:{ 'version_info' : { 'bokeh' : <bokeh library version> 'server' : <bokeh server version> } }
- classmethod create(request_id: ID, **metadata: Any) server_info_reply[source]#
Create an
SERVER-INFO-REPLYmessage- Parameters:
request_id (str) – The message ID for the message that issues the info request
Any additional keyword arguments will be put into the message
metadatafragment as-is.
- class server_info_req(header: Header, metadata: dict[str, Any], content: Content)[source]#
Define the
SERVER-INFO-REQmessage for requesting a Bokeh server provide information about itself.The
contentfragment of for this message is empty.- classmethod create(**metadata: Any) server_info_req[source]#
Create an
SERVER-INFO-REQmessageAny keyword arguments will be put into the message
metadatafragment as-is.
bokeh.protocol.receiver#
Assemble WebSocket wire message fragments into complete Bokeh Server message objects that can be processed.
- class Receiver(protocol: Protocol)[source]#
Receive wire message fragments and assemble complete Bokeh server message objects.
On
MessageErrororValidationError, 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
headerfragment 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
metadatafragment 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
contentfragment is defined by the specific message type.