LangSmithRetry#
- class langsmith.utils.LangSmithRetry(total: bool | int | None = 10, connect: int | None = None, read: int | None = None, redirect: bool | int | None = None, status: int | None = None, other: int | None = None, allowed_methods: Collection[str] | None = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE'}), status_forcelist: Collection[int] | None = None, backoff_factor: float = 0, backoff_max: float = 120, raise_on_redirect: bool = True, raise_on_status: bool = True, history: tuple[RequestHistory, ...] | None = None, respect_retry_after_header: bool = True, remove_headers_on_redirect: Collection[str] = frozenset({'Authorization', 'Cookie', 'Proxy-Authorization'}), backoff_jitter: float = 0.0)[source]#
Wrapper to filter logs with this name.
Attributes
DEFAULT
DEFAULT_ALLOWED_METHODS
Default methods to be used for
allowed_methods
DEFAULT_BACKOFF_MAX
Default maximum backoff time.
DEFAULT_REMOVE_HEADERS_ON_REDIRECT
Default headers to be used for
remove_headers_on_redirect
RETRY_AFTER_STATUS_CODES
Default status codes to be used for
status_forcelist
Methods
__init__
([total, connect, read, redirect, ...])from_int
(retries[, redirect, default])Backwards-compatibility for the old retries format.
Formula for computing the current backoff
get_retry_after
(response)Get the value of Retry-After in seconds.
increment
([method, url, response, error, ...])Return a new Retry object with incremented retry counters.
Are we out of retries?
is_retry
(method, status_code[, has_retry_after])Is this method/status code retryable? (Based on allowlists and control variables such as the number of total retries to allow, whether to respect the Retry-After header, whether this header is present, and whether the returned status code is on the list of status codes to be retried upon on the presence of the aforementioned header)
new
(**kw)parse_retry_after
(retry_after)sleep
([response])Sleep between retry attempts.
sleep_for_retry
(response)- Parameters:
total (bool | int | None)
connect (int | None)
read (int | None)
redirect (bool | int | None)
status (int | None)
other (int | None)
allowed_methods (Collection[str] | None)
status_forcelist (Collection[int] | None)
backoff_factor (float)
backoff_max (float)
raise_on_redirect (bool)
raise_on_status (bool)
history (tuple[RequestHistory, ...] | None)
respect_retry_after_header (bool)
remove_headers_on_redirect (Collection[str])
backoff_jitter (float)
- __init__(total: bool | int | None = 10, connect: int | None = None, read: int | None = None, redirect: bool | int | None = None, status: int | None = None, other: int | None = None, allowed_methods: Collection[str] | None = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE'}), status_forcelist: Collection[int] | None = None, backoff_factor: float = 0, backoff_max: float = 120, raise_on_redirect: bool = True, raise_on_status: bool = True, history: tuple[RequestHistory, ...] | None = None, respect_retry_after_header: bool = True, remove_headers_on_redirect: Collection[str] = frozenset({'Authorization', 'Cookie', 'Proxy-Authorization'}), backoff_jitter: float = 0.0) None #
- Parameters:
total (bool | int | None)
connect (int | None)
read (int | None)
redirect (bool | int | None)
status (int | None)
other (int | None)
allowed_methods (Collection[str] | None)
status_forcelist (Collection[int] | None)
backoff_factor (float)
backoff_max (float)
raise_on_redirect (bool)
raise_on_status (bool)
history (tuple[RequestHistory, ...] | None)
respect_retry_after_header (bool)
remove_headers_on_redirect (Collection[str])
backoff_jitter (float)
- Return type:
None
- classmethod from_int(retries: Retry | bool | int | None, redirect: bool | int | None = True, default: Retry | bool | int | None = None) Retry #
Backwards-compatibility for the old retries format.
- Parameters:
retries (Retry | bool | int | None)
redirect (bool | int | None)
default (Retry | bool | int | None)
- Return type:
Retry
- get_backoff_time() float #
Formula for computing the current backoff
- Return type:
float
- get_retry_after(response: BaseHTTPResponse) float | None #
Get the value of Retry-After in seconds.
- Parameters:
response (BaseHTTPResponse)
- Return type:
float | None
- increment(method: str | None = None, url: str | None = None, response: BaseHTTPResponse | None = None, error: Exception | None = None, _pool: ConnectionPool | None = None, _stacktrace: TracebackType | None = None) Self #
Return a new Retry object with incremented retry counters.
- Parameters:
response (
BaseHTTPResponse
) – A response object, or None, if the server did not return a response.error (Exception) – An error encountered during the request, or None if the response was received successfully.
method (str | None)
url (str | None)
_pool (ConnectionPool | None)
_stacktrace (TracebackType | None)
- Returns:
A new
Retry
object.- Return type:
Self
- is_exhausted() bool #
Are we out of retries?
- Return type:
bool
- is_retry(method: str, status_code: int, has_retry_after: bool = False) bool #
Is this method/status code retryable? (Based on allowlists and control variables such as the number of total retries to allow, whether to respect the Retry-After header, whether this header is present, and whether the returned status code is on the list of status codes to be retried upon on the presence of the aforementioned header)
- Parameters:
method (str)
status_code (int)
has_retry_after (bool)
- Return type:
bool
- new(**kw: Any) Self #
- Parameters:
kw (Any)
- Return type:
Self
- parse_retry_after(retry_after: str) float #
- Parameters:
retry_after (str)
- Return type:
float
- sleep(response: BaseHTTPResponse | None = None) None #
Sleep between retry attempts.
This method will respect a server’s
Retry-After
response header and sleep the duration of the time requested. If that is not present, it will use an exponential backoff. By default, the backoff factor is 0 and this method will return immediately.- Parameters:
response (BaseHTTPResponse | None)
- Return type:
None
- sleep_for_retry(response: BaseHTTPResponse) bool #
- Parameters:
response (BaseHTTPResponse)
- Return type:
bool