Skip to content

refactor: replace requests with httpx#38

Open
isaacbmiller wants to merge 1 commit intomainfrom
isaac/remove-requests
Open

refactor: replace requests with httpx#38
isaacbmiller wants to merge 1 commit intomainfrom
isaac/remove-requests

Conversation

@isaacbmiller
Copy link
Copy Markdown

Summary

Replace requests with httpx across all 7 source files and 1 test file. httpx is already a transitive dependency via openai and litellm, so this adds no new packages while removing requests, urllib3, and charset-normalizer from the dependency tree.

Changes

File Change
dspy/dsp/colbertv2.py requests.get/post -> httpx.get/post
dspy/utils/__init__.py Streaming download: requests.get(stream=True) + iter_content -> httpx.stream('GET') + iter_bytes, allow_redirects -> follow_redirects
dspy/adapters/types/image.py requests.get -> httpx.get
dspy/adapters/types/audio.py requests.get -> httpx.get
dspy/retrievers/databricks_rm.py requests.post -> httpx.post
dspy/clients/databricks.py requests.get/put/post -> httpx.get/put/post, removed no-op json body from GET request
dspy/clients/lm_local.py requests.get -> httpx.get, requests.exceptions.RequestException -> httpx.HTTPError
pyproject.toml requests>=2.31.0 -> httpx>=0.23.0

Notes

  • httpx API is nearly 1:1 with requests for these use cases
  • httpx>=0.23.0 matches openai's own lower bound
  • Net removal: ~783 KB (requests 199KB + urllib3 409KB + charset-normalizer 175KB)

@isaacbmiller isaacbmiller force-pushed the isaac/remove-requests branch from 4dcf7f1 to 43a7735 Compare May 7, 2026 21:42
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 7, 2026

Greptile Summary

Replaces requests with httpx across 7 source files and 2 test files. Since httpx is already a transitive dependency via openai and litellm, this removes requests, urllib3, and charset-normalizer (~783 KB) with no new packages added.

  • All production call sites correctly add follow_redirects=True (addressing the redirect regression noted in earlier review rounds) and the streaming download in utils/__init__.py gains an explicit timeout=300.
  • Three httpx.get() calls in tests/signatures/test_adapter_image.py are missing follow_redirects=True, unlike every other call site in the PR; the test_mime_type_from_response_headers test is the most sensitive because it compares an expected MIME type fetched without redirect-following against encode_image() which does follow redirects.
  • The GET request in clients/databricks.py silently drops the previously-sent json={\"name\": model_name} body; this is likely harmless since the name is in the URL path, but worth confirming against the Databricks API contract.

Confidence Score: 5/5

Safe to merge; all production HTTP call sites are correctly migrated and the previously flagged redirect and timeout gaps have been addressed.

Every source file change is a clean mechanical substitution with follow_redirects=True and appropriate timeouts. The only gaps are three missing follow_redirects=True flags in test helpers and a clarification question about the removed GET JSON body — neither affects production behaviour.

tests/signatures/test_adapter_image.py (missing follow_redirects in three httpx.get calls) and dspy/clients/databricks.py (removed JSON body from GET request)

Important Files Changed

Filename Overview
dspy/clients/lm_local.py Swaps requests.exceptions.RequestException for httpx.HTTPError; correct because ConnectError inherits from RequestError which inherits from HTTPError, so the retry loop still catches connection-refused errors.
dspy/utils/init.py Streaming download migrated to httpx.stream; explicit timeout=300 prevents mid-stream ReadTimeout on large/slow downloads that the previous thread flagged.
dspy/clients/databricks.py All three HTTP calls gain follow_redirects=True; the no-op JSON body was removed from the GET request — confirm Databricks API doesn't read it.
tests/signatures/test_adapter_image.py Three httpx.get() calls are missing follow_redirects=True, unlike all production call sites; could cause test/expected-value mismatch if URLs redirect.
dspy/adapters/types/audio.py Clean swap to httpx.get with follow_redirects=True added, addressing previously flagged regression.
dspy/adapters/types/image.py Clean swap to httpx.get with follow_redirects=True and SSL verify parameter preserved.
dspy/dsp/colbertv2.py Both GET and POST calls migrated cleanly; existing timeout=10 preserved and follow_redirects=True added.
dspy/retrievers/databricks_rm.py Single POST call migrated with follow_redirects=True; no functional changes to error handling or response parsing.
pyproject.toml Swaps requests>=2.31.0 for httpx>=0.23.0, matching OpenAI's own lower bound; no new transitive dependencies added.
tests/retrievers/test_colbertv2.py All four patch targets updated from requests.get/post to httpx.get/post; tests remain correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[HTTP call site] --> B{follow_redirects=True?}
    B -->|YES - all prod files| C[httpx follows 3xx chain]
    B -->|NO - 3 test helpers| D[httpx stops at first 3xx]
    C --> E[raise_for_status and json operate on final response]
    D --> F[raise_for_status passes - 3xx is not an error]
    F --> G[content and headers come from redirect body not target]

    style D fill:#ffe0b2
    style G fill:#ffcccc
Loading

Reviews (4): Last reviewed commit: "refactor: replace requests with httpx" | Re-trigger Greptile

Comment thread dspy/adapters/types/audio.py Outdated
Comment thread dspy/adapters/types/image.py Outdated
Comment thread dspy/dsp/colbertv2.py Outdated
Comment thread dspy/utils/__init__.py Outdated
@isaacbmiller isaacbmiller force-pushed the isaac/remove-requests branch 2 times, most recently from 65b1379 to 589fbbb Compare May 7, 2026 22:03
Comment thread dspy/clients/lm_local.py
httpx is already a transitive dependency via openai and litellm. This
replaces all 7 source files and 1 test file that used requests with
httpx equivalents:

- Simple GET/POST/PUT calls: 1:1 swap
- Streaming download (utils/__init__.py): requests.get(stream=True) +
  iter_content -> httpx.stream('GET') + iter_bytes
- allow_redirects=True -> follow_redirects=True
- requests.exceptions.RequestException -> httpx.HTTPError
- Removed json body from a GET request in databricks.py (no-op)

Removes requests, urllib3, and charset-normalizer from the dep tree.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@isaacbmiller isaacbmiller force-pushed the isaac/remove-requests branch from 589fbbb to 48c489d Compare May 7, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant