Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/38.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Increased the default request timeout to 30 seconds (from httpx's default of 5) and made it configurable via Client(app_id, timeout=...).
13 changes: 11 additions & 2 deletions wolframalpha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,17 @@ class Client:

url = 'https://api.wolframalpha.com/v2/query'

def __init__(self, app_id):
timeout: float = 30.0
"""
Seconds to wait for the API to respond. Wolfram|Alpha's own
``totaltimeout`` defaults to about 20 seconds, so allow somewhat more
than that (rather than httpx's default of 5 seconds).
Pass ``timeout=`` to the constructor to override.
"""

def __init__(self, app_id, **kwargs):
self.app_id = app_id
vars(self).update(kwargs)

@classmethod
def from_env(cls):
Expand Down Expand Up @@ -120,7 +129,7 @@ def query(self, input, params=(), **kwargs):
return asyncio.run(self.aquery(input, params, **kwargs))

async def aquery(self, input, params=(), **kwargs):
async with httpx.AsyncClient() as client:
async with httpx.AsyncClient(timeout=self.timeout) as client:
resp = await client.get(
self.url,
params=multidict.MultiDict(
Expand Down
Loading