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
| Resource | Link |
|---|---|
| Previous | Controlling cost |
| Next | Azure SQL |
| Prerequisites | az3 |
| Time | ~55 minutes |
What you will learn
By the end of this lesson you will be able to:
- Parse a blob URL into account, container, and blob path.
- Contrast flat blob names with a hierarchical Data Lake path.
- Upload and read a small CSV using a local stand-in of container/blob (no live account).
- Refuse a public container for customer data.
- Stop the storage meter by deleting the account or the resource group.
- 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)
- Resource group → Create → search Storage account.
- Basics: subscription, group, unique account name, region, performance, redundancy. Open Tags (
owner,purpose,stop-after). - Advanced: Enable hierarchical namespace if this is a lake. Leave it off for a simple blob drop.
- After create: Containers → + Container. Then Upload a file, or use Storage browser.
- Networking / Anonymous access: keep public access disabled for customer files.
- 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.csvDemo 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 NoneExpected output:
None
ordersDemo 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) == 21Expected output:
2
Bengaluru
21Guided 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-allowsIndependent 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.csvCommon mistake
The deliberate mistake
Symptom:
orders/2026-09-23.csvcannot 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
- Blob REST host:
{account}.blob.core.windows.net. Data Lake Gen2 DFS host:{account}.dfs.core.windows.net(Azure Storage docs). - Hierarchical namespace is a create-time setting on the storage account (can be enabled later in some cases — confirm current portal behaviour before you depend on a conversion).
- Free-account storage amounts (capacity and redundancy SKUs) belong on Microsoft's free-services list and change. Do not hard-code a GB figure in the body.
- Soft delete, versioning, and lifecycle rules add options — and can keep data (and some cost) after a "delete." Check the account's data protection blade before you assume teardown is instant.
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.