Skip to content

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 RateLimit or RateLimit-Policy.

quota int | float

Total budget per window (q in RateLimit-Policy).

window int | float

Length of the budget window in seconds (w in RateLimit-Policy).

remaining int | float

Budget remaining in the current window (r in RateLimit).

reset int | float

Seconds until the current window resets (t in RateLimit).

cost int | float

Estimated cost of the request (X-Nautobot-Cost).

retry_after int

Seconds to wait before retrying a throttled request (Retry-After).

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 requests.Response.headers.

required

Returns:

Type Description
RateLimit | None

The parsed rate limit information, or None when the response carries none of the RateLimit, RateLimit-Policy, X-Nautobot-Cost or Retry-After headers (Nautobot before 3.3, or rate limiting turned off).