title: Apache Beam Python SDK: How to access timestamp of an element?
body: <p>I'm reading messages via <code>ReadFromPubSub</code> with <code>timestamp_attribute=None</code>, which should set timestamps to the publishing time. </p>
  
  <p>This way, I end up with a <code>PCollection</code> of <code>PubsubMessage</code> elements.</p>
  
  <p>How can I access the timestamps of these element in order, e.g. save them to a database? The only properties I can see are <code>data</code> and <code>attributes</code>, and the <code>attributes</code> only has keys coming from Pub/Sub.</p>
  
  <p>Edit:
  Sample code</p>
  
  <pre><code>with beam.Pipeline(options=pipeline_options) as p:
      items = (p
          | ReadFromPubSub(topic=args.read_topic, with_attributes=True)
          | beam.WindowInto(beam.window.FixedWindows(args.time_window))
          | 'FormatMessage' &gt;&gt; beam.Map(format_message)
          | 'WriteRaw' &gt;&gt; WriteToBigQuery(args.raw_table, args.dataset,
              args.project, write_disposition='WRITE_APPEND')
      )
  </code></pre>
  
  <p>where <code>format_message</code> would take a <code>PubsubMessage</code> and return a dictionary representing a row to append to the table:</p>
  
  <pre><code>def format_message(message):
      formatted_message = {
          'data': base64.b64encode(message.data),
          'attributes': str(message.attributes)
      }
      return formatted_message
  </code></pre>