Skip to content

Fix: Replace urllib.request with httpx in SDK hub #515

@kasperjunge

Description

@kasperjunge

httpx is declared as a runtime dependency in pyproject.toml, but agr/sdk/hub.py uses stdlib urllib.request for all GitHub API calls. This creates an inconsistency — the project pays the cost of the httpx dependency without using it in the SDK.

Proposal

Migrate _github_api_request() in agr/sdk/hub.py to use httpx:

# Before (urllib.request)
request = urllib.request.Request(url, headers=headers)
with urllib.request.urlopen(request, timeout=30) as response:
    return json.loads(response.read().decode())

# After (httpx)
response = httpx.get(url, headers=headers, timeout=30)
response.raise_for_status()
return response.json()

Benefits

  • Consistent dependency usage across the project
  • Better error handling and timeout support out of the box
  • Opens the path toward async support (httpx.AsyncClient) for the SDK
  • Simplifies HTTP error code handling (httpx has structured exception types)

Affected files

  • agr/sdk/hub.py_github_api_request() and error handling

Context

Identified in architecture audit: docs/contributing/architecture-audit.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions