nbox.messages
gRPC + Protobuf = ♥️
Contains methods defined here
Functions
convienience function for calling a gRPC stub
convienience function for streaming from a gRPC stub
convert message to json
convert message to dict
load dict into message
- 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.
- kwargs -
The keyword arguments sent to the function.
Raise ValueError if more than one keyword argument is not None
.
- 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.
- 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).
- 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.
Set helper for protobuf Messages.
- 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.
- 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.
- 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.