Apache Beam is an open-source, unified programming model for defining and executing data processing pipelines for both batch and streaming data. It offers language-specific SDKs, including Python, to construct pipelines that can run on various distributed processing backends such as Apache Flink, Apache Spark, and Google Cloud Dataflow. The library maintains an active development pace with minor releases approximately every 6 weeks, and its current version is 2.71.0.
Install & Compatibility
Where this runs
tested against v2.74.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.950 runs
build_error
glibcpy 3.10–3.950 runs
installs and imports cleanly · install 29.0s · import 4.257s · 721MB
750MB installed
● package 750MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
beam
✓ import apache_beam as beam
Standard alias for the Apache Beam SDK.
ReadFromText
✓ from apache_beam.io import ReadFromText
WriteToText
✓ from apache_beam.io import WriteToText
PipelineOptions
✓ from apache_beam.options.pipeline_options import PipelineOptions
This classic WordCount example demonstrates basic Apache Beam concepts: reading data from a source (local file or GCS), applying transformations like splitting, mapping, and combining, and writing the results to an output file. Run it locally using the DirectRunner.
import re
import argparse
import apache_beam as beam
from apache_beam.io import ReadFromText, WriteToText
from apache_beam.options.pipeline_options import PipelineOptions
def main(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument(
'--input',
dest='input',
default='gs://dataflow-samples/shakespeare/kinglear.txt',
help='Input file to process.')
parser.add_argument(
'--output',
dest='output',
default='output.txt',
help='Output file to write results to.')
known_args, pipeline_args = parser.parse_known_args(argv)
pipeline_options = PipelineOptions(pipeline_args)
with beam.Pipeline(options=pipeline_options) as p:
# Read the text file into a PCollection
lines = p | ReadFromText(known_args.input)
# Count the occurrences of each word
counts = (
lines
| 'Split' >> beam.FlatMap(lambda x: re.findall(r'[A-Za-z\']+', x))
| 'PairWithOne' >> beam.Map(lambda x: (x, 1))
| 'GroupAndSum' >> beam.CombinePerKey(sum)
)
# Format the counts into strings
output = counts | 'Format' >> beam.Map(
lambda word_count: '%s: %s' % (word_count[0], word_count[1]))
# Write the output
output | WriteToText(known_args.output)
if __name__ == '__main__':
print("Running Beam WordCount pipeline locally...")
main()
print("Pipeline finished. Check 'output.txt' for results.")
beam --version
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'apache_beam'
This error occurs when the Apache Beam library is not installed in the Python environment.
fixInstall Apache Beam using pip: `pip install apache-beam`.
ImportError: cannot import name 'coder_impl'
This error arises due to an internal import issue within the Apache Beam library, often related to version mismatches or installation problems.
fixEnsure that Apache Beam is correctly installed and up to date: `pip install --upgrade apache-beam`.
Total size of the BoundedSource objects returned by BoundedSource.split() operation is larger than the allowable limit
This error occurs when attempting to process a very large number of files in a single pipeline, exceeding the system's allowable limit.
fixReduce the number of files processed in a single pipeline or split the processing into smaller batches.
OSError: Invalid data stream
This error happens when the pipeline encounters a malformed or corrupted file during processing.
fixImplement error handling mechanisms to skip or log bad records, such as using try-except blocks around file reading operations.
NameError: name 'parse_into_dict' is not defined
This error occurs when a function or variable is referenced before it has been defined or imported.
fixEnsure that all functions and variables are properly defined and imported before they are used in the code.
Audit
Dependencies
pythonrequiredApache Beam 2.71.0 requires Python 3.10 or later.
apache-beam[gcp]optionalIncludes dependencies for Google Cloud Dataflow Runner, GCS IO, BigQuery IO, etc.
apache-beam[interactive]optionalIncludes dependencies for interactive pipeline development (e.g., in notebooks).
apache-beam[tfrecord]optionalIncludes dependencies for TFRecord I/O operations.