Skip to content

Commit 9ff0d84

Browse files
committed
Added function set_timeout
1 parent 46dcb1d commit 9ff0d84

File tree

6 files changed

+53
-4
lines changed

6 files changed

+53
-4
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,6 @@ dmypy.json
144144

145145
# End of https://www.gitignore.io/api/code,macos,python
146146

147-
*.tmp.*
147+
*.tmp.*
148+
149+
env

API-REFERENCE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,23 @@ except Exception as err:
235235
print("Something went wrong: {0}".format(err))
236236
```
237237

238+
---
239+
### set_timeout
240+
241+
Configures the HTTP client timeout for requests made to the Carbone server. The default timeout value is set to 60 seconds, which matches the Carbone Cloud server's default timeout.
242+
243+
If you are generating documents using a Carbone On-Premise server with a custom timeout configuration, you may need to adjust the timeout value accordingly. Increase the timeout value to ensure that the HTTP client waits long enough for the server to process the request.
244+
245+
```python
246+
import carbone_sdk
247+
248+
csdk = carbone_sdk.CarboneSDK("your_access_token")
249+
250+
csdk.set_timeout(120) # = 2 minutes
251+
csdk.set_timeout(300) # = 5 minutes
252+
```
253+
254+
---
238255
### get_status
239256

240257
**Definition**

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### v1.1.1
2+
- Added function `set_timeout`: Configures the HTTP client timeout for requests made to the Carbone server.
3+
14
### v1.1.0
25
- Fixed: Added "requests" as required install.
36
- Update to Carbone version 5

carbone_sdk/carbone_sdk.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ def set_api_version(self, api_version = None):
7777
else:
7878
raise ValueError('Carbone SDK set_api_version error: an argument is invalid: api_version is not a number nor a string')
7979

80+
def set_timeout(self, api_timeout = None):
81+
if api_timeout is None:
82+
raise ValueError('Carbone SDK set_timeout error: argument is missing: api_timeout')
83+
elif not isinstance(api_timeout, int):
84+
raise ValueError('Carbone SDK set_timeout error: argument is not a number')
85+
self._api_timeout = api_timeout
86+
8087
def set_api_url(self, api_url = None):
8188
if api_url is None:
8289
raise ValueError('Carbone SDK set_api_url error: argument is missing: api_url')

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="carbone-sdk",
8-
version="1.1.0",
8+
version="1.1.1",
99
author="CarboneIO",
1010
author_email="support@carbone.io",
1111
description="Carbone API Python SDK to generate documents (PDF DOCX XLSX PPTX CSV XML HTML ODS ODT and more) from a JSON and a template.",
@@ -15,8 +15,10 @@
1515
packages=setuptools.find_packages(),
1616
classifiers=[
1717
"Programming Language :: Python :: 3",
18-
"License :: OSI Approved :: Apache Software License",
1918
"Operating System :: OS Independent",
19+
"Intended Audience :: Developers",
20+
"Development Status :: 5 - Production/Stable",
21+
"Topic :: Software Development :: Libraries :: Python Modules"
2022
],
2123
python_requires='>=3.6',
2224
license='Apache-2.0',

tests/test_carbone_sdk.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def csdk():
1515
class TestInitSDK:
1616
def test_sdk_default_values(self, csdk):
1717
assert csdk._api_headers["Authorization"] == "Bearer Token"
18-
assert csdk._api_headers["carbone-version"] == "4"
18+
assert csdk._api_headers["carbone-version"] == "5"
19+
assert csdk._api_timeout == 60
1920
assert csdk._api_url == "https://api.carbone.io"
2021

2122
def test_init_sdk_error_missing_token(self):
@@ -39,6 +40,23 @@ def test_set_access_token_error_missing_token(self, csdk):
3940
csdk.set_access_token()
4041
assert e.value.args[0] == 'Carbone SDK set_access_token error: argument is missing: api_token'
4142

43+
def test_set_timeout_int(self, csdk):
44+
default_timeout = csdk._api_timeout
45+
new_timeout = 85000
46+
csdk.set_timeout(new_timeout)
47+
assert csdk._api_timeout == new_timeout
48+
csdk.set_timeout(default_timeout)
49+
50+
def test_set_timeout_string(self, csdk):
51+
with pytest.raises(ValueError) as e:
52+
csdk.set_timeout("123123144")
53+
assert e.value.args[0] == 'Carbone SDK set_timeout error: argument is not a number'
54+
55+
def test_set_timeout_missing(self, csdk):
56+
with pytest.raises(ValueError) as e:
57+
csdk.set_timeout()
58+
assert e.value.args[0] == 'Carbone SDK set_timeout error: argument is missing: api_timeout'
59+
4260
def test_set_api_version_int(self, csdk):
4361
new_version = 2
4462
csdk.set_api_version(new_version)

0 commit comments

Comments
 (0)