From 848459120508dce863b64136cafde8c2c10fbf7e Mon Sep 17 00:00:00 2001 From: Qunfei Wu Date: Wed, 25 Feb 2026 22:14:21 +0100 Subject: [PATCH 1/2] fix the format --- CLAUDE.md | 6 +++--- tests_requestx/test_sdk_compatibility.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index cfc825b..a3a2278 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -5,7 +5,7 @@ High-performance Python HTTP client, API-compatible with httpx, powered by Rust' ## Features - **httpx API compatibility** — Drop-in replacement: `import requestx as httpx` works -- **AI SDK compatible** — Works with OpenAI, Anthropic SDKs via `http_client=requestx.Client()` +- **AI SDK compatible** — Works with OpenAI, Anthropic SDKs via `http_client=requestx.Client()` or `AsyncClient` - **High performance** — Rust-powered with GIL-free I/O, SIMD JSON (sonic-rs), zero-copy bytes - **Full async support** — Tokio runtime for true concurrent multiplexing - **Standards compliant** — WHATWG URL, RFC 2388 (multipart), RFC 7616 (digest auth), HTTP/2 @@ -189,9 +189,9 @@ let mut headers = Vec::with_capacity(response.headers().len()); ``` ### 7. SDK Compatibility -- requestx patches `type.__instancecheck__` at import to pass httpx.Client isinstance checks +- requestx patches `builtins.isinstance` at import to pass httpx.Client isinstance checks - This enables AI SDK compatibility (OpenAI, Anthropic accept requestx.Client) -- Patch is global but detection is narrow (class + module name matching) +- Patch is global but detection is narrow (checks `__name__` == "Client"/"AsyncClient" and `__module__` starts with "requestx") ## Don't diff --git a/tests_requestx/test_sdk_compatibility.py b/tests_requestx/test_sdk_compatibility.py index ba36508..848d639 100644 --- a/tests_requestx/test_sdk_compatibility.py +++ b/tests_requestx/test_sdk_compatibility.py @@ -52,7 +52,7 @@ def test_openai_sdk_accepts_requestx_client(self): # OpenAI SDK checks isinstance(http_client, httpx.Client) # This should not raise TypeError try: - openai_client = OpenAI(api_key="test-key", http_client=client) + OpenAI(api_key="test-key", http_client=client) except TypeError as e: pytest.fail(f"OpenAI SDK rejected requestx.Client: {e}") @@ -66,7 +66,7 @@ def test_openai_async_sdk_accepts_requestx_async_client(self): # OpenAI SDK checks isinstance(http_client, httpx.AsyncClient) # This should not raise TypeError try: - openai_client = AsyncOpenAI(api_key="test-key", http_client=client) + AsyncOpenAI(api_key="test-key", http_client=client) except TypeError as e: pytest.fail(f"AsyncOpenAI SDK rejected requestx.AsyncClient: {e}") @@ -84,7 +84,7 @@ def test_anthropic_sdk_accepts_requestx_client(self): # Anthropic SDK checks isinstance(http_client, httpx.Client) # This should not raise TypeError try: - anthropic_client = Anthropic(api_key="test-key", http_client=client) + Anthropic(api_key="test-key", http_client=client) except TypeError as e: pytest.fail(f"Anthropic SDK rejected requestx.Client: {e}") @@ -98,6 +98,6 @@ def test_anthropic_async_sdk_accepts_requestx_async_client(self): # Anthropic SDK checks isinstance(http_client, httpx.AsyncClient) # This should not raise TypeError try: - anthropic_client = AsyncAnthropic(api_key="test-key", http_client=client) + AsyncAnthropic(api_key="test-key", http_client=client) except TypeError as e: pytest.fail(f"AsyncAnthropic SDK rejected requestx.AsyncClient: {e}") From 2a6b3442c3cb2f245eaa8212f7e23d144bfe945f Mon Sep 17 00:00:00 2001 From: Qunfei Wu Date: Sat, 28 Feb 2026 11:42:32 +0100 Subject: [PATCH 2/2] Adding the goal --- python/requestx/_client.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/requestx/_client.py b/python/requestx/_client.py index 3c39038..526ddbd 100644 --- a/python/requestx/_client.py +++ b/python/requestx/_client.py @@ -352,7 +352,15 @@ def build_request(self, method, url, **kwargs): else: kwargs["params"] = self._params - rust_request = self._client.build_request(method, merged_url, **kwargs) + # Filter to only parameters supported by Rust build_request + # Rust signature: (method, url, *, content=None, data=None, files=None, json=None, params=None, headers=None, cookies=None) + # Note: timeout and extensions are httpx API parameters but not supported by Rust + supported_kwargs = {} + for key in ["content", "data", "files", "json", "params", "headers", "cookies"]: + if key in kwargs and kwargs[key] is not None: + supported_kwargs[key] = kwargs[key] + + rust_request = self._client.build_request(method, merged_url, **supported_kwargs) # Create a wrapper that delegates to the Rust request but has our headers proxy wrapped = _WrappedRequest(rust_request, sync_stream=sync_stream) # Link the stream back to the owner for consumption tracking