← Python Tutorials
HABIBI LAB / PYTHON AUTOMATION

Python automation.
Real-world projects.

Build reliable Python tools for everyday work. Start with five practical projects, then explore new collections covering APIs, data pipelines, reporting, and more as they are published.

05 ready-to-learn projects03 upcoming collections100% practical
# From a repetitive task
input  = "messy_data.xlsx"
task   = "clean + validate"
output = "ready_to_use.xlsx"

# A useful result, not just syntax.
status = "Ready to review ✓"
INPUT → SOLUTION → RESULTLEARNING LIBRARY / PYTHON
01 / AUTOMATION PROJECT LIBRARY

Real projects.
Useful results.

Collection 01: five complete, hands-on projects. Each solves a real problem with readable Python and practical checks. More projects will be added here without changing the existing lessons.

The downloads folder problem

Organize hundreds of files safely

A shared work folder has invoices, photos, reports, and repeated filenames. You need to organize it without accidentally overwriting an important file.

pathlibshutillogging

What you will learn

  • Safe paths and folders
  • classifying files by extension
  • filename collisions
  • dry runs
  • traceable execution

The real-world approach

Start with a small, realistic dataset or folder. Observe the problem, build a working first version, then add checks that make the result trustworthy.

PYTHON / EXAMPLE PREVIEW
from pathlib import Path

source = Path("downloads")
categories = {".pdf": "Documents", ".xlsx": "Spreadsheets",
              ".png": "Images", ".jpg": "Images"}

for file in source.iterdir():
    if not file.is_file():
        continue
    folder = categories.get(file.suffix.lower(), "Other")
    destination = source / folder / file.name
    print(f"PREVIEW: {file.name} -> {destination}")
Why these tools?

Why `pathlib`? It makes path operations readable and works across operating systems. This intentionally previews moves only; the full project adds explicit confirmation, conflict handling, and an activity log before making changes.

Your mini-project

A safe file organizer that previews where files would go before anything is moved.

The inconsistent spreadsheet problem

Clean a messy Excel workbook

You receive a workbook with duplicate IDs, blank values, and numeric fields stored as text. Decisions based on this file will be wrong unless the records are checked.

pandasopenpyxl

What you will learn

  • Loading Excel data
  • preserving text identifiers
  • duplicate review
  • type conversion
  • audit-friendly exports

The real-world approach

Start with a small, realistic dataset or folder. Observe the problem, build a working first version, then add checks that make the result trustworthy.

PYTHON / EXAMPLE PREVIEW
import pandas as pd

source = pd.read_excel("input.xlsx", dtype={"ID": "string"})
required = {"ID", "Amount"}
if missing := required - set(source.columns):
    raise ValueError(f"Missing columns: {sorted(missing)}")

source["ID"] = source["ID"].str.strip()
source["Amount"] = pd.to_numeric(source["Amount"], errors="coerce")
duplicates = source[source.duplicated("ID", keep=False)]
print(f"Rows to review: {len(duplicates)}")
Why these tools?

Why `pandas`? Column-level operations replace repetitive cell-by-cell work. `dtype="string"` helps preserve leading-zero IDs; converting invalid amounts to missing values makes exceptions visible instead of silently inventing numbers.

Your mini-project

A data-cleaning workbook with separate cleaned records, duplicate candidates, and validation findings.

The repeated download problem

Collect reliable data from a public API

A researcher needs fresh economic indicators for several countries. Downloading spreadsheets one by one is slow, error-prone, and hard to reproduce.

requestspandasjson

What you will learn

  • HTTP requests
  • query parameters
  • JSON structures
  • pagination
  • timeout and HTTP error handling
  • recording data sources

The real-world approach

Start with a small, realistic dataset or folder. Observe the problem, build a working first version, then add checks that make the result trustworthy.

PYTHON / EXAMPLE PREVIEW
import requests

url = "https://api.worldbank.org/v2/country/AFG/indicator/SP.POP.TOTL"
response = requests.get(
    url, params={"format": "json", "per_page": 10}, timeout=20
)
response.raise_for_status()
metadata, records = response.json()
for row in (records or []):
    print(row["date"], row["value"])
Why these tools?

Why `requests`? It provides explicit HTTP errors, parameters, and timeouts. This snippet demonstrates the response structure; the complete project adds pagination, retries, response validation, and reproducible exports.

Your mini-project

A reproducible public-data collector that exports a tidy table of World Bank indicators with source metadata.

The manual market-research problem

Turn public web pages into structured research

You need to compare information from multiple publicly accessible listings. Repeated copying into spreadsheets creates inconsistent fields and missing entries.

requestsbeautifulsoup4pandas

What you will learn

  • HTML structure
  • selecting elements
  • parsing text
  • handling missing fields
  • respecting access policies
  • structured comparison

The real-world approach

Start with a small, realistic dataset or folder. Observe the problem, build a working first version, then add checks that make the result trustworthy.

PYTHON / EXAMPLE PREVIEW
from bs4 import BeautifulSoup

html = """<article class='item'>
  <h2>Sample Product</h2><span class='price'>120</span>
</article>"""
soup = BeautifulSoup(html, "html.parser")
items = []
for card in soup.select("article.item"):
    title = card.select_one("h2")
    price = card.select_one(".price")
    if title and price:
        items.append({"name": title.get_text(strip=True),
                      "price": price.get_text(strip=True)})
print(items)
Why these tools?

Why Beautiful Soup? Its CSS selectors make HTML extraction easier to inspect and maintain. Start with a controlled sample. Only access real websites when permitted; follow their terms and published access rules, and prefer official APIs.

Your mini-project

A responsible research extractor built against a permitted practice page or local HTML sample, producing a comparison dataset.

The repetitive reporting problem

Build a dependable monthly reporting workflow

A team combines several Excel reports each month, checks totals, groups transactions, and produces the same management summary again and again.

pandaspathlibopenpyxllogging

What you will learn

  • Batch imports
  • schema validation
  • grouping
  • reconciliation
  • output files
  • observability
  • repeatable runs

The real-world approach

Start with a small, realistic dataset or folder. Observe the problem, build a working first version, then add checks that make the result trustworthy.

PYTHON / EXAMPLE PREVIEW
from pathlib import Path
import pandas as pd

files = sorted(Path("monthly_inputs").glob("*.xlsx"))
if not files:
    raise FileNotFoundError("No monthly workbooks found")

frames = [pd.read_excel(path) for path in files]
required = {"Region", "Amount"}
if any(not required.issubset(frame.columns) for frame in frames):
    raise ValueError("An input workbook has missing columns")

combined = pd.concat(frames, ignore_index=True)
combined["Amount"] = pd.to_numeric(combined["Amount"], errors="raise")
summary = combined.groupby("Region", as_index=False)["Amount"].sum()
summary.to_excel("monthly_summary.xlsx", index=False)
Why these tools?

Why validate before concatenating? Files can contain different columns or invalid values. Checking them early prevents quiet reporting errors. The finished project adds reconciliation, duplicate-run protection, logs, and an exception workbook.

Your mini-project

A one-command reporting assistant that validates inputs and produces a summarized Excel report plus a review log.

02 / EXPANDING COLLECTION

More projects will live here.

The existing five projects are Collection 01. These upcoming collections will be added in the same visual format as each practical tutorial is ready.

COLLECTION 02 / PLANNED

APIs & Integrations

Work with endpoints, authentication, scheduled requests, and useful third-party services.

COLLECTION 03 / PLANNED

Data Pipelines

Design dependable extract, clean, validate, and load workflows for real datasets.

COLLECTION 04 / PLANNED

Reporting Tools

Automate recurring reports, checks, exports, and notifications.

THE HABIBI LAB STANDARD

Next: more useful automation.

This is a growing project library. Future collections will cover API integrations, scheduled workflows, ETL/data pipelines, and other small tools you can build and reuse.

← Python Tutorials