Skip to content

Deps cleanup PR 2: Replace requests in vespa/models.py #1287

@thomasht86

Description

@thomasht86

Part of #1285.

Background

We want to minimize pyvespa's runtime dependency surface (see #1285). vespa/models.py is one of the last places in vespa/ still importing requests directly.

Scope

Replace requests usage in vespa/models.py:_validate_single_url so this file no longer needs requests.

Current usage

  • vespa/models.py:8import requests
  • vespa/models.py:276requests.head(url, timeout=10, allow_redirects=True)
  • vespa/models.py:279requests.get(url, timeout=10, stream=True, allow_redirects=True) (fallback when HEAD doesn't return 200)
  • vespa/models.py:287except requests.RequestException

Used to validate user-supplied model_url / tokenizer_url values.

Approach

Recommended: use stdlib urllib.request (one-shot validation, no pooling needed — one fewer thing depending on httpr surface area).

Alternative: use httpr.head / httpr.get (sync API) — fine if httpr is already a runtime dep.

Update the exception handler from requests.RequestException to the new equivalent.

Tasks

  • Replace requests.head / requests.get calls
  • Update exception handling
  • Remove import requests from vespa/models.py
  • Unit test covering: HEAD success, HEAD-fails-then-GET-succeeds, both fail → ValueError
    • Recommend pytest-httpserver or a local socket — don't mock the HTTP library directly
  • Confirm retry behavior still works (function is wrapped in @retry(stop=stop_after_attempt(3), ...))

Out of scope

Risk

Very low. Pure refactor of a validation helper, no public API change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions