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.
Messages Module Functions
Stay organized with collections
Save and categorize content based on your preferences.
The protorpc.messages
package provides the following positional utility function:
- find_definition(name, relative_to=None)
-
Find definition by name in module-space.
The find algorithm finds definitions by name relative to a message definition or by fully qualified name. If no definition is found relative to the relative_to
parameter, it searches against the container of relative_to
. If relative_to
is a nested Message, it searches its message_definition(). If that message has no message_definition(), it searches its module. If relative_to
is a module, the find algorithm searches for the containing module and searches relative to it. If the module is a top-level module, the find algorithm searches for the a message using a fully qualified name. If it still finds no message, the search fails and the method raises a DefinitionNotFoundError.
For example, when looking for any definition foo.bar.ADefinition
relative to an actual message definition abc.xyz.SomeMessage
:
find_definition('foo.bar.ADefinition', SomeMessage)
The arguments to this method follow a pattern similar to a search for fully qualified names:
abc.xyz.SomeMessage. foo.bar.ADefinition
abc.xyz. foo.bar.ADefinition
abc. foo.bar.ADefinition
foo.bar.ADefinition
When resolving the name relative to Message definitions and modules, the algorithm searches any Messages or sub-modules found in its path, ignoring non-Message values.
A name that begins with '.'
is considered to be a fully qualified name. The find algorithm begins searching from the topmost package. For example, assume two message types:
abc.xyz.SomeMessage
xyz.SomeMessage
Searching for .xyz.SomeMessage
relative to abc
resolves to xyz.SomeMessage
and not abc.xyz.SomeMessage
. For this kind of name,
the relative_to parameter is effectively ignored and always set to None.
For more information about package name resolution, please see the Protocol Buffers Package specifier.
Arguments
- name
- Name of a definition to find. May be fully qualified or relative.
- relative_to
- Searches for a definition relative to the message definition or module. If None, causes a fully qualified name search.
Returns an Enum or Message class definition associated with the name.
raises a DefinitionNotFoundError if no definition is found in any search path.
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-08-07 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-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003efind_definition\u003c/code\u003e function in \u003ccode\u003eprotorpc.messages\u003c/code\u003e locates definitions by name, either relative to a message or module or by a fully qualified name.\u003c/p\u003e\n"],["\u003cp\u003eThe search algorithm for \u003ccode\u003efind_definition\u003c/code\u003e prioritizes searching relative to the \u003ccode\u003erelative_to\u003c/code\u003e parameter, progressing up the module hierarchy if necessary and then falling back to searching by fully qualified name.\u003c/p\u003e\n"],["\u003cp\u003eA name starting with \u003ccode\u003e'.'\u003c/code\u003e in \u003ccode\u003efind_definition\u003c/code\u003e is treated as fully qualified, starting the search from the topmost package and ignoring the \u003ccode\u003erelative_to\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003efind_definition\u003c/code\u003e method requires two arguments: \u003ccode\u003ename\u003c/code\u003e, which can be fully qualified or relative, and \u003ccode\u003erelative_to\u003c/code\u003e, that specifies a definition to start the search from.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003efind_definition\u003c/code\u003e will return an \u003ccode\u003eEnum\u003c/code\u003e or \u003ccode\u003eMessage\u003c/code\u003e class definition, and in case a definition cannot be found, it will raise a \u003ccode\u003eDefinitionNotFoundError\u003c/code\u003e exception.\u003c/p\u003e\n"]]],[],null,[]]