Server Util

Helper functions and classes for creating and running a gRPC service.

class bosdyn.client.server_util.ResponseContext(response, request, rpc_logger=None, channel_prefix=None, exc_callback=None)[source]

Bases: object

Helper to log gRPC request and response message to the data buffer for a service.

It should be called using a “with” statement each time an RPC is received such that the request and response proto messages can be passed in. It will automatically log the request and response to the data buffer, and mutates the headers to add additional information before logging.

  • response (protobuf) – any gRPC response message with a bosdyn.api.ResponseHeader proto.

  • request (protobuf) – any gRPC request message with a bosdyn.api.RequestHeader proto.

  • rpc_logger (DataBufferClient) – Optional data buffer client to log the messages; if not provided, only the headers will be mutated and nothing will be logged.

  • channel_prefix (string) – the prefix you want this req / resp pair logged under.

  • exc_callback (function) – called with exception type, value, and traceback info if an exception is raised in the body of the “with” statement.

class bosdyn.client.server_util.GrpcServiceRunner(service_servicer, add_servicer_to_server_fn, port=0, max_workers=4, max_send_message_length=None, max_receive_message_length=None, timeout_secs=3, force_sigint_capture=True, logger=None)[source]

Bases: object

A runner to start a gRPC server on a background thread and allow easy cleanup.

  • service_servicer (custom servicer class derived from ServiceServicer) – Servicer that defines server behavior.

  • add_servicer_to_server_fn (function) – Function generated by gRPC compilation that attaches the servicer to the gRPC server.

  • port (int) – The port number the service can be accessed through on the host system. Defaults to 0, which will assign an ephemeral port.

  • max_send_message_length (int) – Max message length (bytes) allowed for messages sent.

  • max_receive_message_length (int) – Max message length (bytes) allowed for messages received.

  • timeout_secs (int) – Number of seconds to wait for a clean server shutdown.

  • force_sigint_capture (bool) – Re-assign the SIGINT handler to default in order to prevent other scripts from blocking a clean exit. Defaults to True.

  • logger (logging.Logger) – Logger to log with.


Blocks until the gRPC server shuts down.


Spin the thread until a SIGINT is received and then shut down cleanly.

bosdyn.client.server_util.populate_response_header(response, request, error_code=1, error_msg=None)[source]
Sets the ResponseHeader header in the response.

response (bosdyn.api Response message): The GRPC response message to be populated. request (bosdyn.api Request message): The header from the request is added to the response. error_code (header_pb2.CommonError): The status for the RPC response. error_msg (str): An optional error message describing a bad header status failure.


Mutates the response message’s header to be fully populated.

Deprecated since version 3.0.0: The populate_response_header helper has moved to Please use bosdyn.client.server_util.populate_response_header.


Removes any large bytes fields from a protobuf message depending on the proto type.

Deprecated since version 3.0.0: The strip_large_bytes_fields helper has moved to Please use bosdyn.client.server_util.strip_large_bytes_fields.


Creates set of protos which will have bytes fields removed.

Deprecated since version 3.0.0: The get_bytes_field_whitelist helper has moved to Please use bosdyn.client.server_util.get_bytes_field_allowlist.


Removes bytes from the image_pb2.ImageResponse proto.

Deprecated since version 3.0.0: The strip_image_response helper has moved to Please use bosdyn.client.server_util.strip_image_response.


Removes bytes from the image_pb2.GetImageResponse proto.

Deprecated since version 3.0.0: The strip_get_image_response helper has moved to Please use bosdyn.client.server_util.strip_get_image_response.


Removes bytes from the local_grid_pb2.GetLocalGridsResponse proto.

Deprecated since version 3.0.0: The strip_local_grid_responses helper has moved to Please use bosdyn.client.server_util.strip_local_grid_responses.


Removes bytes from the data_acquisition_store_pb2.StoreImageRequest proto.

Deprecated since version 3.0.0: The strip_store_image_request helper has moved to Please use bosdyn.client.server_util.strip_store_image_request.


Removes bytes from the data_acquisition_store_pb2.StoreDataRequest proto.

Deprecated since version 3.0.0: The strip_store_data_request helper has moved to Please use bosdyn.client.server_util.strip_store_data_request.


Removes bytes from the data_buffer_pb2.RecordSignalTicksRequest proto.

Deprecated since version 3.0.0: The strip_record_signal_tick helper has moved to Please use bosdyn.client.server_util.strip_record_signal_tick.


Removes bytes from the data_buffer_pb2.RecordDataBlobsRequest proto.

Deprecated since version 3.0.0: The strip_record_data_blob helper has moved to Please use bosdyn.client.server_util.strip_record_data_blob.


Removes bytes from the log_annotation_pb2.AddLogAnnotationRequest proto.

Deprecated since version 3.0.0: The strip_log_annotation helper has moved to Please use bosdyn.client.server_util.strip_log_annotation.