Pydoc Pydoc

Takes a collection of key-value pairs and returns the key of each element.


In the following example, we create a pipeline with a PCollection of key-value pairs. Then, we apply Keys to extract the keys and discard the values.

import apache_beam as beam

with beam.Pipeline() as pipeline:
  icons = (
      | 'Garden plants' >> beam.Create([
          ('🍓', 'Strawberry'),
          ('🥕', 'Carrot'),
          ('🍆', 'Eggplant'),
          ('🍅', 'Tomato'),
          ('🥔', 'Potato'),
      | 'Keys' >> beam.Keys()
      | beam.Map(print))

Output PCollection after Keys:

Run code now Run code now
View source code View source code

Pydoc Pydoc