Skip to content

refactor(api): share request helpers between the sync and async transports - #223

Closed
he-james wants to merge 1 commit into
masterfrom
jhe/share-request-helpers
Closed

refactor(api): share request helpers between the sync and async transports#223
he-james wants to merge 1 commit into
masterfrom
jhe/share-request-helpers

Conversation

@he-james

@he-jameshe-james commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Extract the pieces that a sync transport and an asyncio transport must share. This PR does not change behavior.

Files changed

FileChange
assemblyai/api.pyStatus checks move into _raise_for_status. New helpers build the request bodies and the query params.
assemblyai/client.pyHeader and pool-limit code move into _build_headers and _build_limits.
assemblyai/transcriber.pyThe response accessors on Transcript move into the new mixin. Net 228 lines removed.
assemblyai/_transcript_fields.pyNew. TranscriptFields mixin and config_from_response.

Why

An asyncio transport would repeat many pieces of code.

  1. Error handling. Each endpoint raises its own exception type with its own message. _raise_for_status holds both, so the two paths cannot diverge.
  2. Client construction. The user-agent, the auth header, and the keepalive limit.
  3. Response accessors.Transcript has 27 properties that read a fetched TranscriptResponse. None of them perform I/O. Both transcript classes can therefore share them. A subclass implements _response().

…ports
Prepare for an asyncio transcriber. This commit does not change behavior.
- api: move the status checks into `_raise_for_status`. Add helpers for the
request bodies and the query params. Both transports now raise the same
exception type and message for each endpoint.
- client: move the header and pool-limit code into module helpers. `AsyncClient`
then uses the same user-agent, auth header, and keepalive.
- _transcript_fields: move the response accessors from `Transcript` into a
`TranscriptFields` mixin. The mixin reads an abstract `_response()`. This also
deletes the repeated None checks.
Tests: `pytest tests/unit` gives 382 passed, 3 failed. The 3 failures need
`pyaudio` and also fail on master.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for freeto 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.

2 participants

@he-james@jchang-assemblyai