intermediatePython Framework • Core Concepts

Working with External Data

Join 1.2k+ learners

JSON: The Language of APIs

JSON (JavaScript Object Notation) is the de-facto standard for web data. Python's `json` module makes it trivial to convert strings to dicts (`json.loads`) and dicts to strings (`json.dumps`).

Python
import json data = '{"name": "Alice", "score": 99}' user = json.loads(data) print(user['name']) # Alice print(json.dumps(user, indent=2)) # Pretty printing

Working with CSVs

CSV (Comma Separated Values) files are the bread and butter of data science. The `csv` module handles reading and writing rows correctly, managing quoting and special characters automatically.

Python
import csv with open('data.csv', 'w', newline='') as f: writer = csv.writer(f) writer.writerow(['Name', 'Role']) writer.writerow(['Bob', 'Builder'])

APIs & HTTP Methods

APIs (Application Programming Interfaces) allow code to talk to code. We interaction via HTTP methods: • **GET**: Retrieve data (like reading a webpage). • **POST**: Send new data (like submitting a form). • **PUT/PATCH**: Update existing data. • **DELETE**: Remove data. Combined, these form right **CRUD** (Create, Read, Update, Delete) cycle.

Python
# Conceptual Request requests.post('https://api.app.com/users', json={'name': 'Dave'}) # Returns 201 Created requests.get('https://api.app.com/users/1') # Returns 200 OK + {'id': 1, 'name': 'Dave'}

Request & Response Anatomy

Every interaction involves a **Request** (Headers, Body, Method) and a **Response** (Status Code, Body). **Common Status Codes:** • `200 OK`: Success • `201 Created`: Resource made • `400 Bad Request`: You messed up • `401 Unauthorized`: Who are you? • `404 Not Found`: It's not there • `500 Server Error`: They messed up

Python
import urllib.request import json url = 'https://jsonplaceholder.typicode.com/todos/1' with urllib.request.urlopen(url) as response: if response.status == 200: data = json.loads(response.read()) print(f"Task: {data['title']}")

Master this concept

Hands-on practice is the fastest way to learn. Head over to our interactive workspace to solve this topic's challenge.

Launch Editor

Visual Lab

Data ETL Pipeline

API / File
Parse (JSON/CSV)
if
Process Data
Save to DB
Start/End
Condition
Action

New Challenge available!

Master Working with External Data with a hands-on task.