Python 2.7 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Python 2.7
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Python
2.7 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Python.
Definition Module Functions
Stay organized with collections
Save and categorize content based on your preferences.
The protorpc.definition
package provides the following functions:
- define_enum(enum_descriptor, module_name)
-
Defines an Enum class for a descriptor.
Arguments
- enum_descriptor
- EnumDescriptor to use to build the Enum class.
- module_name
- Module name to give the new descriptor class.
Returns a new messages.Enum subclass as described by enum_descriptor
.
- define_field(field_descriptor)
-
Defines a Field instance from the provided descriptor.
Arguments
- field_descriptor
- FieldDescriptor class to use to build the Field instance.
Returns a new field instance as described by field_descriptor
.
- define_message(message_descriptor, module_name)
-
Defines a Message class from the provided descriptor.
Arguments
- message_descriptor
- MessageDescriptor to use to describe the message class.
- module_name
- The module name to give the new descriptor class.
Returns a new messages.Message sub-class as described by message_descriptor
.
- define_service(service_descriptor, module)
-
Defines a new service proxy.
Arguments
- service_descriptor
- ServiceDescriptor class that describes the service.
- module
- The module to add the service to. Request and response types are found relative to this module.
Returns a class proxy capable of communicating with a remote server.
- define_file(file_descriptor, module=None)
-
Defines a module from the given file descriptor.
Arguments
- file_descriptor
- FileDescriptor instance from which to describe the module.
- module=None
- Module to which to add contained objects. Module name overrides value in file_descriptor.package. Definitions are added to the existing module if provided.
If no module is provided, creates a new module with its name set to the file descriptor's package. If a module is provided, returns the same module.
Utility Functions
- import_file(file_descriptor, modules=None)
-
Imports a FileDescriptor into a module space. Similar to define_file(), except that a new module and any required parent modules are created and added to the modules parameter, or sys.modules if not provided.
Arguments
- file_descriptor
- FileDescriptor instance from which to describe the module.
- modulesmodules=None
- Dictionary of modules to update. Modules and their parents that
do not exist will be created. If an existing module is found that
matches
file_descriptor.package
, that module is updated with the FileDescriptor contents.
Returns matches to the modules
argument, or a new module if no matches are found.
- import_file_set(file_set, modules=None)
-
Arguments
- file_set
- Either a string or a FileSet instance. If a string, import_file_set() opens the file and reads the serialized FileSet. If a FileSet instance, imports definitions from this instance.
- modules
- Dictionary of modules to update. Modules and their parents that do not exist will be created. If an existing module is found that matches the
file_descriptor.package
, that module is updated with the FileDescriptor contents.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-03 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eprotorpc.definition\u003c/code\u003e package provides functions for defining various components like Enums, Fields, Messages, and Services from their respective descriptors.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003edefine_file\u003c/code\u003e and \u003ccode\u003eimport_file\u003c/code\u003e allow creating or importing modules based on a \u003ccode\u003eFileDescriptor\u003c/code\u003e, with the latter automatically creating parent modules if necessary.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003edefine_enum\u003c/code\u003e, \u003ccode\u003edefine_field\u003c/code\u003e, \u003ccode\u003edefine_message\u003c/code\u003e, and \u003ccode\u003edefine_service\u003c/code\u003e each creates a new class or instance based on a descriptor, such as \u003ccode\u003eEnumDescriptor\u003c/code\u003e, \u003ccode\u003eFieldDescriptor\u003c/code\u003e, \u003ccode\u003eMessageDescriptor\u003c/code\u003e and \u003ccode\u003eServiceDescriptor\u003c/code\u003e respectively.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eimport_file_set\u003c/code\u003e can import definitions from a \u003ccode\u003eFileSet\u003c/code\u003e instance or a serialized \u003ccode\u003eFileSet\u003c/code\u003e string, updating a provided module dictionary or creating new modules if needed.\u003c/p\u003e\n"]]],[],null,["# Definition Module Functions\n\nThe `protorpc.definition` package provides the following functions:\n\ndefine_enum(enum_descriptor, module_name)\n\n: Defines an Enum class for a descriptor.\n\n **Arguments**\n\n enum_descriptor\n : EnumDescriptor to use to build the Enum class.\n\n module_name\n : Module name to give the new descriptor class.\n\n Returns a new [messages.Enum](/appengine/docs/legacy/standard/python/tools/protorpc/messages/enumclass) subclass as described by `enum_descriptor`.\n\ndefine_field(field_descriptor)\n\n: Defines a Field instance from the provided descriptor.\n\n **Arguments**\n\n field_descriptor\n : FieldDescriptor class to use to build the Field instance.\n\n Returns a new field instance as described by `field_descriptor`.\n\ndefine_message(message_descriptor, module_name)\n\n: Defines a Message class from the provided descriptor.\n\n **Arguments**\n\n message_descriptor\n : MessageDescriptor to use to describe the message class.\n\n module_name\n : The module name to give the new descriptor class.\n\n Returns a new [messages.Message sub-class](/appengine/docs/legacy/standard/python/tools/protorpc/messages/messageclass) as described by `message_descriptor`.\n\ndefine_service(service_descriptor, module)\n\n: Defines a new service proxy.\n\n **Arguments**\n\n service_descriptor\n : ServiceDescriptor class that describes the service.\n\n module\n : The module to add the service to. Request and response types are found relative to this module.\n\n Returns a class proxy capable of communicating with a remote server.\n\ndefine_file(file_descriptor, module=None)\n\n: Defines a module from the given file descriptor.\n\n **Arguments**\n\n file_descriptor\n : FileDescriptor instance from which to describe the module.\n\n module=None\n : Module to which to add contained objects. Module name overrides value in file_descriptor.package. Definitions are added to the existing module if provided.\n\n If no module is provided, creates a new module with its name set to the file descriptor's package. If a module is provided, returns the same module.\n\nimport_file(file_descriptor, modules=None)\n\n: Imports a FileDescriptor into a module space. Similar to [define_file()](#define_file), except that a new module and any required parent modules are created and added to the modules parameter, or sys.modules if not provided.\n\n **Arguments**\n\n file_descriptor\n : FileDescriptor instance from which to describe the module.\n\n modulesmodules=None\n : Dictionary of modules to update. Modules and their parents that\n do not exist will be created. If an existing module is found that\n matches `file_descriptor.package`, that module is updated with the FileDescriptor contents.\n\n Returns matches to the `modules` argument, or a new module if no matches are found.\n\nimport_file_set(file_set, modules=None)\n\n: \u003cbr /\u003e\n\n **Arguments**\n\n file_set\n : Either a string or a FileSet instance. If a string, import_file_set() opens the file and reads the serialized FileSet. If a FileSet instance, imports definitions from this instance.\n\n modules\n : Dictionary of modules to update. Modules and their parents that do not exist will be created. If an existing module is found that matches the `file_descriptor.package`, that module is updated with the FileDescriptor contents."]]