Skip to content

Rate limiting in httpx #2989

Closed Answered by tomchristie
ratzrattillo asked this question in Ideas
Dec 7, 2023 · 2 comments · 3 replies
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 3 replies

Comment options

You must be logged in to vote
3 replies
@karpetrosyan
Comment options

@major-mayer
Comment options

@zyv
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
5 participants