google.protobuf.descriptor_pool

Provides DescriptorPool to use as a container for proto2 descriptors.

The DescriptorPool is used in conjection with a DescriptorDatabase to maintain a collection of protocol buffer descriptors for use when dynamically creating message types at runtime.

For most applications protocol buffers should be used via modules generated by the protocol buffer compiler tool. This should only be used when the type of protocol buffers used in an application or library cannot be predetermined.

Below is a straightforward example on how to use this class:

pool = DescriptorPool() file_descriptor_protos = [ … ] for file_descriptor_proto in file_descriptor_protos:

pool.Add(file_descriptor_proto)

my_message_descriptor = pool.FindMessageTypeByName(‘some.package.MessageType’)

The message descriptor can be used in conjunction with the message_factory module in order to create a protocol buffer class that can be encoded and decoded.

If you want to get a Python class for the specified proto, use the helper functions inside google.protobuf.message_factory directly instead of this class.

google.protobuf.descriptor_pool.Default()
class google.protobuf.descriptor_pool.DescriptorPool(descriptor_db=None)

A collection of protobufs dynamically constructed by descriptor protos.

Add(file_desc_proto)

Adds the FileDescriptorProto and its types to this pool.

Parameters

file_desc_proto – The FileDescriptorProto to add.

AddDescriptor(**kwargs)
AddEnumDescriptor(**kwargs)
AddExtensionDescriptor(**kwargs)
AddFileDescriptor(**kwargs)
AddSerializedFile(serialized_file_desc_proto)

Adds the FileDescriptorProto and its types to this pool.

Parameters

serialized_file_desc_proto – A bytes string, serialization of the FileDescriptorProto to add.

AddServiceDescriptor(**kwargs)
FindAllExtensions(message_descriptor)

Gets all the known extension of a given message.

Extensions have to be registered to this pool by calling AddExtensionDescriptor.

Parameters

message_descriptor – descriptor of the extended message.

Returns

A list of FieldDescriptor describing the extensions.

FindEnumTypeByName(full_name)

Loads the named enum descriptor from the pool.

Parameters

full_name – The full name of the enum descriptor to load.

Returns

The enum descriptor for the named type.

Raises

KeyError – if the enum cannot be found in the pool.

FindExtensionByName(full_name)

Loads the named extension descriptor from the pool.

Parameters

full_name – The full name of the extension descriptor to load.

Returns

A FieldDescriptor, describing the named extension.

Raises

KeyError – if the extension cannot be found in the pool.

FindExtensionByNumber(message_descriptor, number)

Gets the extension of the specified message with the specified number.

Extensions have to be registered to this pool by calling AddExtensionDescriptor.

Parameters
  • message_descriptor – descriptor of the extended message.

  • number – integer, number of the extension field.

Returns

A FieldDescriptor describing the extension.

Raises

KeyError – when no extension with the given number is known for the specified message.

FindFieldByName(full_name)

Loads the named field descriptor from the pool.

Parameters

full_name – The full name of the field descriptor to load.

Returns

The field descriptor for the named field.

Raises

KeyError – if the field cannot be found in the pool.

FindFileByName(file_name)

Gets a FileDescriptor by file name.

Parameters

file_name – The path to the file to get a descriptor for.

Returns

A FileDescriptor for the named file.

Raises

KeyError – if the file cannot be found in the pool.

FindFileContainingSymbol(symbol)

Gets the FileDescriptor for the file containing the specified symbol.

Parameters

symbol – The name of the symbol to search for.

Returns

A FileDescriptor that contains the specified symbol.

Raises

KeyError – if the file cannot be found in the pool.

FindMessageTypeByName(full_name)

Loads the named descriptor from the pool.

Parameters

full_name – The full name of the descriptor to load.

Returns

The descriptor for the named type.

Raises

KeyError – if the message cannot be found in the pool.

FindMethodByName(full_name)

Loads the named service method descriptor from the pool.

Parameters

full_name – The full name of the method descriptor to load.

Returns

The method descriptor for the service method.

Raises

KeyError – if the method cannot be found in the pool.

FindOneofByName(full_name)

Loads the named oneof descriptor from the pool.

Parameters

full_name – The full name of the oneof descriptor to load.

Returns

The oneof descriptor for the named oneof.

Raises

KeyError – if the oneof cannot be found in the pool.

FindServiceByName(full_name)

Loads the named service descriptor from the pool.

Parameters

full_name – The full name of the service descriptor to load.

Returns

The service descriptor for the named service.

Raises

KeyError – if the service cannot be found in the pool.