Skip to content

Rate limiting in httpx #2989

Closed Answered by tomchristie
ratzrattillo asked this question in Ideas
Discussion options

You must be logged in to vote

The approach I'd take if implementing this would be...

Approach 3: Implement rate limiting in a transport, using composition.

class RateLimit(httpx.BaseTransport):
    def __init__(self, transport, ...):
        self.transport = transport
        ...  # Initial configuration

    def handle_request(self, request):
        ...  # Wait for any existing rate limits
        response = self.transport.handle_request(request)
        ...  # Update rate limit state
        return response


# Usage...
transport = RateLimit(
    httpx.HTTPTransport(),
    ...
)
client = httpx.Client(transport=transport)

Could something like this be integrated via parameters in the httpx.(Async)Client classes?

It…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@karpetrosyan
Comment options

Answer selected by ratzrattillo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants