feat: add configurable request timeout to the Creators API - #151
feat: add configurable request timeout to the Creators API#151YPCrumble wants to merge 1 commit into
Conversation
The sync AmazonCreatorsApi called the bundled SDK without _request_timeout, so urllib3 received an explicit None and requests could hang forever. The async layer already applied a 30 second timeout, but did not let callers change it. Both classes now accept a timeout parameter in seconds, sharing the existing DEFAULT_TIMEOUT of 30 seconds. That constant moves to core.constants so the sync layer can use it without pulling in the optional httpx dependency, and is re-exported from aio.client for compatibility. Passing None restores the previous behavior of waiting indefinitely. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Reopening to retrigger CI — the original run never executed. All 8 jobs were cancelled with "The job was not acquired by Runner of type hosted even after multiple attempts", a GitHub-hosted runner outage on 6 Aug, so the red matrix reflects zero code having run. Runners have since recovered. |
|
@sergioteula thanks for maintaining this repo! This PR would help me prevent stalled requests to Amazon from consuming workers during brief outages. Let me know if you see any issues or have any concerns! BTW, On CI failing: Because GitHub doesn't pass repository secrets to workflows triggered by fork PRs, so Two things confirm it's environmental: those same tests skip cleanly when run locally on this branch ( Changing that line to |
Summary
The sync
AmazonCreatorsApicallsself._api.<method>(...)without_request_timeoutat all four call sites (get_items,search_items,get_variations,get_browse_nodes). The bundled SDK'srest.pythen takes itstimeout = Nonebranch and hands that explicitNoneto urllib3, so no timeout is applied at all and a stalled endpoint hangs the caller indefinitely.The async layer already gets this right:
aio/client.pydefinesDEFAULT_TIMEOUT = 30.0and passes it to httpx. Same library, opposite safety default — and neither one is configurable today.This adds a
timeoutparameter, in seconds, to both classes, and reuses the existing 30 second default for the sync layer rather than introducing a new number.Behavior change
Sync requests now time out after 30 seconds instead of waiting forever. That is a real change, and it is the point of the PR — but it is a change, so
timeout=Noneis supported and restores the old behavior exactly, for anyone who wants it.I went with a real default rather than an opt-in
Nonebecause "no timeout" is not a defensible default for a network client, and because 30 seconds is not a new opinion — it is the value this library already ships and has been using in the async layer since 6.1.0. If you would rather keep this strictly non-breaking, I am happy to flip the sync default toNone(opt-in only, zero behavior change); it is a one-line change plus a changelog note. Your call, since it is your semver contract.What changed
AmazonCreatorsApi.__init__takestimeout: float | None = DEFAULT_TIMEOUTand forwards_request_timeout=self.timeoutat all four SDK call sites.AsyncAmazonCreatorsApi.__init__takes the same parameter and passes it to bothAsyncHttpClientconstruction sites (the context-manager client and the per-request one). Async callers were previously stuck with 30 seconds and no way to change it.DEFAULT_TIMEOUTmoves fromaio/client.pytocore/constants.py, next toDEFAULT_THROTTLING, so both layers can share one value. It has to live there rather than inaio/client.py, because that module importshttpxat module scope and httpx is an optional extra — importing it from the sync path would make every sync-only install require httpx. It is still importable fromaio.clientas before, so nothing downstream breaks.AsyncHttpClient'stimeoutannotation widens tofloat | None, sinceNoneis how both httpx and the SDK spell "wait indefinitely".None.Seconds and float throughout, matching
urllib3,httpx, Amazon's_request_timeout, and the existingthrottlingparameter next to it. Ints work fine (timeout=10); the SDK normalizes them.No files under
creatorsapi_python_sdk/were touched. Amazon's SDK already accepts_request_timeouton everyDefaultApimethod — the wrapper simply never set it. This is plumbing, not a design change.The async half is separable. If you would rather keep this to the sync fix, I will drop it and leave
AsyncAmazonCreatorsApias is.Checks
ruff format,ruff check,mypy, and the full test suite pass locally on Python 3.9 through 3.14. Verified in a clean environment without httpx installed that the sync API still imports and picks up the default.CHANGELOG.md,pyproject.toml, anddocs/conf.pyare bumped to 6.4.0 and passscripts/check_version.py.Unrelated to #86 / #76, despite the similar title — that issue was a script not exiting on Windows in the legacy
amazon_paapimodule, not a network timeout.