{"library":"unidiff","code":"import urllib.request\nfrom unidiff import PatchSet\n\n# Example: Parse a diff from a GitHub pull request URL\ndiff_url = 'https://github.com/matiasb/python-unidiff/pull/3.diff'\nwith urllib.request.urlopen(diff_url) as response:\n    diff_data = response.read()\n    encoding = response.headers.get_content_charset() or 'utf-8'\n    patch = PatchSet(diff_data.decode(encoding))\n\nprint(f\"Parsed {len(patch)} files in the diff.\")\nfor patched_file in patch:\n    print(f\"File: {patched_file.path}\")\n    print(f\"  Added: {patched_file.added} lines, Removed: {patched_file.removed} lines\")\n    for hunk in patched_file:\n        for line in hunk:\n            if line.is_added:\n                print(f\"    + {line.value.strip()}\")\n            elif line.is_removed:\n                print(f\"    - {line.value.strip()}\")","lang":"python","description":"This quickstart demonstrates how to fetch a diff from a URL and parse it using `PatchSet`. It then iterates through the patched files and their hunks to display added and removed lines. `PatchSet` can also be instantiated from a file-like object or directly from a string.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}