Skip to content
TeachTrails
Data EngineeringPython

Python for Data Engineers: Why and How to Start

Why data engineers use Python and how to start: installing Python, virtual environments, running scripts, and your first data script, explained simply.

Sukanya Saha, Technology Consultant

8 min read

Beginner friendly

What Python does in a data team

ShopKart's data lives in many places: order CSV files from the app, a payments API, a PostgreSQL database. Every morning someone has to collect it, clean it and load it so analysts can use it. SQL is great inside a database; Python moves data between systems and automates everything around it.

📊 Where Python fits in a pipeline

Extract

Read CSV/JSON files, call REST APIs, query databases

Transform

Clean, validate, de-duplicate, reshape (plain Python or pandas)

Load

Write Parquet, upsert into PostgreSQL or a warehouse

Run & check

Logging, retries, tests, scheduling (Airflow, Databricks jobs)

TaskPython toolLesson
Read and write CSV, JSONcsv, json, pathlib (built in)5
Handle bad data and failurestry/except, logging6
Pull data from APIsrequests7
Clean and reshape tablespandas, Parquet8
Load databasespsycopg (PostgreSQL), sqlite39
Build and test a pipelineargparse, pytest11
Big dataPySpark (see our Databricks course)-

Step 1: Install Python

Download Python 3.12+ from python.org (Windows/macOS) or use your system's package manager. On Windows, tick “Add Python to PATH” during install. Then check it works:

Terminal
$ python --version
Python 3.13.14

On some systems the command is python3 instead of python.

Step 2: Create a project with a virtual environment

Terminal
# a folder for the project
$mkdir shopkart && cd shopkart
# create a virtual environment in .venv
$python -m venv .venv
# activate it (macOS/Linux)
$source .venv/bin/activate
# activate it (Windows PowerShell)
$.venv\Scripts\Activate.ps1
# install the libraries this course uses
$pip install pandas pyarrow requests "psycopg[binary]" pytest
# save exact versions so others get the same setup
$pip freeze > requirements.txt

Step 3: Your first lines of Python

Type python to open the interactive prompt (the REPL), handy for quick experiments:

Python
print("Hello, data engineer!")
Output
Hello, data engineer!

Step 4: Your first data script

Real work lives in .py files. Create first_script.py:

first_script.py
# first_script.py: ShopKart's first data question
daily_sales = [1999, 4999, 1497, 2498]   # one number per order today

total = sum(daily_sales)
average = total / len(daily_sales)

print(f"Orders today: {len(daily_sales)}")
print(f"Total sales: ₹{total:,}")
print(f"Average order: ₹{average:,.2f}")
Terminal
$ python first_script.py
Orders today: 4
Total sales: ₹10,993
Average order: ₹2,748.25
  • # starts a comment: Python ignores it.
  • [ ... ] is a list; sum() and len() are built-in functions.
  • f"...{total:,}" is an f-string: it puts values into text, with a thousands separator. Lesson 2 covers it.
  • Indentation matters in Python: blocks are defined by spaces (4 per level), not braces.

Notebook or script?

Jupyter / Databricks notebook.py script
Best forExploring data, quick chartsPipelines that run every day
TestingHardEasy with pytest
Code review / GitMessy diffsClean diffs
SchedulingPossible (Databricks jobs)Anywhere (cron, Airflow, jobs)

The ShopKart files we'll use

Most lessons work with three small files that are messy on purpose, like real data:

FileWhat's insideProblems hidden in it
data/orders.csv10 ordersLower-case status, extra spaces, a duplicate, a missing customer, quantity 'two'
data/customers.json5 customers with nested contact infonull phone numbers, a null city
data/events.jsonlWebsite events, one JSON per lineDifferent fields per event type

🎯 Interview questions on this topic

Try to answer out loud first, then tap to check.

Q1Why is Python popular for data engineering?Fresher
Readable syntax, a huge ecosystem (requests, pandas, pyarrow, database drivers, PySpark, Airflow), strong community, and it's the language of most orchestration and processing tools. It's fast enough for glue work, and heavy lifting is delegated to engines like Spark or warehouses.
Q2What is a virtual environment and why use it?Fresher
An isolated directory with its own Python packages, so each project has its own dependency versions. It prevents conflicts and makes setups reproducible via requirements.txt or pyproject.toml.
Q3Is Python compiled or interpreted?1–3 yrs
CPython compiles source to bytecode (.pyc), which the Python virtual machine interprets. It's dynamically typed: types are checked at run time, though type hints let tools check them earlier.
Q4How do you make a Python project reproducible?1–3 yrs
Pin dependencies (requirements.txt with exact versions or a lock file via pip-tools/uv/poetry), document the Python version, use a virtual environment, keep config in environment variables, and ideally containerise with Docker.

Key takeaways

  • Python connects the systems in a data pipeline.
  • Set up every project with its own virtual environment.
  • Pipelines live in .py files; notebooks are for exploring.
  • Next: Python's building blocks: numbers, text and None.

Frequently asked questions

Why do data engineers use Python?

Python is easy to read, has libraries for almost every data task (files, APIs, databases, pandas, Spark), and is the main language of tools like Airflow, PySpark and Databricks notebooks. It's the glue that moves data between systems.

Which Python version should I install?

A recent stable version: 3.12 or newer. This course uses Python 3.13. Avoid Python 2; it has been dead since 2020.

What is a virtual environment?

A private folder of packages for one project, so project A can use pandas 2 while project B uses pandas 3 without conflict. Create one with python -m venv .venv and activate it before installing packages.

pip, venv, uv or conda?

pip installs packages and venv creates environments: both come with Python, and this course uses them. uv is a newer, very fast tool that does both. conda is popular in data science. Learn pip + venv first.

Do I need an IDE?

Any editor works. VS Code with the Python extension is the most common free choice; PyCharm is popular too. Jupyter notebooks are great for exploring data, but pipelines live in .py files.

🧠 Quick check: Python for data engineering

  1. 1. What is a virtual environment for?

  2. 2. How do you run a script called load.py?

  3. 3. Where should pipeline code live?

  4. 4. Which is NOT a typical data engineering use of Python?

Python for Data Engineers

Part 1 of 13: Python for Data Engineers