DRAFT - Use httpx as the transport#1046
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 344 |
| Duplication | 84 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1046 +/- ##
==========================================
- Coverage 94.79% 94.28% -0.51%
==========================================
Files 7 9 +2
Lines 807 1155 +348
==========================================
+ Hits 765 1089 +324
- Misses 42 66 +24 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Andy-Grigg
left a comment
There was a problem hiding this comment.
No major concerns. Various comments, some specific, some general.
| Examples | ||
| -------- | ||
| >>> client = ApiClient(requests.Session(), | ||
| >>> transport = httpx.MockTransport(lambda request: httpx.Response(200)) |
There was a problem hiding this comment.
Similar question here about the intended audience for the example here. Although again, I suppose this is on the 'generic' ApiClient class.
But even then, would the user be expected to instantiate their own transport class, or would we expect the PyGranta package (or bindings) to do that automatically?
| response_type_map, | ||
| ) | ||
|
|
||
| @staticmethod |
There was a problem hiding this comment.
There's a lot of what looks like boilerplate here. Is this just httpx doing less hand-holding than requests?
There was a problem hiding this comment.
Not really, its more that requests exposes a very permissive API and handles it, it's very "python 2.x" whereas httpx has more type requirements. This just ensures that we translate the old requests style arguments into new httpx style ones (bytes for content)
| def _url_with_query_string(url: str, query_params: Optional[str]) -> str: | ||
| if not query_params: | ||
| return url | ||
| return f"{url}&{query_params}" if "?" in url else f"{url}?{query_params}" |
There was a problem hiding this comment.
This is kind of odd. What problem is being solved here?
There was a problem hiding this comment.
This handles merging the url with query parameters - if the user provides a base url that already has query parameters we need to merge them, this is actually quite a bad solution - I will do something better...
Move the explicit doc/_build/ rule next to Sphinx-related comments so local html/latex output stays ignored; keep _autosummary documented separately. Co-authored-by: Cursor <cursoragent@cursor.com>
Vendor Requests-style CaseInsensitiveDict (Apache-2.0 attribution) for session headers and exception snapshots. Export CaseInsensitiveDict from the public package. Restrict ApiException / ApiClientBase signatures to httpx.Response. Co-authored-by: Cursor <cursoragent@cursor.com>
Introduce urllib3-style retries on a custom httpx.HTTPTransport. Wire TransportConfiguration into httpx.Client construction, WWW-Authenticate collection via httpx.Headers.get_list, and drop the old requests session shims from utilities. Co-authored-by: Cursor <cursoragent@cursor.com>
Require httpx.Client for ApiClient.request paths and deserialization. Rebuild ApiClientFactory on httpx with platform auth (NTLM, Negotiate, OIDC) and fix probe URL handling. Port OIDCSessionFactory to httpx-auth and typed TransportConfiguration round-trips. Co-authored-by: Cursor <cursoragent@cursor.com>
Replace requests-mock with pytest-httpx; align dispatch and multipart tests with httpx.Client.request. Update session, OIDC, exception, and integration tests for httpx responses and factory behaviour. Add retry transport unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
Remove the requests stack from core dependencies; refresh the lockfile. Add per-module mypy overrides so Windows CI passes without per-import ignores when optional httpx auth extras are present or absent. Co-authored-by: Cursor <cursoragent@cursor.com>
Link the engineering plan from the doc toctree; record vendoring, test strategy, and phased rollout decisions. Co-authored-by: Cursor <cursoragent@cursor.com>
…ctory session headers Updated documentation to specify that the headers in `idp_session_configuration` are not fully respected for IdP HTTP clients, particularly regarding the `Accept` and `Content-Type` headers. Added a test to ensure that the initial probe to the API uses only the factory's session headers, confirming the expected behavior of the `ApiClientFactory`.
Generated clients always used the default; the flag was wired incorrectly to streaming for requests. call_api now always deserializes and raises ApiException with a parsed exception model on error. request() no longer accepts _preload_content. Add brief docstrings on context manager methods for pydocstyle. Co-authored-by: Cursor <cursoragent@cursor.com>
Use a single optional outbound proxy URL and route it through one httpx mount keyed by the API (or IdP) scheme from mount_scheme_url. ApiClientFactory passes api_url; OIDC passes authority or resource URL. Remove per-scheme dict handling and NotImplementedError paths from client init kwargs. Update tests and user guide. Co-authored-by: Cursor <cursoragent@cursor.com>
- Add .valeignore for Sphinx _build and api/_autosummary output. - Extend ANSYS Vale accept list (httpx, certifi, conda, OpenSSL). - Reword user guide HTTPS/session section for Google rules and spacing. - Fix RetryingHTTPTransport docstrings (numpy style, handle_request). - Split pydocstyle pre-commit: skip D105/D102 on vendored CaseInsensitiveDict. Co-authored-by: Cursor <cursoragent@cursor.com>
…F401 - Remove httpx from intersphinx_mapping (no Sphinx objects.inv on MkDocs site). - Reorder ApiClient class docstring to Parameters, Notes, Examples (GL07). - Remove unused typing.Any import in _exceptions.py. Co-authored-by: Cursor <cursoragent@cursor.com>
Expose AsyncApiClient from the public package, wire async request paths through the existing client stack, and align retry transport and session utilities with async-capable httpx usage. Add unit tests for the async client surface and updated retry behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
Factor Uvicorn apps into fixture_apps with shared /models routes, add server_utils and async_integration helpers, and extend basic, anonymous, and negotiate suites with parametrized GET/POST/PUT/DELETE/HEAD/OPTIONS checks alongside existing PATCH coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
- Added tests to ensure AsyncApiClient correctly rejects sync clients and handles async client closure. - Implemented tests for OIDCSessionFactory to verify audience header handling in API and IDP configurations. - Included checks for proper error handling when invalid HTTP clients are used. Co-authored-by: Cursor <cursoragent@cursor.com>
In Progress