Skip to main content
PCollection
Interactive Syntax Reference
PCollection

Apache Beam Cheatsheet: PCollection

Recommended reading: 3 minsCopy-paste ready Python code snippets

Core Architecture Overview

Understand the core data container, its properties, and state representations.

beam.Create()
returns: PCollection
Purpose & Description

Generates a PCollection from an in-memory iterable (lists, sets, dictionary lists).

Syntax Signaturebeam.Create(iterable)
Executable Example
import apache_beam as beam

with beam.Pipeline() as p:
    elements = p | "Create Elements" >> beam.Create([10, 20, 30])
    elements | beam.Map(print)
Expected Stdout / Output
10
20
30
Time Complexity

O(N) where N is the number of elements in the iterable

Used In

Testing, loading configurations, and quick sandbox runs.

Related Methods

ReadFromText(), ReadFromPubSub()

Pro Tip

Avoid creating very large PCollections using beam.Create since the entire list is held in driver memory.

PCollection Attributes
returns: Data Representation
Purpose & Description

Understanding core immutability, distributed elements, and schemas.

Syntax SignaturePCollection Characteristics (Immutable, Distributed, Bounded/Unbounded)
Executable Example
import apache_beam as beam

# PCollections are immutable; transforms return new collections
inputs = p | beam.Create([1, 2, 3, 4])
evens = inputs | "FilterEvens" >> beam.Filter(lambda x: x % 2 == 0)
Used In

Architecting streaming or batch pipelines.

Common Pitfall

Attempting to modify elements in-place inside user code processes.

Pro Tip

PCollections do not support index lookups or random access. All access must flow through transforms.

More Free Data Engineering Cheatsheets (DataPlayArena Network)Interactive syntax references