Skip to content
Back to top
View this page

# pyrate_limiter.extras.requests_limiter module

class pyrate_limiter.extras.requests_limiter.RateLimitedRequestsSession(limiter, name='pyrate_limiter.extras.requests_limiter', **_)

  Bases: `Session`

  A requests.Session that enforces a rate limit via a provided Limiter.

  The limiter’s `try_acquire(name)` is called before every outbound request.

  __init__(limiter, name='pyrate_limiter.extras.requests_limiter', **_)

    Initialize the rate-limited session.

    Parameters:

      - limiter (`Limiter`) – Object exposing `try_acquire(str) -> None` that blocks/raises when over limit.

      - name (`str`) – Token/key used by the limiter to bucket this session’s requests.

      - **_ – Ignored; accepted for API compatibility.

  close()

    Close the underlying HTTP adapters and release resources.

    Return type:

      `None`

  request(method, url, *args, **kwargs)

    Perform an HTTP request after acquiring from the limiter.

    Parameters:

      - method (`str` | `bytes`) – HTTP method (e.g., “GET”, “POST”).

      - url (`str` | `bytes`) – Request URL.

      - *args – Passed through to `requests.Session.request`.

      - **kwargs – Passed through to `requests.Session.request`.

    Return type:

      `Response`

    Returns:

      `requests.Response` returned by the underlying session.