Rana Maninder Singh
Lesson 4 of 8Microsoft Azure for Data & AI

Storage: Blob and Data Lake basics

Lesson opener

In one line: Azure Blob is object storage (container + blob name); Data Lake Gen2 is the same account with a hierarchical namespace so folders are real.

Why it matters: A Pune warehouse dump that lands in the wrong container, or is parsed as a local path, never reaches the notebook — and a hot account left online still meters.

Before this lesson: Controlling cost.

Before you start

ResourceLink
PreviousControlling cost
NextAzure SQL
Prerequisitesaz3
Time~55 minutes

What you will learn

By the end of this lesson you will be able to:

  1. Parse a blob URL into account, container, and blob path.
  2. Contrast flat blob names with a hierarchical Data Lake path.
  3. Upload and read a small CSV using a local stand-in of container/blob (no live account).
  4. Refuse a public container for customer data.
  5. Stop the storage meter by deleting the account or the resource group.
  6. Walk the portal create path for a storage account in text.

Blob vs Data Lake (Gen2)

Blob Storage stores objects. The address is storage account → container → blob name. A blob name can contain slashes (orders/2026-09-23.csv) but those slashes are part of the name unless hierarchical namespace is on.

Azure Data Lake Storage Gen2 is a storage account with hierarchical namespace. Folders can be renamed and access-controlled like directories. Analytics engines prefer that shape.

WHY Path bugs and ACL bugs are different. Flat names do not make orders/ a folder.

WHEN Lake-style analytics and fine-grained directory ACLs → Gen2. Simple object drop from an app → blob is enough.

Cost. A storage account starts a small meter as soon as it exists (capacity, operations, egress). Delete the storage account or its resource group to stop it. Soft-delete and reserved names can delay reuse of the account name; that is not "still paying for TB." Public anonymous access is a data leak, not a discount.

Portal click-path (text only)

  1. Resource group → Create → search Storage account.
  2. Basics: subscription, group, unique account name, region, performance, redundancy. Open Tags (owner, purpose, stop-after).
  3. Advanced: Enable hierarchical namespace if this is a lake. Leave it off for a simple blob drop.
  4. After create: Containers → + Container. Then Upload a file, or use Storage browser.
  5. Networking / Anonymous access: keep public access disabled for customer files.
  6. Teardown: delete the storage account, or delete the group.

This lesson's Python does not call Azure. It teaches the path shape so a later SDK call has the right strings.

Demo 1 — Parse a blob URL

Official host shape: {account}.blob.core.windows.net/{container}/{blob}.

from urllib.parse import urlparse

def parse_blob_url(url: str) -> dict:
    parsed = urlparse(url)
    host = parsed.netloc.lower()
    if not host.endswith(".blob.core.windows.net"):
        raise ValueError("not a blob.core.windows.net url")
    account = host.split(".")[0]
    parts = [p for p in parsed.path.split("/") if p]
    if len(parts) < 2:
        raise ValueError("need container and blob")
    return {"account": account, "container": parts[0], "blob": "/".join(parts[1:])}

info = parse_blob_url(
    "https://stchurnlab01.blob.core.windows.net/raw/orders/2026-09-23.csv"
)
print(info["account"])
print(info["container"])
print(info["blob"])
assert info["blob"] == "orders/2026-09-23.csv"

Expected output:

stchurnlab01
raw
orders/2026-09-23.csv

Demo 2 — Flat name vs lake folder

def parent_folder(blob_name: str, hierarchical: bool) -> str | None:
    if "/" not in blob_name:
        return None
    parent = blob_name.rsplit("/", 1)[0]
    return parent if hierarchical else None

print(parent_folder("orders/2026-09-23.csv", False))
print(parent_folder("orders/2026-09-23.csv", True))
assert parent_folder("only.csv", True) is None

Expected output:

None
orders

Demo 3 — Local stand-in: upload and read

import csv
from io import StringIO

containers: dict[str, dict[str, str]] = {"raw": {}}

def upload(container: str, blob: str, text: str) -> None:
    if container not in containers:
        raise KeyError(container)
    containers[container][blob] = text

def read_csv(container: str, blob: str) -> list[dict]:
    text = containers[container][blob]
    return list(csv.DictReader(StringIO(text)))

upload("raw", "tiny.csv", "city,orders\nBengaluru,12\nPune,9\n")
rows = read_csv("raw", "tiny.csv")
print(len(rows))
print(rows[0]["city"])
print(sum(int(r["orders"]) for r in rows))
assert sum(int(r["orders"]) for r in rows) == 21

Expected output:

2
Bengaluru
21

Guided practice: refuse public customer data

def may_set_public(container_purpose: str) -> str:
    if container_purpose == "customer":
        return "refuse-public"
    return "ok-if-policy-allows"

print(may_set_public("customer"))
print(may_set_public("static-website"))
assert may_set_public("customer") == "refuse-public"

Expected output:

refuse-public
ok-if-policy-allows

Independent practice: split a lake path

Deliverable: print account, filesystem (container), and path from an dfs.core.windows.net URL. Same path rules; different host.

from urllib.parse import urlparse

def parse_dfs_url(url: str) -> dict:
    parsed = urlparse(url)
    if not parsed.netloc.lower().endswith(".dfs.core.windows.net"):
        raise ValueError("not a dfs host")
    account = parsed.netloc.split(".")[0]
    parts = [p for p in parsed.path.split("/") if p]
    return {"account": account, "filesystem": parts[0], "path": "/".join(parts[1:])}

out = parse_dfs_url("https://stchurnlab01.dfs.core.windows.net/gold/kpi/daily.csv")
print(out["filesystem"])
print(out["path"])
assert out["account"] == "stchurnlab01"

Expected output:

gold
kpi/daily.csv

Common mistake

The deliberate mistake

Symptom: orders/2026-09-23.csv cannot be listed as a folder; every tool shows one long blob name.

Diagnosis: hierarchical namespace is off. Slashes are characters in the blob name.

Correction: create a new account with hierarchical namespace for lake work, or treat the name as flat.

Prevention: decide blob vs lake on the ticket before Create.

Snapshot — checked September 2026

Where this connects

What you can now do:

  • Parse blob and DFS URLs.
  • Upload and read a tiny CSV in a local container stand-in.
  • Refuse public access for customer files.

Next lesson: Azure SQL. A database is a different meter. Same group, same tags.