Rate Limit¶
pynautobot.core.rate_limit
¶
Parse the rate limiting headers returned by Nautobot 3.3+.
pynautobot.core.rate_limit.RateLimit
dataclass
¶
Rate limit information reported by Nautobot 3.3+ in REST API response headers.
Nautobot only sends these headers when rate limiting is set to report or enforce mode.
Any value Nautobot did not send, or that could not be parsed, is None.
Attributes:
| Name | Type | Description |
|---|---|---|
policy |
str
|
Name of the rate limit policy, from |
quota |
int | float
|
Total budget per window ( |
window |
int | float
|
Length of the budget window in seconds ( |
remaining |
int | float
|
Budget remaining in the current window ( |
reset |
int | float
|
Seconds until the current window resets ( |
cost |
int | float
|
Estimated cost of the request ( |
retry_after |
int
|
Seconds to wait before retrying a throttled request ( |
Examples:
>>> nb.dcim.devices.all()
>>> nb.rate_limit.remaining
996
>>> try:
... nb.dcim.devices.all()
... except pynautobot.RequestError as e:
... if e.rate_limit and e.rate_limit.retry_after:
... time.sleep(e.rate_limit.retry_after)
from_headers(headers)
classmethod
¶
Build a RateLimit from HTTP response headers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers |
Mapping
|
The response headers, such as |
required |
Returns:
| Type | Description |
|---|---|
RateLimit | None
|
The parsed rate limit information, or |