Skip to content
This repository was archived by the owner on Nov 6, 2026. It is now read-only.

Latest commit

 

History

History
73 lines (57 loc) · 2.56 KB

configuration.md

File metadata and controls

73 lines (57 loc) · 2.56 KB

Configuration

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.

Max retry attempts

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)

Custom retry strategy

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)