Skip to main content
Albero Academy

Project: ETL Pipeline

Extract, transform and load data across CSV/JSON and a database.

Projects15 min

This project mirrors real data-engineering work: a small ETL pipeline that extracts data from a CSV, transforms (cleans and reshapes) it, and loads it into a SQLite database. It ties together files, cleaning, databases and logging.

The three stages

  • Extract — read rows from a CSV (or an API).
  • Transform — clean values, convert types, filter, derive new fields.
  • Load — insert into a SQLite table with parameterised queries.
  • Log progress and skip bad rows without crashing the whole batch.

Pipeline scaffold

etl.py
import csv, sqlite3, logging
logging.basicConfig(level=logging.INFO)
def extract(path):
with open(path, newline="") as f:
yield from csv.DictReader(f) # stream rows lazily
def transform(row):
return {"name": row["name"].strip().title(),
"package": float(row["package"])} # may raise → caught below
def load(rows, db="out.db"):
conn = sqlite3.connect(db)
conn.execute("CREATE TABLE IF NOT EXISTS students(name TEXT, package REAL)")
ok = 0
for row in rows:
try:
clean = transform(row)
except (KeyError, ValueError) as e:
logging.warning("skipping bad row: %s", e)
continue
conn.execute("INSERT INTO students VALUES (?, ?)",
(clean["name"], clean["package"]))
ok += 1
conn.commit(); conn.close()
logging.info("loaded %d rows", ok)
load(extract("students.csv"))

Stretch goals

Add a "de-duplicate" step, make it idempotent (re-runnable without double-inserting), or swap the CSV source for an API extract.

Key takeaways

  1. 01ETL = Extract, Transform, Load — a core data-engineering pattern.
  2. 02Combines files/CSV, cleaning, databases and logging.
  3. 03Stream rows lazily (yield) so large files fit in memory.
  4. 04Parameterised inserts keep the load step safe from injection.
  5. 05Handle bad rows gracefully so one error does not stop the batch.

Finished this chapter?

Mark it complete to track your progress through Python.