Caution
box-python-sdk-gen is deprecated and no longer maintained. As of September 17, 2025, it receives no new features, bug fixes, or security patches. Do not use it for new projects.
Use box-python-sdk v10+ instead: pip install "boxsdk>=10".
The equivalent of this page is box-python-sdk/docs/configuration.md. To migrate existing code, see the migration guide.
The default maximum number of retries in case of failed API call is 5.
To change this number you should initialize BoxRetryStrategy with the new value and pass it to NetworkSession.
from box_sdk_gen import (
BoxClient,
BoxDeveloperTokenAuth,
NetworkSession,
BoxRetryStrategy,
)
auth = BoxDeveloperTokenAuth(token="DEVELOPER_TOKEN_GOES_HERE")
network_session = NetworkSession(retry_strategy=BoxRetryStrategy(max_attempts=6))
client = BoxClient(auth=auth, network_session=network_session)You can also implement your own retry strategy by subclassing RetryStrategy and overriding should_retry and retry_after methods.
This example shows how to set custom strategy that retries on 5xx status codes and waits 1 second between retries.
from box_sdk_gen import (
BoxClient,
BoxDeveloperTokenAuth,
NetworkSession,
RetryStrategy,
FetchOptions,
FetchResponse,
)
class CustomRetryStrategy(RetryStrategy):
def should_retry(
self,
fetch_options: FetchOptions,
fetch_response: FetchResponse,
attempt_number: int,
) -> bool:
return fetch_response.status_code >= 500
def retry_after(
self,
fetch_options: FetchOptions,
fetch_response: FetchResponse,
attempt_number: int,
) -> float:
return 1.0
auth = BoxDeveloperTokenAuth(token="DEVELOPER_TOKEN_GOES_HERE")
network_session = NetworkSession(retry_strategy=CustomRetryStrategy())
client = BoxClient(auth=auth, network_session=network_session)