protobuf Package

descriptor Module

Descriptors essentially contain exactly the information found in a .proto file, in types that make this information accessible in Python.

class google.protobuf.descriptor.Descriptor(name, full_name, filename, containing_type, fields, nested_types, enum_types, extensions, options=None, is_extendable=True, extension_ranges=None, file=None, serialized_start=None, serialized_end=None)[source]

Bases: google.protobuf.descriptor._NestedDescriptorBase

Descriptor for a protocol message type.

A Descriptor instance has the following attributes:

name: (str) Name of this protocol message type. full_name: (str) Fully-qualified name of this protocol message type,

which will include protocol “package” name and the name of any enclosing types.
containing_type: (Descriptor) Reference to the descriptor of the
type containing us, or None if this is top-level.
fields: (list of FieldDescriptors) Field descriptors for all
fields in this type.
fields_by_number: (dict int -> FieldDescriptor) Same FieldDescriptor
objects as in |fields|, but indexed by “number” attribute in each FieldDescriptor.
fields_by_name: (dict str -> FieldDescriptor) Same FieldDescriptor
objects as in |fields|, but indexed by “name” attribute in each FieldDescriptor.
nested_types: (list of Descriptors) Descriptor references
for all protocol message types nested within this one.
nested_types_by_name: (dict str -> Descriptor) Same Descriptor
objects as in |nested_types|, but indexed by “name” attribute in each Descriptor.
enum_types: (list of EnumDescriptors) EnumDescriptor references
for all enums contained within this type.
enum_types_by_name: (dict str ->EnumDescriptor) Same EnumDescriptor
objects as in |enum_types|, but indexed by “name” attribute in each EnumDescriptor.
enum_values_by_name: (dict str -> EnumValueDescriptor) Dict mapping
from enum value name to EnumValueDescriptor for that value.
extensions: (list of FieldDescriptor) All extensions defined directly
within this message type (NOT within a nested type).
extensions_by_name: (dict, string -> FieldDescriptor) Same FieldDescriptor
objects as |extensions|, but indexed by “name” attribute of each FieldDescriptor.

is_extendable: Does this type define any extension ranges?

options: (descriptor_pb2.MessageOptions) Protocol message options or None
to use default message options.

file: (FileDescriptor) Reference to file descriptor.

CopyToProto(proto)[source]

Copies this to a descriptor_pb2.DescriptorProto.

Args:
proto: An empty descriptor_pb2.DescriptorProto.
class google.protobuf.descriptor.DescriptorBase(options, options_class_name)[source]

Bases: object

Descriptors base class.

This class is the base of all descriptor classes. It provides common options related functionaility.

Attributes:
has_options: True if the descriptor has non-default options. Usually it
is not necessary to read this – just call GetOptions() which will happily return the default instance. However, it’s sometimes useful for efficiency, and also useful inside the protobuf implementation to avoid some bootstrapping issues.
GetOptions()[source]

Retrieves descriptor options.

This method returns the options set or creates the default options for the descriptor.

class google.protobuf.descriptor.EnumDescriptor(name, full_name, filename, values, containing_type=None, options=None, file=None, serialized_start=None, serialized_end=None)[source]

Bases: google.protobuf.descriptor._NestedDescriptorBase

Descriptor for an enum defined in a .proto file.

An EnumDescriptor instance has the following attributes:

name: (str) Name of the enum type. full_name: (str) Full name of the type, including package name

and any enclosing type(s).
values: (list of EnumValueDescriptors) List of the values
in this enum.
values_by_name: (dict str -> EnumValueDescriptor) Same as |values|,
but indexed by the “name” field of each EnumValueDescriptor.
values_by_number: (dict int -> EnumValueDescriptor) Same as |values|,
but indexed by the “number” field of each EnumValueDescriptor.
containing_type: (Descriptor) Descriptor of the immediate containing
type of this enum, or None if this is an enum defined at the top level in a .proto file. Set by Descriptor’s constructor if we’re passed into one.

file: (FileDescriptor) Reference to file descriptor. options: (descriptor_pb2.EnumOptions) Enum options message or

None to use default enum options.
CopyToProto(proto)[source]

Copies this to a descriptor_pb2.EnumDescriptorProto.

Args:
proto: An empty descriptor_pb2.EnumDescriptorProto.
class google.protobuf.descriptor.EnumValueDescriptor(name, index, number, type=None, options=None)[source]

Bases: google.protobuf.descriptor.DescriptorBase

Descriptor for a single value within an enum.

name: (str) Name of this value. index: (int) Dense, 0-indexed index giving the order that this

value appears textually within its enum in the .proto file.

number: (int) Actual number assigned to this enum value. type: (EnumDescriptor) EnumDescriptor to which this value

belongs. Set by EnumDescriptor’s constructor if we’re passed into one.
options: (descriptor_pb2.EnumValueOptions) Enum value options message or
None to use default enum value options options.
exception google.protobuf.descriptor.Error[source]

Bases: exceptions.Exception

Base error for this module.

class google.protobuf.descriptor.FieldDescriptor(name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=None, has_default_value=True)[source]

Bases: google.protobuf.descriptor.DescriptorBase

Descriptor for a single field in a .proto file.

A FieldDescriptor instance has the following attriubtes:

name: (str) Name of this field, exactly as it appears in .proto. full_name: (str) Name of this field, including containing scope. This is

particularly relevant for extensions.
index: (int) Dense, 0-indexed index giving the order that this
field textually appears within its message in the .proto file.

number: (int) Tag number declared for this field in the .proto file.

type: (One of the TYPE_* constants below) Declared type. cpp_type: (One of the CPPTYPE_* constants below) C++ type used to

represent this field.
label: (One of the LABEL_* constants below) Tells whether this
field is optional, required, or repeated.
has_default_value: (bool) True if this field has a default value defined,
otherwise false.
default_value: (Varies) Default value of this field. Only
meaningful for non-repeated scalar fields. Repeated fields should always set this to [], and non-repeated composite fields should always set this to None.
containing_type: (Descriptor) Descriptor of the protocol message
type that contains this field. Set by the Descriptor constructor if we’re passed into one. Somewhat confusingly, for extension fields, this is the descriptor of the EXTENDED message, not the descriptor of the message containing this field. (See is_extension and extension_scope below).
message_type: (Descriptor) If a composite field, a descriptor
of the message type contained in this field. Otherwise, this is None.
enum_type: (EnumDescriptor) If this field contains an enum, a
descriptor of that enum. Otherwise, this is None.

is_extension: True iff this describes an extension field. extension_scope: (Descriptor) Only meaningful if is_extension is True.

Gives the message that immediately contains this extension field. Will be None iff we’re a top-level (file-level) extension field.
options: (descriptor_pb2.FieldOptions) Protocol message field options or
None to use default field options.
CPPTYPE_BOOL = 7
CPPTYPE_DOUBLE = 5
CPPTYPE_ENUM = 8
CPPTYPE_FLOAT = 6
CPPTYPE_INT32 = 1
CPPTYPE_INT64 = 2
CPPTYPE_MESSAGE = 10
CPPTYPE_STRING = 9
CPPTYPE_UINT32 = 3
CPPTYPE_UINT64 = 4
LABEL_OPTIONAL = 1
LABEL_REPEATED = 3
LABEL_REQUIRED = 2
MAX_CPPTYPE = 10
MAX_LABEL = 3
MAX_TYPE = 18
TYPE_BOOL = 8
TYPE_BYTES = 12
TYPE_DOUBLE = 1
TYPE_ENUM = 14
TYPE_FIXED32 = 7
TYPE_FIXED64 = 6
TYPE_FLOAT = 2
TYPE_GROUP = 10
TYPE_INT32 = 5
TYPE_INT64 = 3
TYPE_MESSAGE = 11
TYPE_SFIXED32 = 15
TYPE_SFIXED64 = 16
TYPE_SINT32 = 17
TYPE_SINT64 = 18
TYPE_STRING = 9
TYPE_UINT32 = 13
TYPE_UINT64 = 4
class google.protobuf.descriptor.FileDescriptor(name, package, options=None, serialized_pb=None)[source]

Bases: google.protobuf.descriptor.DescriptorBase

Descriptor for a file. Mimics the descriptor_pb2.FileDescriptorProto.

name: name of file, relative to root of source tree. package: name of the package serialized_pb: (str) Byte string of serialized

descriptor_pb2.FileDescriptorProto.
CopyToProto(proto)[source]

Copies this to a descriptor_pb2.FileDescriptorProto.

Args:
proto: An empty descriptor_pb2.FileDescriptorProto.
class google.protobuf.descriptor.MethodDescriptor(name, full_name, index, containing_service, input_type, output_type, options=None)[source]

Bases: google.protobuf.descriptor.DescriptorBase

Descriptor for a method in a service.

name: (str) Name of the method within the service. full_name: (str) Full name of method. index: (int) 0-indexed index of the method inside the service. containing_service: (ServiceDescriptor) The service that contains this

method.

input_type: The descriptor of the message that this method accepts. output_type: The descriptor of the message that this method returns. options: (descriptor_pb2.MethodOptions) Method options message or

None to use default method options.
class google.protobuf.descriptor.ServiceDescriptor(name, full_name, index, methods, options=None, file=None, serialized_start=None, serialized_end=None)[source]

Bases: google.protobuf.descriptor._NestedDescriptorBase

Descriptor for a service.

name: (str) Name of the service. full_name: (str) Full name of the service, including package name. index: (int) 0-indexed index giving the order that this services

definition appears withing the .proto file.
methods: (list of MethodDescriptor) List of methods provided by this
service.
options: (descriptor_pb2.ServiceOptions) Service options message or
None to use default service options.

file: (FileDescriptor) Reference to file info.

CopyToProto(proto)[source]

Copies this to a descriptor_pb2.ServiceDescriptorProto.

Args:
proto: An empty descriptor_pb2.ServiceDescriptorProto.
FindMethodByName(name)[source]

Searches for the specified method, and returns its descriptor.

descriptor_pb2 Module

class google.protobuf.descriptor_pb2.DescriptorProto(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A390>
ENUM_TYPE_FIELD_NUMBER = 4
EXTENSION_FIELD_NUMBER = 6
EXTENSION_RANGE_FIELD_NUMBER = 5
class ExtensionRange(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A290>
END_FIELD_NUMBER = 2
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
START_FIELD_NUMBER = 1
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

end

Magic attribute generated for “end” proto field.

start

Magic attribute generated for “start” proto field.

DescriptorProto.FIELD_FIELD_NUMBER = 2
DescriptorProto.FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static DescriptorProto.FromString(s)
DescriptorProto.HasField(field_name)
DescriptorProto.IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
DescriptorProto.ListFields()
DescriptorProto.MergeFrom(msg)
DescriptorProto.MergeFromString(serialized)
DescriptorProto.NAME_FIELD_NUMBER = 1
DescriptorProto.NESTED_TYPE_FIELD_NUMBER = 3
DescriptorProto.OPTIONS_FIELD_NUMBER = 7
static DescriptorProto.RegisterExtension(extension_handle)
DescriptorProto.SerializePartialToString()
DescriptorProto.SerializeToString()
DescriptorProto.SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

DescriptorProto.enum_type

Magic attribute generated for “enum_type” proto field.

DescriptorProto.extension

Magic attribute generated for “extension” proto field.

DescriptorProto.extension_range

Magic attribute generated for “extension_range” proto field.

DescriptorProto.field

Magic attribute generated for “field” proto field.

DescriptorProto.name

Magic attribute generated for “name” proto field.

DescriptorProto.nested_type

Magic attribute generated for “nested_type” proto field.

DescriptorProto.options

Magic attribute generated for “options” proto field.

class google.protobuf.descriptor_pb2.EnumDescriptorProto(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A530>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
NAME_FIELD_NUMBER = 1
OPTIONS_FIELD_NUMBER = 3
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

VALUE_FIELD_NUMBER = 2
name

Magic attribute generated for “name” proto field.

options

Magic attribute generated for “options” proto field.

value

Magic attribute generated for “value” proto field.

class google.protobuf.descriptor_pb2.EnumOptions(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearExtension(extension_handle)
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A990>
Extensions
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasExtension(extension_handle)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

UNINTERPRETED_OPTION_FIELD_NUMBER = 999
uninterpreted_option

Magic attribute generated for “uninterpreted_option” proto field.

class google.protobuf.descriptor_pb2.EnumValueDescriptorProto(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A5B0>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
NAME_FIELD_NUMBER = 1
NUMBER_FIELD_NUMBER = 2
OPTIONS_FIELD_NUMBER = 3
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

name

Magic attribute generated for “name” proto field.

number

Magic attribute generated for “number” proto field.

options

Magic attribute generated for “options” proto field.

class google.protobuf.descriptor_pb2.EnumValueOptions(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearExtension(extension_handle)
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A9D0>
Extensions
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasExtension(extension_handle)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

UNINTERPRETED_OPTION_FIELD_NUMBER = 999
uninterpreted_option

Magic attribute generated for “uninterpreted_option” proto field.

class google.protobuf.descriptor_pb2.FieldDescriptorProto(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DEFAULT_VALUE_FIELD_NUMBER = 7
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A4B0>
EXTENDEE_FIELD_NUMBER = 2
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
LABEL_FIELD_NUMBER = 4
LABEL_OPTIONAL = 1
LABEL_REPEATED = 3
LABEL_REQUIRED = 2
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
NAME_FIELD_NUMBER = 1
NUMBER_FIELD_NUMBER = 3
OPTIONS_FIELD_NUMBER = 8
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

TYPE_BOOL = 8
TYPE_BYTES = 12
TYPE_DOUBLE = 1
TYPE_ENUM = 14
TYPE_FIELD_NUMBER = 5
TYPE_FIXED32 = 7
TYPE_FIXED64 = 6
TYPE_FLOAT = 2
TYPE_GROUP = 10
TYPE_INT32 = 5
TYPE_INT64 = 3
TYPE_MESSAGE = 11
TYPE_NAME_FIELD_NUMBER = 6
TYPE_SFIXED32 = 15
TYPE_SFIXED64 = 16
TYPE_SINT32 = 17
TYPE_SINT64 = 18
TYPE_STRING = 9
TYPE_UINT32 = 13
TYPE_UINT64 = 4
default_value

Magic attribute generated for “default_value” proto field.

extendee

Magic attribute generated for “extendee” proto field.

label

Magic attribute generated for “label” proto field.

name

Magic attribute generated for “name” proto field.

number

Magic attribute generated for “number” proto field.

options

Magic attribute generated for “options” proto field.

type

Magic attribute generated for “type” proto field.

type_name

Magic attribute generated for “type_name” proto field.

class google.protobuf.descriptor_pb2.FieldOptions(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
CORD = 1
CTYPE_FIELD_NUMBER = 1
Clear()
ClearExtension(extension_handle)
ClearField(field_name)
DEPRECATED_FIELD_NUMBER = 3
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A950>
EXPERIMENTAL_MAP_KEY_FIELD_NUMBER = 9
Extensions
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasExtension(extension_handle)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
PACKED_FIELD_NUMBER = 2
static RegisterExtension(extension_handle)
STRING = 0
STRING_PIECE = 2
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

UNINTERPRETED_OPTION_FIELD_NUMBER = 999
ctype

Magic attribute generated for “ctype” proto field.

deprecated

Magic attribute generated for “deprecated” proto field.

experimental_map_key

Magic attribute generated for “experimental_map_key” proto field.

packed

Magic attribute generated for “packed” proto field.

uninterpreted_option

Magic attribute generated for “uninterpreted_option” proto field.

class google.protobuf.descriptor_pb2.FileDescriptorProto(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DEPENDENCY_FIELD_NUMBER = 3
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A230>
ENUM_TYPE_FIELD_NUMBER = 5
EXTENSION_FIELD_NUMBER = 7
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MESSAGE_TYPE_FIELD_NUMBER = 4
MergeFrom(msg)
MergeFromString(serialized)
NAME_FIELD_NUMBER = 1
OPTIONS_FIELD_NUMBER = 8
PACKAGE_FIELD_NUMBER = 2
static RegisterExtension(extension_handle)
SERVICE_FIELD_NUMBER = 6
SOURCE_CODE_INFO_FIELD_NUMBER = 9
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

dependency

Magic attribute generated for “dependency” proto field.

enum_type

Magic attribute generated for “enum_type” proto field.

extension

Magic attribute generated for “extension” proto field.

message_type

Magic attribute generated for “message_type” proto field.

name

Magic attribute generated for “name” proto field.

options

Magic attribute generated for “options” proto field.

package

Magic attribute generated for “package” proto field.

service

Magic attribute generated for “service” proto field.

source_code_info

Magic attribute generated for “source_code_info” proto field.

class google.protobuf.descriptor_pb2.FileDescriptorSet(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A0F0>
FILE_FIELD_NUMBER = 1
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

file

Magic attribute generated for “file” proto field.

class google.protobuf.descriptor_pb2.FileOptions(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
CC_GENERIC_SERVICES_FIELD_NUMBER = 16
CODE_SIZE = 2
Clear()
ClearExtension(extension_handle)
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A810>
Extensions
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasExtension(extension_handle)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
JAVA_GENERATE_EQUALS_AND_HASH_FIELD_NUMBER = 20
JAVA_GENERIC_SERVICES_FIELD_NUMBER = 17
JAVA_MULTIPLE_FILES_FIELD_NUMBER = 10
JAVA_OUTER_CLASSNAME_FIELD_NUMBER = 8
JAVA_PACKAGE_FIELD_NUMBER = 1
LITE_RUNTIME = 3
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
OPTIMIZE_FOR_FIELD_NUMBER = 9
PY_GENERIC_SERVICES_FIELD_NUMBER = 18
static RegisterExtension(extension_handle)
SPEED = 1
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

UNINTERPRETED_OPTION_FIELD_NUMBER = 999
cc_generic_services

Magic attribute generated for “cc_generic_services” proto field.

java_generate_equals_and_hash

Magic attribute generated for “java_generate_equals_and_hash” proto field.

java_generic_services

Magic attribute generated for “java_generic_services” proto field.

java_multiple_files

Magic attribute generated for “java_multiple_files” proto field.

java_outer_classname

Magic attribute generated for “java_outer_classname” proto field.

java_package

Magic attribute generated for “java_package” proto field.

optimize_for

Magic attribute generated for “optimize_for” proto field.

py_generic_services

Magic attribute generated for “py_generic_services” proto field.

uninterpreted_option

Magic attribute generated for “uninterpreted_option” proto field.

class google.protobuf.descriptor_pb2.MessageOptions(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearExtension(extension_handle)
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A890>
Extensions
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasExtension(extension_handle)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MESSAGE_SET_WIRE_FORMAT_FIELD_NUMBER = 1
MergeFrom(msg)
MergeFromString(serialized)
NO_STANDARD_DESCRIPTOR_ACCESSOR_FIELD_NUMBER = 2
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

UNINTERPRETED_OPTION_FIELD_NUMBER = 999
message_set_wire_format

Magic attribute generated for “message_set_wire_format” proto field.

no_standard_descriptor_accessor

Magic attribute generated for “no_standard_descriptor_accessor” proto field.

uninterpreted_option

Magic attribute generated for “uninterpreted_option” proto field.

class google.protobuf.descriptor_pb2.MethodDescriptorProto(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A6D0>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
INPUT_TYPE_FIELD_NUMBER = 2
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
NAME_FIELD_NUMBER = 1
OPTIONS_FIELD_NUMBER = 4
OUTPUT_TYPE_FIELD_NUMBER = 3
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

input_type

Magic attribute generated for “input_type” proto field.

name

Magic attribute generated for “name” proto field.

options

Magic attribute generated for “options” proto field.

output_type

Magic attribute generated for “output_type” proto field.

class google.protobuf.descriptor_pb2.MethodOptions(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearExtension(extension_handle)
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481AA50>
Extensions
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasExtension(extension_handle)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

UNINTERPRETED_OPTION_FIELD_NUMBER = 999
uninterpreted_option

Magic attribute generated for “uninterpreted_option” proto field.

class google.protobuf.descriptor_pb2.ServiceDescriptorProto(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481A630>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
METHOD_FIELD_NUMBER = 2
MergeFrom(msg)
MergeFromString(serialized)
NAME_FIELD_NUMBER = 1
OPTIONS_FIELD_NUMBER = 3
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

method

Magic attribute generated for “method” proto field.

name

Magic attribute generated for “name” proto field.

options

Magic attribute generated for “options” proto field.

class google.protobuf.descriptor_pb2.ServiceOptions(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearExtension(extension_handle)
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481AA10>
Extensions
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasExtension(extension_handle)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

UNINTERPRETED_OPTION_FIELD_NUMBER = 999
uninterpreted_option

Magic attribute generated for “uninterpreted_option” proto field.

class google.protobuf.descriptor_pb2.SourceCodeInfo(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481AC50>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
LOCATION_FIELD_NUMBER = 1
ListFields()
class Location(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481AC10>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
PATH_FIELD_NUMBER = 1
static RegisterExtension(extension_handle)
SPAN_FIELD_NUMBER = 2
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

path

Magic attribute generated for “path” proto field.

span

Magic attribute generated for “span” proto field.

SourceCodeInfo.MergeFrom(msg)
SourceCodeInfo.MergeFromString(serialized)
static SourceCodeInfo.RegisterExtension(extension_handle)
SourceCodeInfo.SerializePartialToString()
SourceCodeInfo.SerializeToString()
SourceCodeInfo.SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

SourceCodeInfo.location

Magic attribute generated for “location” proto field.

class google.protobuf.descriptor_pb2.UninterpretedOption(**kwargs)[source]

Bases: google.protobuf.message.Message

AGGREGATE_VALUE_FIELD_NUMBER = 8
ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481ABB0>
DOUBLE_VALUE_FIELD_NUMBER = 6
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IDENTIFIER_VALUE_FIELD_NUMBER = 3
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
NAME_FIELD_NUMBER = 2
NEGATIVE_INT_VALUE_FIELD_NUMBER = 5
class NamePart(**kwargs)[source]

Bases: google.protobuf.message.Message

ByteSize()
Clear()
ClearField(field_name)
DESCRIPTOR = <google.protobuf.descriptor.Descriptor object at 0x0481AAB0>
FindInitializationErrors()

Finds required fields which are not initialized.

Returns:
A list of strings. Each string is a path to an uninitialized field from the top-level message, e.g. “foo.bar[5].baz”.
static FromString(s)
HasField(field_name)
IS_EXTENSION_FIELD_NUMBER = 2
IsInitialized(errors=None)

Checks if all required fields of a message are set.

Args:
errors: A list which, if provided, will be populated with the field
paths of all missing required fields.
Returns:
True iff the specified message has all required fields set.
ListFields()
MergeFrom(msg)
MergeFromString(serialized)
NAME_PART_FIELD_NUMBER = 1
static RegisterExtension(extension_handle)
SerializePartialToString()
SerializeToString()
SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

is_extension

Magic attribute generated for “is_extension” proto field.

name_part

Magic attribute generated for “name_part” proto field.

UninterpretedOption.POSITIVE_INT_VALUE_FIELD_NUMBER = 4
static UninterpretedOption.RegisterExtension(extension_handle)
UninterpretedOption.STRING_VALUE_FIELD_NUMBER = 7
UninterpretedOption.SerializePartialToString()
UninterpretedOption.SerializeToString()
UninterpretedOption.SetInParent()

Sets the _cached_byte_size_dirty bit to true, and propagates this to our listener iff this was a state change.

UninterpretedOption.aggregate_value

Magic attribute generated for “aggregate_value” proto field.

UninterpretedOption.double_value

Magic attribute generated for “double_value” proto field.

UninterpretedOption.identifier_value

Magic attribute generated for “identifier_value” proto field.

UninterpretedOption.name

Magic attribute generated for “name” proto field.

UninterpretedOption.negative_int_value

Magic attribute generated for “negative_int_value” proto field.

UninterpretedOption.positive_int_value

Magic attribute generated for “positive_int_value” proto field.

UninterpretedOption.string_value

Magic attribute generated for “string_value” proto field.

message Module

Contains an abstract base class for protocol messages.

exception google.protobuf.message.DecodeError[source]

Bases: google.protobuf.message.Error

exception google.protobuf.message.EncodeError[source]

Bases: google.protobuf.message.Error

exception google.protobuf.message.Error[source]

Bases: exceptions.Exception

class google.protobuf.message.Message[source]

Bases: object

Abstract base class for protocol messages.

Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.

TODO(robinson): Link to an HTML document here.

TODO(robinson): Document that instances of this class will also have an Extensions attribute with __getitem__ and __setitem__. Again, not sure how to best convey this.

TODO(robinson): Document that the class must also have a static
RegisterExtension(extension_field) method. Not sure how to best express at this point.
ByteSize()[source]

Returns the serialized size of this message. Recursively calls ByteSize() on all contained messages.

Clear()[source]

Clears all data that was set in the message.

ClearExtension(extension_handle)[source]
ClearField(field_name)[source]
CopyFrom(other_msg)[source]

Copies the content of the specified message into the current message.

The method clears the current message and then merges the specified message using MergeFrom.

Args:
other_msg: Message to copy into the current one.
DESCRIPTOR = None
HasExtension(extension_handle)[source]
HasField(field_name)[source]

Checks if a certain field is set for the message. Note if the field_name is not defined in the message descriptor, ValueError will be raised.

IsInitialized()[source]

Checks if the message is initialized.

Returns:
The method returns True if the message is initialized (i.e. all of its required fields are set).
ListFields()[source]

Returns a list of (FieldDescriptor, value) tuples for all fields in the message which are not empty. A singular field is non-empty if HasField() would return true, and a repeated field is non-empty if it contains at least one element. The fields are ordered by field number

MergeFrom(other_msg)[source]

Merges the contents of the specified message into current message.

This method merges the contents of the specified message into the current message. Singular fields that are set in the specified message overwrite the corresponding fields in the current message. Repeated fields are appended. Singular sub-messages and groups are recursively merged.

Args:
other_msg: Message to merge into the current message.
MergeFromString(serialized)[source]

Merges serialized protocol buffer data into this message.

When we find a field in |serialized| that is already present in this message:

  • If it’s a “repeated” field, we append to the end of our list.
  • Else, if it’s a scalar, we overwrite our field.
  • Else, (it’s a nonrepeated composite), we recursively merge into the existing composite.

TODO(robinson): Document handling of unknown fields.

Args:
serialized: Any object that allows us to call buffer(serialized)
to access a string of bytes using the buffer interface.

TODO(robinson): When we switch to a helper, this will return None.

Returns:
The number of bytes read from |serialized|. For non-group messages, this will always be len(serialized), but for messages which are actually groups, this will generally be less than len(serialized), since we must stop when we reach an END_GROUP tag. Note that if we do stop because of an END_GROUP tag, the number of bytes returned does not include the bytes for the END_GROUP tag information.
ParseFromString(serialized)[source]

Like MergeFromString(), except we clear the object first.

SerializePartialToString()[source]

Serializes the protocol message to a binary string.

This method is similar to SerializeToString but doesn’t check if the message is initialized.

Returns:
A string representation of the partial message.
SerializeToString()[source]

Serializes the protocol message to a binary string.

Returns:
A binary string representation of the message if all of the required fields in the message are set (i.e. the message is initialized).
Raises:
message.EncodeError if the message isn’t initialized.
SetInParent()[source]

Mark this as present in the parent.

This normally happens automatically when you assign a field of a sub-message, but sometimes you want to make the sub-message present while keeping it empty. If you find yourself using this, you may want to reconsider your design.

reflection Module

Contains a metaclass and helper functions used to create protocol message classes from Descriptor objects at runtime.

Recall that a metaclass is the “type” of a class. (A class is to a metaclass what an instance is to a class.)

In this case, we use the GeneratedProtocolMessageType metaclass to inject all the useful functionality into the classes output by the protocol compiler at compile-time.

The upshot of all this is that the real implementation details for ALL pure-Python protocol buffers are here in this file.

class google.protobuf.reflection.GeneratedProtocolMessageType(name, bases, dictionary)[source]

Bases: type

Metaclass for protocol message classes created at runtime from Descriptors.

We add implementations for all methods described in the Message class. We also create properties to allow getting/setting all fields in the protocol message. Finally, we create slots to prevent users from accidentally “setting” nonexistent fields in the protocol message, which then wouldn’t get serialized / deserialized properly.

The protocol compiler currently uses this metaclass to create protocol message classes at runtime. Clients can also manually create their own classes at runtime, as in this example:

mydescriptor = Descriptor(.....) class MyProtoClass(Message):

__metaclass__ = GeneratedProtocolMessageType DESCRIPTOR = mydescriptor

myproto_instance = MyProtoClass() myproto.foo_field = 23 ...

service Module

DEPRECATED: Declares the RPC service interfaces.

This module declares the abstract interfaces underlying proto2 RPC services. These are intended to be independent of any particular RPC implementation, so that proto2 services can be used on top of a variety of implementations. Starting with version 2.3.0, RPC implementations should not try to build on these, but should instead provide code generator plugins which generate code specific to the particular RPC implementation. This way the generated code can be more appropriate for the implementation in use and can avoid unnecessary layers of indirection.

class google.protobuf.service.RpcChannel[source]

Bases: object

Abstract interface for an RPC channel.

An RpcChannel represents a communication line to a service which can be used to call that service’s methods. The service may be running on another machine. Normally, you should not use an RpcChannel directly, but instead construct a stub {@link Service} wrapping it. Example:

Example:
RpcChannel channel = rpcImpl.Channel(“remotehost.example.com:1234”) RpcController controller = rpcImpl.Controller() MyService service = MyService_Stub(channel) service.MyMethod(controller, request, callback)
CallMethod(method_descriptor, rpc_controller, request, response_class, done)[source]

Calls the method identified by the descriptor.

Call the given method of the remote service. The signature of this procedure looks the same as Service.CallMethod(), but the requirements are less strict in one important way: the request object doesn’t have to be of any specific class as long as its descriptor is method.input_type.

class google.protobuf.service.RpcController[source]

Bases: object

An RpcController mediates a single method call.

The primary purpose of the controller is to provide a way to manipulate settings specific to the RPC implementation and to find out about RPC-level errors. The methods provided by the RpcController interface are intended to be a “least common denominator” set of features which we expect all implementations to support. Specific implementations may provide more advanced features (e.g. deadline propagation).

ErrorText()[source]

If Failed is true, returns a human-readable description of the error.

Failed()[source]

Returns true if the call failed.

After a call has finished, returns true if the call failed. The possible reasons for failure depend on the RPC implementation. Failed() must not be called before a call has finished. If Failed() returns true, the contents of the response message are undefined.

IsCanceled()[source]

Checks if the client cancelled the RPC.

If true, indicates that the client canceled the RPC, so the server may as well give up on replying to it. The server should still call the final “done” callback.

NotifyOnCancel(callback)[source]

Sets a callback to invoke on cancel.

Asks that the given callback be called when the RPC is canceled. The callback will always be called exactly once. If the RPC completes without being canceled, the callback will be called after completion. If the RPC has already been canceled when NotifyOnCancel() is called, the callback will be called immediately.

NotifyOnCancel() must be called no more than once per request.

Reset()[source]

Resets the RpcController to its initial state.

After the RpcController has been reset, it may be reused in a new call. Must not be called while an RPC is in progress.

SetFailed(reason)[source]

Sets a failure reason.

Causes Failed() to return true on the client side. “reason” will be incorporated into the message returned by ErrorText(). If you find you need to return machine-readable information about failures, you should incorporate it into your response protocol buffer and should NOT call SetFailed().

StartCancel()[source]

Initiate cancellation.

Advises the RPC system that the caller desires that the RPC call be canceled. The RPC system may cancel it immediately, may wait awhile and then cancel it, or may not even cancel the call at all. If the call is canceled, the “done” callback will still be called and the RpcController will indicate that the call failed at that time.

exception google.protobuf.service.RpcException[source]

Bases: exceptions.Exception

Exception raised on failed blocking RPC method call.

class google.protobuf.service.Service[source]

Bases: object

Abstract base interface for protocol-buffer-based RPC services.

Services themselves are abstract classes (implemented either by servers or as stubs), but they subclass this base interface. The methods of this interface can be used to call the methods of the service without knowing its exact type at compile time (analogous to the Message interface).

CallMethod(method_descriptor, rpc_controller, request, done)[source]

Calls a method of the service specified by method_descriptor.

If “done” is None then the call is blocking and the response message will be returned directly. Otherwise the call is asynchronous and “done” will later be called with the response value.

In the blocking case, RpcException will be raised on error.

Preconditions: * method_descriptor.service == GetDescriptor * request is of the exact same classes as returned by

GetRequestClass(method).
  • After the call has started, the request must not be modified.
  • “rpc_controller” is of the correct type for the RPC implementation being used by this Service. For stubs, the “correct type” depends on the RpcChannel which the stub is using.

Postconditions: * “done” will be called when the method is complete. This may be

before CallMethod() returns or it may be at some point in the future.
  • If the RPC failed, the response value passed to “done” will be None. Further details about the failure can be found by querying the RpcController.
GetDescriptor()[source]

Retrieves this service’s descriptor.

GetRequestClass(method_descriptor)[source]

Returns the class of the request message for the specified method.

CallMethod() requires that the request is of a particular subclass of Message. GetRequestClass() gets the default instance of this required type.

Example:
method = service.GetDescriptor().FindMethodByName(“Foo”) request = stub.GetRequestClass(method)() request.ParseFromString(input) service.CallMethod(method, request, callback)
GetResponseClass(method_descriptor)[source]

Returns the class of the response message for the specified method.

This method isn’t really needed, as the RpcChannel’s CallMethod constructs the response protocol message. It’s provided anyway in case it is useful for the caller to know the response type in advance.

service_reflection Module

Contains metaclasses used to create protocol service and service stub classes from ServiceDescriptor objects at runtime.

The GeneratedServiceType and GeneratedServiceStubType metaclasses are used to inject all useful functionality into the classes output by the protocol compiler at compile-time.

class google.protobuf.service_reflection.GeneratedServiceStubType(name, bases, dictionary)[source]

Bases: google.protobuf.service_reflection.GeneratedServiceType

Metaclass for service stubs created at runtime from ServiceDescriptors.

This class has similar responsibilities as GeneratedServiceType, except that it creates the service stub classes.

class google.protobuf.service_reflection.GeneratedServiceType(name, bases, dictionary)[source]

Bases: type

Metaclass for service classes created at runtime from ServiceDescriptors.

Implementations for all methods described in the Service class are added here by this class. We also create properties to allow getting/setting all fields in the protocol message.

The protocol compiler currently uses this metaclass to create protocol service classes at runtime. Clients can also manually create their own classes at runtime, as in this example:

mydescriptor = ServiceDescriptor(.....) class MyProtoService(service.Service):

__metaclass__ = GeneratedServiceType DESCRIPTOR = mydescriptor

myservice_instance = MyProtoService() ...

text_format Module

Contains routines for printing protocol messages in text format.

google.protobuf.text_format.MessageToString(message, as_utf8=False, as_one_line=False)[source]
google.protobuf.text_format.PrintMessage(message, out, indent=0, as_utf8=False, as_one_line=False)[source]
google.protobuf.text_format.PrintField(field, value, out, indent=0, as_utf8=False, as_one_line=False)[source]

Print a single field name/value pair. For repeated fields, the value should be a single element.

google.protobuf.text_format.PrintFieldValue(field, value, out, indent=0, as_utf8=False, as_one_line=False)[source]

Print a single field value (not including name). For repeated fields, the value should be a single element.

google.protobuf.text_format.Merge(text, message)[source]

Merges an ASCII representation of a protocol message into a message.

Args:
text: Message ASCII representation. message: A protocol buffer message to merge into.
Raises:
ParseError: On ASCII parsing problems.

Table Of Contents

Previous topic

google Package

Next topic

compiler Package

This Page