Feat: Add Pythonic Pipeline pattern using functional composition by marcoscoladev · Pull Request #461 · faif/python-patterns
Summary
This PR adds a Pythonic implementation of the Pipeline (Functional Pipeline) pattern to the repository.
The example demonstrates how sequential data processing can be composed using callables, iterables, and generators, instead of class-heavy or framework-style abstractions. The goal is to provide a clear, minimal reference that aligns with common Python idioms.
Motivation
While the repository includes many classic GoF and architectural patterns, it did not previously contain a dedicated example of the Pipeline pattern, which is widely used in Python for:
- data processing and ETL workflows
- generator-based stream transformations
- middleware-style request/response chains
Adding this pattern fills a practical gap and reflects how Python developers commonly structure such flows.
Files Changed
Added
-
patterns/behavioral/pipeline.py
Adds a Pythonic implementation of the Pipeline (Functional Pipeline) pattern,
including a short TL;DR, minimal implementation, and runnable example. -
tests/test_pipeline.py
Adds a small test to verify pipeline composition and behavior.
Changed
README.md
Addspipelineto the list of behavioral patterns.
Design & Implementation
The implementation focuses on simplicity and readability:
- Each pipeline stage is a callable transforming an
Iterableinto anotherIterable - Generator-based stages enable lazy evaluation and efficient processing
- A small
composehelper connects stages left-to-right - A lightweight
Pipelinewrapper is included for convenience without introducing complex abstractions - The module contains a short TL;DR and a runnable example
Example
The included demonstration builds a pipeline that:
- filters even numbers
- squares them
- takes the first three results
This illustrates how small, reusable stages can be combined into a readable data flow.
Testing
The behavior was verified by running the example included in the module.
Doc
Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=191372963