Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.
Stay organized with collections Save and categorize content based on your preferences.

google.appengine.api.yaml_listener module


PyYAML event listener

Contains class which interprets YAML events and forwards them to a handler object.


class google.appengine.api.yaml_listener.EventHandlersource

Bases: object

Handler interface for parsing YAML files.

Implement this interface to define specific YAML event handling class. Implementing classes instances are passed to the constructor of EventListener to act as a receiver of YAML parse events.

Alias(event, loader)source

Handle alias event

DocumentEnd(event, loader)source

Handle end of document event

DocumentStart(event, loader)source

Handle start of document event

MappingEnd(event, loader)source

Handle end of mapping event

MappingStart(event, loader)source

Handle start of mapping event

Scalar(event, loader)source

Handle scalar event

SequenceEnd(event, loader)source

Handle end of sequence event

SequenceStart(event, loader)source

Handle start of sequence event

StreamEnd(event, loader)source

Handle end of stream event

StreamStart(event, loader)source

Handle start of stream event

class google.appengine.api.yaml_listener.EventListener(event_handler)source

Bases: object

Helper class to re-map PyYAML events to method calls.

By default, PyYAML generates its events via a Python generator. This class is a helper that iterates over the events from the PyYAML parser and forwards them to a handle class in the form of method calls. For simplicity, the underlying event is forwarded to the handler as a parameter to the call.

This object does not itself produce iterable objects, but is really a mapping to a given handler instance.

Example use:

class PrintDocumentHandler(object):
def DocumentStart(event):

print “A new document has been started”


key1: value1 — key2: value2 ‘’‘

>>> A new document has been started A new document has been started

In the example above, the implemented handler class (PrintDocumentHandler) has a single method which reports each time a new document is started within a YAML file. It is not necessary to subclass the EventListener, merely it receives a PrintDocumentHandler instance. Every time a new document begins, PrintDocumentHandler.DocumentStart is called with the PyYAML event passed in as its parameter..

HandleEvent(event, loader=None)source

Handle individual PyYAML event.


event – Event to forward to method call in method call.


IllegalEvent when receives an unrecognized or unsupported event type.

Parse(stream, loader_class=google.appengine._internal.ruamel.yaml.loader.SafeLoader, **loader_args)source

Call YAML parser to generate and handle all events.

Calls PyYAML parser and sends resulting generator to handle_event method for processing.

  • stream – String document or open file object to process as per the yaml.parse method. Any object that implements a ‘read()’ method which returns a string document will work with the YAML parser.

  • loader_class – Used for dependency injection.

  • **loader_args – Pass to the loader on construction.