Skip to content

Replace requests with httpx2 and add an asynchronous client - #635

Open
wendigo wants to merge 1 commit into
masterfrom
user/serafin/httpx2
Open

Replace requests with httpx2 and add an asynchronous client#635
wendigo wants to merge 1 commit into
masterfrom
user/serafin/httpx2

Conversation

@wendigo

@wendigo wendigo commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Migrate the HTTP stack from requests to httpx2, with HTTP/2 negotiated via ALPN on TLS connections and transparent HTTP/1.1 fallback.

  • Extract the transport-agnostic protocol logic (headers, response processing, retry decisions, session state, segment decoding) into trino/_protocol.py, shared by the sync and async clients.
  • Rework trino.auth: Authentication now contributes get_http_auth() and get_client_arguments() since verify/cert/trust_env are constructor-only in httpx; OAuth2 is an httpx2.Auth generator flow working for both sync and async clients; Kerberos/GSSAPI use an in-repo SPNEGO flow on python-gssapi (trino/_spnego.py) instead of requests_kerberos and requests_gssapi.
  • Add trino.aio, an asynchronous DBAPI-like interface on httpx2.AsyncClient with spooled protocol support (async segment downloads, heartbeat task, acknowledgment tasks drained on close).
  • Replace httpretty with a hand-written recording MockTrinoServer over httpx2.MockTransport serving sync and async unit tests alike.

Description

Non-technical explanation

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

* Fix some things. ({issue}`issuenumber`)

@cla-bot cla-bot Bot added the cla-signed label Aug 31, 2026
Migrate the HTTP stack from requests to httpx2, with HTTP/2 negotiated
via ALPN on TLS connections and transparent HTTP/1.1 fallback.

- Extract the transport-agnostic protocol logic (headers, response
  processing, retry decisions, session state, segment decoding) into
  trino/_protocol.py, shared by the sync and async clients.
- Rework trino.auth: Authentication now contributes get_http_auth() and
  get_client_arguments() since verify/cert/trust_env are constructor-only
  in httpx; OAuth2 is an httpx2.Auth generator flow working for both sync
  and async clients; Kerberos/GSSAPI use an in-repo SPNEGO flow on
  python-gssapi (trino/_spnego.py) instead of requests_kerberos and
  requests_gssapi.
- Add trino.aio, an asynchronous DBAPI-like interface on
  httpx2.AsyncClient with spooled protocol support (async segment
  downloads, heartbeat task, acknowledgment tasks drained on close).
- Replace httpretty with a hand-written recording MockTrinoServer over
  httpx2.MockTransport serving sync and async unit tests alike.
@wendigo
wendigo force-pushed the user/serafin/httpx2 branch from 5a3d9b2 to dee8b39 Compare August 31, 2026 16:32
@wendigo

wendigo commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Thoughts @hashhar @azawlocki-sbdt ?

@azawlocki-sbdt

Copy link
Copy Markdown
Contributor

@wendigo, I see three commits here (requests -> httpx2, refactor to _protocol.py, async API), not just a single one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants