nimblebox logo
Docs
v2.1.0

nbox.messages

gRPC + Protobuf = ♥️

Contains methods defined here

Functions

iconfunctionrpc
[source]

convienience function for calling a gRPC stub

iconfunctionstreaming_rpc
[source]

convienience function for streaming from a gRPC stub

iconfunctionmessage_to_json
[source]

convert message to json

iconfunctionmessage_to_dict
[source]

convert message to dict

iconfunctiondict_to_message
[source]

load dict into message

iconfunctionwrite_string_to_file
[source]
iconfunctionread_file_to_string
[source]
iconfunctionwrite_binary_to_file
[source]
iconfunctionread_file_to_binary
[source]
iconfunctionfrom_any_pb
[source]
(pb_type:type,any_pb:google.protobuf.any_pb2.Any)
Parameters
  • pb_type -

    the type of the message that any_pb stores an instance of.

  • any_pb -

    the object to be converted.

Converts an Any protobuf to the specified message type.

Returns:

  • pb_type: An instance of the pb_type message.
iconfunctioncheck_oneof
[source]
(kwargs:dict)
Parameters
  • kwargs -

    The keyword arguments sent to the function.

Raise ValueError if more than one keyword argument is not None.

iconfunctionget_messages
[source]
(module:module)
Parameters
  • module -

    A Python module; :func:dir will be run against this module to find Message subclasses.

Discovers all protobuf Message classes in a given import module.

Returns:

  • dict[str, google.protobuf.message.Message]: A dictionary with the Message class names as keys, and the Message subclasses themselves as values.
iconfunction_resolve_subkeys
[source]
(key:str,separator:str)
Parameters
  • key -

    A string that may or may not contain the separator.

  • separator -

    The namespace separator. Defaults to ..

Resolve a potentially nested key. If the key contains the separator (e.g. .) then the key will be split on the first instance of the subkey:

  >>> _resolve_subkeys('a.b.c')
  ('a', 'b.c')
  >>> _resolve_subkeys('d|e|f', separator='|')
  ('d', 'e|f')

If not, the subkey will be None:

  >>> _resolve_subkeys('foo')
  ('foo', None)

Returns:

  • Tuple[str, str]: The key and subkey(s).
iconfunctionget
[source]
(mdg_or_dict:Union[~google.protobuf.message.Message, Mapping],key:str)
Parameters
  • mdg_or_dict -

    the object.

  • key -

    The key to retrieve from the object.

Retrieve a key's value from a protobuf Message or dictionary. Note on default (Any): If the key is not present on the object, and a default is set, returns that default instead. A type-appropriate falsy default is generally recommended, as protobuf messages almost always have default values for unset values and it is not always possible to tell the difference between a falsy value and an unset one. If no default is set then KeyError will be raised if the key is not present in the object.

Returns:

  • Any: The return value from the underlying Message or dict.
iconfunction_set_field_on_message
[source]

Set helper for protobuf Messages.

iconfunctionset
[source]
(msg_or_dict:Union[~google.protobuf.message.Message, Mapping],key:str,value:Any)
Parameters
  • msg_or_dict -

    the object.

  • key -

    The key to set.

  • value -

    The value to set.

Set a key's value on a protobuf Message or dictionary.

iconfunctionsetdefault
[source]
(msg_or_dict:Union[~google.protobuf.message.Message, Mapping],key:str,value:Any)
Parameters
  • msg_or_dict -

    the object.

  • key -

    The key on the object in question.

  • value -

    The value to set.

Set the key on a protobuf Message or dictionary to a given value if the current value is falsy. Because protobuf Messages do not distinguish between unset values and falsy ones particularly well (by design), this method treats any falsy value (e.g. 0, empty list) as a target to be overwritten, on both Messages and dictionaries.

iconfunctionfield_mask
[source]
(original:~google.protobuf.message.Message,modified:~google.protobuf.message.Message)
Parameters
  • original -

    the original message. If set to None, this field will be interpretted as an empty message.

  • modified -

    the modified message. If set to None, this field will be interpretted as an empty message.

Create a field mask by comparing two messages.

Returns:

  • google.protobuf.field_mask_pb2.FieldMask: field mask that contains the list of field names that have different values between the two messages. If the messages are equivalent, then the field mask is empty.
iconfunction_field_mask_helper
[source]
iconfunction_get_path
[source]
iconfunction_is_message
[source]
iconfunction_is_wrapper
[source]
nbox SDKnbox provides built in access to all the APIs and packages them in the most user friendly manner.Star 0