The Complete ETLPipeline Class
Advanced · Write the code · from Build a Simple ETL Pipeline: Extract, Transform, Load
From the lesson: Step 7: Build the Complete ETLPipeline Class
Now let's assemble everything into a single ETLPipeline class. A class-based pipeline is easier to configure, test, and rerun. It tracks statistics from each step so you can monitor the pipeline's health.
Read this part of the lessonBuild an ETLPipeline class with these methods:
1. __init__(self) - initializes stats dict: {extracted: 0, validated: 0, errors: 0, transformed: 0, loaded: 0}.
2. extract(self, api_data, csv_data) - combines both sources, updates stats, returns records.
3. validate(self, records) - filters out records with empty name or non-positive amount, updates stats, returns valid records.
4. transform(self, records) - cleans (strip, title case names, lowercase emails) and adds amount_tier, updates stats, returns transformed records.
5. load(self, records) - creates SQLite :memory: db, loads records, stores connection as self.conn, updates stats.
6. run(self, api_data, csv_data) - runs all steps in order, prints a summary report.
Test by running the pipeline with sample data. The summary should print "=== PIPELINE SUMMARY ===" and each stat.
More ETL Pipeline exercises
- Build the Extraction LayerAdvanced
- Data ValidationAdvanced
- Clean and Standardize DataAdvanced
- Enrich Records with Derived FieldsAdvanced
- Load Data into SQLiteAdvanced
- Verify and Analyze Loaded DataAdvanced
All Python exercises · 50 practice problems · Practical Projects quiz