Skip to content

Support passing a custom transport to the httpx client (#615) - #659

Merged
martin-majlis merged 2 commits into
masterfrom
support-custom-transport-615
Sep 4, 2026
Merged

martin-majlis merged 2 commits into
masterfrom
support-custom-transport-615

Conversation

@martin-majlis

Copy link
Copy Markdown
Owner

Summary

Closes #615.

Callers can now pass a custom httpx transport to Wikipedia / AsyncWikipedia, enabling caching transports such as Hishel.

Previously both clients hardcoded transport=httpx.HTTPTransport() after **self._client_kwargs, so passing transport=... raised TypeError: got multiple values for keyword argument 'transport'. The default transport is now injected via setdefault (mirroring the existing timeout default), so a caller-supplied transport is honoured and the correct default (httpx.HTTPTransport / httpx.AsyncHTTPTransport) applies when none is given.

import hishel, httpx, wikipediaapi

wiki = wikipediaapi.Wikipedia(
    user_agent="MyProject/1.0 (contact@example.com)",
    language="en",
    transport=hishel.CacheTransport(transport=httpx.HTTPTransport()),
)

Changes

  • sync_http_client.py / async_http_client.py: inject default transport only when the caller didn't supply one.
  • Docstrings (base_http_client.py, wikipedia.py, async_wikipedia.py) mention the transport kwarg.
  • README.rst (and index.rst, a symlink): new "Custom HTTP Transport" section; DESIGN.rst notes.
  • CHANGES.rst: Unreleased entry.
  • Tests: custom-transport-used and default-transport-when-absent, sync + async.

Verification

  • Full suite: 899 passed, 3 skipped, 94% coverage.
  • make run-ruff, make run-type-check, make run-pre-commit: all pass.
  • End-to-end sanity via httpx.MockTransport: sync and async page summaries served through the custom transport with no network.

🤖 Generated with Claude Code

martin-majlis and others added 2 commits September 4, 2026 06:59
The sync and async HTTP clients hardcoded transport=httpx.HTTPTransport()
after **self._client_kwargs, so passing transport=... raised
TypeError: got multiple values for keyword argument 'transport'. This
blocked using caching transports like Hishel.

Now the default transport is injected via setdefault (mirroring the
existing timeout default), so a caller-supplied transport is honoured
and the correct default applies when none is given.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUJyTApfnoWm4Gq8yBgds7
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HUJyTApfnoWm4Gq8yBgds7
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.04%. Comparing base (deb98f6) to head (9a741bd).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #659   +/-   ##
=======================================
  Coverage   94.04%   94.04%           
=======================================
  Files          76       76           
  Lines        3373     3375    +2     
=======================================
+ Hits         3172     3174    +2     
  Misses        201      201           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martin-majlis
martin-majlis merged commit a8b1336 into master Sep 4, 2026
43 checks passed
@martin-majlis
martin-majlis deleted the support-custom-transport-615 branch September 4, 2026 05:57
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.

Support passing transport to underly httpx client so caching transports can be used

1 participant