Add rate limit information and proactive rate limit handling#53
Add rate limit information and proactive rate limit handling#53
Conversation
- Upgrade hypersync-client dependency from 1.0.2 to 1.1.0 - Add RateLimitInfo type with limit, remaining, reset_secs, cost, retry_after_secs, is_rate_limited, and suggested_wait_secs fields - Add get_with_rate_limit() method returning (QueryResponse, RateLimitInfo) - Add rate_limit_info() method to get last observed rate limit state - Add wait_for_rate_limit() method to wait until rate limit window resets - Add proactive_rate_limit_sleep config option to ClientConfig (default: True) - Register RateLimitInfo as a PyO3 class in the module - Bump package version from 0.10.0 to 0.11.0 - Update Python type stubs in __init__.py https://claude.ai/code/session_012mwJv9YsuFKTvrgftATDB7
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughThis pull request introduces rate-limiting support by adding a Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Python Client
participant HC as HypersyncClient
participant Inner as _HypersyncClient (Rust)
participant Server as Hypersync Server
Client->>HC: get_with_rate_limit(query)
activate HC
HC->>Inner: execute query
activate Inner
Inner->>Server: fetch data
Server-->>Inner: response + rate-limit headers
Inner-->>HC: QueryResponse + RateLimitInfo
deactivate Inner
HC->>HC: convert to Python types
HC-->>Client: (QueryResponse, RateLimitInfo)
deactivate HC
Note over Client,Server: Proactive rate-limit handling
Client->>HC: wait_for_rate_limit()
activate HC
HC->>Inner: wait until rate-limit resets
activate Inner
Inner-->>Inner: sleep until reset_secs elapsed
Inner-->>HC: completed
deactivate Inner
HC-->>Client: resumed
deactivate HC
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
This PR adds comprehensive rate limit support to the Hypersync Python client, enabling users to access rate limit information from server responses and proactively manage rate limiting.
Key Changes
RateLimitInfoclass: Exposes rate limit details including limit, remaining quota, reset time, cost per request, retry-after header, and suggested wait timeget_with_rate_limit(): Returns both query response and rate limit info as a tuplerate_limit_info(): Retrieves the most recently observed rate limit informationwait_for_rate_limit(): Async method to wait until the rate limit window resetsClientConfigoption:proactive_rate_limit_sleepflag to enable proactive sleeping when rate limit is exhausted (default: True)hypersync-clientfrom 1.0.2 to 1.1.0 to support new rate limit APIsImplementation Details
RateLimitInfois a Rust struct with Python bindings that converts from the underlyinghypersync_client::RateLimitInfotypeis_rate_limited()andsuggested_wait_secs()from the client libraryfuture_into_pyfor Python async compatibilityskip_serializing_ifto maintain backward compatibilityhttps://claude.ai/code/session_012mwJv9YsuFKTvrgftATDB7
Summary by CodeRabbit
New Features
proactive_rate_limit_sleepconfiguration option to control rate limit behavior.Chores