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.
Stay organized with collections
Save and categorize content based on your preferences.
google.appengine.api.yaml_builder module
Summary
PyYAML event builder handler
Receives events from YAML listener and forwards them to a builder
object so that it can construct a properly structured object.
Contents
- class google.appengine.api.yaml_builder.Buildersource
-
Bases: object
Interface for building documents and type from YAML events.
Implement this interface to create a new builder. Builders are
passed to the BuilderHandler and used as a factory and assembler
for creating concrete representations of YAML files.
- AppendTo(subject, value)source
Append value to a sequence representation.
Implementation is defined by sub-class of Builder.
Parameters
- BuildDocument()source
Build new document.
The object built by this method becomes the top level entity
that the builder handler constructs. The actual type is
determined by the sub-class of the Builder class and can essentially
be any type at all. This method is always called when the parser
encounters the start of a new document.
ReturnsNew object instance representing concrete document which is
returned to user via BuilderHandler.GetResults().
- BuildMapping(top_value)source
Build a new mapping representation.
Called when StartMapping event received. Type of object is determined
by Builder sub-class.
Parameterstop_value – Object which will be new mappings parant. Will be object
returned from previous call to BuildMapping or BuildSequence.
ReturnsInstance of new object that represents a mapping type in target model.
- BuildSequence(top_value)source
Build a new sequence representation.
Called when StartSequence event received. Type of object is determined
by Builder sub-class.
Parameterstop_value – Object which will be new sequences parant. Will be object
returned from previous call to BuildMapping or BuildSequence.
ReturnsInstance of new object that represents a sequence type in target model.
- EndMapping(top_value, mapping)source
Previously constructed mapping scope is at an end.
Called when the end of a mapping block is encountered. Useful for
additional clean up or end of scope validation.
Parameters
- EndSequence(top_value, sequence)source
Previously constructed sequence scope is at an end.
Called when the end of a sequence block is encountered. Useful for
additional clean up or end of scope validation.
Parameters
- InitializeDocument(document, value)source
Initialize document with value from top level of document.
This method is called when the root document element is encountered at
the top level of a YAML document. It should get called immediately
after BuildDocument.
Receiving the None value indicates the empty document.
Parameters
- MapTo(subject, key, value)source
Map value to a mapping representation.
Implementation is defined by sub-class of Builder.
Parameters
-
subject – Object that represents mapping. Value returned from
BuildMapping.
-
key – Key used to map value to subject. Can be any scalar value.
-
value – Value which is mapped to subject. Can be any kind of value.
- class google.appengine.api.yaml_builder.BuilderHandler(builder)source
-
Bases: google.appengine.api.yaml_listener.EventHandler
PyYAML event handler used to build objects.
Maintains state information as it receives parse events so that object
nesting is maintained. Uses provided builder object to construct and
assemble objects as it goes.
As it receives events from the YAML parser, it builds a stack of data
representing structural tokens. As the scope of documents, mappings
and sequences end, those token, value pairs are popped from the top of
the stack so that the original scope can resume processing.
A special case is made for the _KEY token. It represents a temporary
value which only occurs inside mappings. It is immediately popped off
the stack when it’s associated value is encountered in the parse stream.
It is necessary to do this because the YAML parser does not combine
key and value information in to a single event.
- Alias(event, loader)source
Not implemented yet.
Parametersevent – Ignored.
- DocumentEnd(event, loader)source
End of document.
Parametersevent – Ignored.
- DocumentStart(event, loader)source
Build new document.
Pushes new document on to stack.
Parametersevent – Ignored.
- GetResults()source
Get results of document stream processing.
This method can be invoked after fully parsing the entire YAML file
to retrieve constructed contents of YAML file. Called after EndStream.
ReturnsA tuple of all document objects that were parsed from YAML stream.
RaisesInternalError if the builder stack is not empty by the end of parsing.
- MappingEnd(event, loader)source
End of mapping
Parameters
-
event – Ignored.
-
loader – Ignored.
- MappingStart(event, loader)source
Start of mapping scope.
Create a mapping from builder and then handle in the context of its
parent.
Parameters
- Scalar(event, loader)source
Handle scalar value
Since scalars are simple values that are passed directly in by the
parser, handle like any value with no additional processing.
Of course, key values will be handles specially. A key value is recognized
when the top token is _TOKEN_MAPPING.
Parametersevent – Event containing scalar value.
- SequenceEnd(event, loader)source
End of sequence.
Parameters
-
event – Ignored
-
loader – Ignored.
- SequenceStart(event, loader)source
Start of sequence scope
Create a new sequence from the builder and then handle in the context
of its parent.
Parameters
- StreamEnd(event, loader)source
Cleans up internal state of handler after parsing
Parametersevent – Ignored.
- StreamStart(event, loader)source
Initializes internal state of handler
Parametersevent – Ignored.
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-06-16 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-06-16 UTC."],[[["\u003cp\u003eThe \u003ccode\u003egoogle.appengine.api.yaml_builder\u003c/code\u003e module provides tools for constructing structured objects from YAML events using a builder pattern.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eBuilder\u003c/code\u003e class serves as an interface for defining how different YAML constructs (documents, mappings, sequences) are built, allowing custom object creation.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eBuilderHandler\u003c/code\u003e class manages the parsing events from PyYAML, maintains object nesting, and utilizes a \u003ccode\u003eBuilder\u003c/code\u003e instance to construct objects, maintaining internal states and handling different tokens.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eBuilder\u003c/code\u003e methods like \u003ccode\u003eBuildDocument\u003c/code\u003e, \u003ccode\u003eBuildMapping\u003c/code\u003e, and \u003ccode\u003eBuildSequence\u003c/code\u003e are called by \u003ccode\u003eBuilderHandler\u003c/code\u003e to build corresponding YAML components, while \u003ccode\u003eAppendTo\u003c/code\u003e, \u003ccode\u003eMapTo\u003c/code\u003e, \u003ccode\u003eEndMapping\u003c/code\u003e and \u003ccode\u003eEndSequence\u003c/code\u003e are used for refinement and cleanup.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eBuilderHandler\u003c/code\u003e's \u003ccode\u003eGetResults\u003c/code\u003e method retrieves a tuple of all constructed document objects after the entire YAML stream is parsed, providing the final output of the building process.\u003c/p\u003e\n"]]],[],null,["# google.appengine.api.yaml_builder module\n========================================\n\nSummary\n-------\n\nPyYAML event builder handler\n\nReceives events from YAML listener and forwards them to a builder\nobject so that it can construct a properly structured object.\n\nContents\n--------\n\n*class* google.appengine.api.yaml_builder.Builder[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder)\n\n: Bases: object\n\n Interface for building documents and type from YAML events.\n\n Implement this interface to create a new builder. Builders are\n passed to the BuilderHandler and used as a factory and assembler\n for creating concrete representations of YAML files. \n\n AppendTo(subject, value)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder.AppendTo)\n\n : Append value to a sequence representation.\n\n Implementation is defined by sub-class of Builder.\n Parameters\n\n - subject -- Object that represents sequence. Value returned from\n BuildSequence\n\n - value -- Value to be appended to subject. Can be any kind of value.\n\n BuildDocument()[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder.BuildDocument)\n\n : Build new document.\n\n The object built by this method becomes the top level entity\n that the builder handler constructs. The actual type is\n determined by the sub-class of the Builder class and can essentially\n be any type at all. This method is always called when the parser\n encounters the start of a new document.\n Returns\n\n New object instance representing concrete document which is\n returned to user via BuilderHandler.GetResults(). \n\n BuildMapping(top_value)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder.BuildMapping)\n\n : Build a new mapping representation.\n\n Called when StartMapping event received. Type of object is determined\n by Builder sub-class.\n Parameters\n\n top_value -- Object which will be new mappings parant. Will be object\n returned from previous call to BuildMapping or BuildSequence.\n Returns\n\n Instance of new object that represents a mapping type in target model. \n\n BuildSequence(top_value)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder.BuildSequence)\n\n : Build a new sequence representation.\n\n Called when StartSequence event received. Type of object is determined\n by Builder sub-class.\n Parameters\n\n top_value -- Object which will be new sequences parant. Will be object\n returned from previous call to BuildMapping or BuildSequence.\n Returns\n\n Instance of new object that represents a sequence type in target model. \n\n EndMapping(top_value, mapping)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder.EndMapping)\n\n : Previously constructed mapping scope is at an end.\n\n Called when the end of a mapping block is encountered. Useful for\n additional clean up or end of scope validation.\n Parameters\n\n - top_value -- Value which is parent of the mapping.\n\n - mapping -- Mapping which is at the end of its scope.\n\n EndSequence(top_value, sequence)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder.EndSequence)\n\n : Previously constructed sequence scope is at an end.\n\n Called when the end of a sequence block is encountered. Useful for\n additional clean up or end of scope validation.\n Parameters\n\n - top_value -- Value which is parent of the sequence.\n\n - sequence -- Sequence which is at the end of its scope.\n\n InitializeDocument(document, value)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder.InitializeDocument)\n\n : Initialize document with value from top level of document.\n\n This method is called when the root document element is encountered at\n the top level of a YAML document. It should get called immediately\n after BuildDocument.\n\n Receiving the None value indicates the empty document.\n Parameters\n\n - document -- Document as constructed in BuildDocument.\n\n - value -- Scalar value to initialize the document with.\n\n MapTo(subject, key, value)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#Builder.MapTo)\n\n : Map value to a mapping representation.\n\n Implementation is defined by sub-class of Builder.\n Parameters\n\n - subject -- Object that represents mapping. Value returned from\n BuildMapping.\n\n - key -- Key used to map value to subject. Can be any scalar value.\n\n - value -- Value which is mapped to subject. Can be any kind of value.\n\n*class* google.appengine.api.yaml_builder.BuilderHandler(builder)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler)\n\n: Bases: [google.appengine.api.yaml_listener.EventHandler](/appengine/docs/legacy/standard/python/refdocs/google.appengine.api.yaml_listener#google.appengine.api.yaml_listener.EventHandler)\n\n PyYAML event handler used to build objects.\n\n Maintains state information as it receives parse events so that object\n nesting is maintained. Uses provided builder object to construct and\n assemble objects as it goes.\n\n As it receives events from the YAML parser, it builds a stack of data\n representing structural tokens. As the scope of documents, mappings\n and sequences end, those token, value pairs are popped from the top of\n the stack so that the original scope can resume processing.\n\n A special case is made for the _KEY token. It represents a temporary\n value which only occurs inside mappings. It is immediately popped off\n the stack when it's associated value is encountered in the parse stream.\n It is necessary to do this because the YAML parser does not combine\n key and value information in to a single event. \n\n Alias(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.Alias)\n\n : Not implemented yet.\n\n Parameters\n\n event -- Ignored. \n\n DocumentEnd(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.DocumentEnd)\n\n : End of document.\n\n Parameters\n\n event -- Ignored. \n\n DocumentStart(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.DocumentStart)\n\n : Build new document.\n\n Pushes new document on to stack.\n Parameters\n\n event -- Ignored. \n\n GetResults()[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.GetResults)\n\n : Get results of document stream processing.\n\n This method can be invoked after fully parsing the entire YAML file\n to retrieve constructed contents of YAML file. Called after EndStream.\n Returns\n\n A tuple of all document objects that were parsed from YAML stream.\n Raises\n\n InternalError if the builder stack is not empty by the end of parsing. \n\n MappingEnd(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.MappingEnd)\n\n : End of mapping\n\n Parameters\n\n - event -- Ignored.\n\n - loader -- Ignored.\n\n MappingStart(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.MappingStart)\n\n : Start of mapping scope.\n\n Create a mapping from builder and then handle in the context of its\n parent.\n Parameters\n\n - event -- MappingStartEvent generated by loader.\n\n - loader -- Loader that generated event.\n\n Scalar(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.Scalar)\n\n : Handle scalar value\n\n Since scalars are simple values that are passed directly in by the\n parser, handle like any value with no additional processing.\n\n Of course, key values will be handles specially. A key value is recognized\n when the top token is _TOKEN_MAPPING.\n Parameters\n\n event -- Event containing scalar value. \n\n SequenceEnd(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.SequenceEnd)\n\n : End of sequence.\n\n Parameters\n\n - event -- Ignored\n\n - loader -- Ignored.\n\n SequenceStart(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.SequenceStart)\n\n : Start of sequence scope\n\n Create a new sequence from the builder and then handle in the context\n of its parent.\n Parameters\n\n - event -- SequenceStartEvent generated by loader.\n\n - loader -- Loader that generated event.\n\n StreamEnd(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.StreamEnd)\n\n : Cleans up internal state of handler after parsing\n\n Parameters\n\n event -- Ignored. \n\n StreamStart(event, loader)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/yaml_builder#BuilderHandler.StreamStart)\n\n : Initializes internal state of handler\n\n Parameters\n\n event -- Ignored."]]