You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/website/docs/dlt-ecosystem/verified-sources/rest_api/advanced.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -241,3 +241,22 @@ source_config = {
241
241
242
242
In this example, the resource will set the correct encoding for all responses. More callables can be added to the list of response_actions.
243
243
244
+
245
+
### Setup timeouts and retry strategies
246
+
`rest_api` uses `dlt`[custom sessions](../../../general-usage/http/requests.md) and [`RESTClient`](../../../general-usage/http/rest-client.md) to access http(s) endpoints. You can use them to configure timeout, retries and other aspects. For example:
Copy file name to clipboardExpand all lines: docs/website/docs/dlt-ecosystem/verified-sources/rest_api/basic.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -240,6 +240,7 @@ The `client` configuration is used to connect to the API's endpoints. It include
240
240
-`auth` (optional): Authentication configuration. This can be a simple token, an `AuthConfigBase` object, or a more complex authentication method.
241
241
-`session` (requests.Session, optional): A custom session object. When provided, this session will be used for all HTTP requests instead of the default session. Can be used, for example, with [requests-oauthlib](https://github.com/requests/requests-oauthlib) for OAuth authentication.
242
242
-`paginator` (optional): Configuration for the default pagination used for resources that support pagination. Refer to the [pagination](#pagination) section for more details.
243
+
-`session` (optional): Custom `requests` session to setup custom [timeouts and retry strategies.](advanced.md#setup-timeouts-and-retry-strategies)
request_max_retry_delay = 30# Cap exponential delay to 30 seconds
64
64
```
65
65
66
+
:::note
67
+
Default session retires as follows:
68
+
69
+
```toml
70
+
[runtime]
71
+
request_timeout=60
72
+
request_max_attempts = 5
73
+
request_backoff_factor = 1
74
+
request_max_retry_delay = 300
75
+
```
76
+
:::
77
+
66
78
For more control, you can create your own instance of `dlt.sources.requests.Client` and use that instead of the global client.
67
79
68
80
This lets you customize which status codes and exceptions to retry on:
@@ -98,6 +110,12 @@ http_client = Client(
98
110
retry_condition=retry_if_error_key
99
111
)
100
112
```
113
+
114
+
:::tip
115
+
`requests.Client` is thread safe. We recommend to share sessions across threads for better performance.
116
+
:::
117
+
118
+
101
119
## Handling API Rate Limits
102
120
103
121
HTTP 429 errors indicate you've hit API rate limits. The dlt requests client retries these automatically and respects `Retry-After` headers. If rate limits persist, consider additional mitigation strategies.
Copy file name to clipboardExpand all lines: docs/website/docs/general-usage/http/rest-client.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -620,6 +620,7 @@ Unfortunately, most OAuth 2.0 implementations vary, and thus you might need to s
620
620
-`client_secret`: Client credential to obtain authorization. Usually issued via a developer portal.
621
621
-`access_token_request_data`: A dictionary with data required by the authorization server apart from the `client_id`, `client_secret`, and `"grant_type": "client_credentials"`. Defaults to `None`.
622
622
-`default_token_expiration`: The time in seconds after which the temporary access token expires. Defaults to 3600.
623
+
-`session`: Custom `requests` session where you can configure default timeouts and retry strategies
request_max_retry_delay = 30# Cap exponential delay to 30 seconds
730
731
```
731
732
733
+
:::note
734
+
`RESTClient` retries by default:
735
+
736
+
```toml
737
+
[runtime]
738
+
request_timeout=60
739
+
request_max_attempts = 5
740
+
request_backoff_factor = 1
741
+
request_max_retry_delay = 300
742
+
```
743
+
:::
744
+
745
+
### Use custom session
746
+
You can pass custom `requests``Session` to `RESTClient`. `dlt`[provides own implementation](requests.md#customizing-retry-settings) where you can easily configure
747
+
retry strategies, timeouts and other factors. For example:
will set-up the client for a short connect and read timeouts with no retries.
756
+
732
757
### URL sanitization and secret protection
733
758
734
759
The RESTClient automatically sanitizes URLs in logs and error messages to prevent exposure of sensitive information. Query parameters with the following names are automatically redacted:
0 commit comments