Skip to content

Deps cleanup PR 3: Drop httpx and requests from vespa/application.py #1288

Description

@thomasht86

Part of #1285.

Background

We want to minimize pyvespa's runtime dependency surface (see #1285). The httpx → httpr migration is mostly done, but application.py still carries httpx and requests for backwards-compat type hints and exception handling.

Scope

Drop import httpx and import requests from vespa/application.py. This is the most impactful PR in the series — it includes a public API break.

May be split into 3a + 3b during review if it gets heavy:

Part 3a — Remove httpx type-hint shim

  • application.py:38 — drop import httpx
  • application.py:2050 — timeout: Union[httpx.Timeout, int, float] → Union[int, float]. Drop the isinstance(timeout, httpx.Timeout) branch + DeprecationWarning at lines 2141–2147. The deprecation warning has been live a while — check git blame application.py | grep httpx.Timeout to confirm the window
  • application.py:2052 — client: Optional[Union[httpx.AsyncClient, httpr.AsyncClient]] → Optional[httpr.AsyncClient]
  • application.py:325-326, 371-373, 387 — same on the sync get_async_session factory
  • Update docstrings (lines 348–387, 885, 1038, 1051, 1094, 1106) that say httpx.AsyncClient
  • tests/unit/test_application.py:20 — drop import httpx; remove any test constructing httpx.Timeout / httpx.AsyncClient

Part 3b — Remove requests (exceptions + type hints)

  • application.py:14-16 — drop from requests import Session, Response, ConnectionError, HTTPError, JSONDecodeError
  • _is_connection_error (line 71) — requests.ConnectionError is mostly redundant with the builtin ConnectionError plus httpr.RequestError / httpr.ConnectError that the function already checks
  • raise_for_status (line 190) — currently raises requests.HTTPError. Define vespa.exceptions.HTTPError and raise that instead
  • JSONDecodeError — switch to json.JSONDecodeError (stdlib)
  • Session / Response type hints at lines 14-15 are dead weight on a path that returns httpr.Response. Drop or replace with a Protocol
  • Docstrings at lines 426, 1425 mention requests.Session → update to httpr.Client
  • Update the comment at line 207 (# Check if response has raise_for_status method (requests/httpx))

Public API impact

Breaking changes for downstream:

  1. Passing httpx.Timeout to VespaAsync raises TypeError. Mitigation: the DeprecationWarning has been live for a while; remove cleanly and call out in changelog.
  2. Passing httpx.AsyncClient to VespaAsync raises TypeError. Mitigation: require httpr.AsyncClient, call out in changelog.
  3. Catching requests.HTTPError from raise_for_status no longer works. Mitigation: export vespa.exceptions.HTTPError AND keep vespa.exceptions.HTTPError = requests.HTTPError style alias for one release if/while requests is still in dev extras — OR just bump the minor version and call it out.

Recommend: re-export HTTPError from vespa.exceptions with a one-release deprecation alias.

Tasks

  • Part 3a: drop import httpx and all httpx.* type hints
  • Part 3a: update docstrings
  • Part 3a: update tests/unit/test_application.py (drop httpx import + adjust tests)
  • Part 3b: define vespa.exceptions.HTTPError
  • Part 3b: update raise_for_status, _is_connection_error
  • Part 3b: drop from requests ... imports
  • Part 3b: update unit tests (mocks of requests.Response)
  • Add CHANGELOG entry covering the breaking changes
  • Verify: grep -rn 'import httpx\|from httpx\|import requests\|from requests' vespa/ returns no hits

Out of scope

Risk

Medium. The public API break is real but contained. Most users probably already get an httpr.AsyncClient back from app.get_async_session() and don't construct httpx types themselves, but it's worth a release-notes call-out.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions