Skip to content

Commit 3274a5b

Browse files
committed
Make timeouts configurable on the client
This adds a configuration parameter to the `Client` and documents it in the README.md.
1 parent 4fbdab9 commit 3274a5b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,16 @@ c.xlsx('input.pdf', 'output.xlsx')
3030
## Test
3131

3232
python -m unittest test.test_pdftables_api
33+
34+
## Configuring a timeout
35+
36+
If you are converting a large document, you may want to increase the timeout.
37+
The below example allows 60 seconds to connect to our server, and 1 hour to
38+
convert the document.
39+
40+
```py
41+
import pdftables_api
42+
43+
c = pdftables_api.Client('my-api-key', timeout=(60, 3600))
44+
c.xlsx('input.pdf', 'output.xlsx')
45+
```

pdftables_api/pdftables_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040

4141

4242
class Client(object):
43-
def __init__(self, api_key, api_url=_API_URL):
43+
def __init__(self, api_key, api_url=_API_URL, timeout=_DEFAULT_TIMEOUT):
4444
self.api_key = api_key
4545
self.api_url = api_url
46+
self.timeout = timeout
4647

4748
def xlsx(self, pdf_path, xlsx_path):
4849
"""
@@ -94,7 +95,7 @@ def dump(self, pdf_fo, out_format=None, query_params=None, **requests_params):
9495
raise APIException("Invalid API key")
9596

9697
if 'timeout' not in requests_params:
97-
requests_params.update({'timeout': _DEFAULT_TIMEOUT})
98+
requests_params.update({'timeout': self.timeout})
9899

99100
(_, out_format) = Client.ensure_format_ext(None, out_format)
100101
url = self.api_url

0 commit comments

Comments
 (0)