feat: async WebSocket streaming client#32
Conversation
Add a real-time streaming client for the OilPriceAPI Rails ActionCable endpoint (/cable, EnergyPricesChannel), exposed via the async SDK as `client.stream`. - Implements the ActionCable JSON subprotocol: welcome -> subscribe -> confirm_subscription -> message; pings/control frames filtered. - Token auth via `?token=` query param + `Authorization: Token` header (matches application_cable/connection.rb find_verified_user). - Ergonomic async API: `async with client.stream.prices(commodities=[...]) as stream: async for update in stream: ...` - Auto-reconnect with exponential backoff + jitter; clean unsubscribe + close teardown. - Pydantic models for price_update / welcome / rig_count_update payloads (StreamUpdate wrapper with typed accessors). - New optional `[stream]` extra (websockets>=11), wired into `all`/`dev`. - 13 unit tests with a fully mocked websocket transport (no network): handshake, dispatch, control-frame filtering, reconnect, give-up, teardown, namespace wiring. Gates: ruff clean, mypy strict Success (39 files), pytest 240 passed / 9 skipped, coverage 55.9% (>= 50% threshold). New streaming modules: client 92.6%, models 95.4%. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 56 minutes and 16 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ 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 |
Add a real-time streaming client for the OilPriceAPI Rails ActionCable endpoint (/cable, EnergyPricesChannel), exposed via the async SDK as `client.stream`. - Implements the ActionCable JSON subprotocol: welcome -> subscribe -> confirm_subscription -> message; pings/control frames filtered. - Token auth via `?token=` query param + `Authorization: Token` header (matches application_cable/connection.rb find_verified_user). - Ergonomic async API: `async with client.stream.prices(commodities=[...]) as stream: async for update in stream: ...` - Auto-reconnect with exponential backoff + jitter; clean unsubscribe + close teardown. - Pydantic models for price_update / welcome / rig_count_update payloads (StreamUpdate wrapper with typed accessors). - New optional `[stream]` extra (websockets>=11), wired into `all`/`dev`. - 13 unit tests with a fully mocked websocket transport (no network): handshake, dispatch, control-frame filtering, reconnect, give-up, teardown, namespace wiring. Gates: ruff clean, mypy strict Success (39 files), pytest 240 passed / 9 skipped, coverage 55.9% (>= 50% threshold). New streaming modules: client 92.6%, models 95.4%. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Adds a real-time async WebSocket streaming client to the Python SDK, exposing the OilPriceAPI ActionCable stream (
/cable,EnergyPricesChannel) — a Professional+ feature no SDK previously surfaced. Available viaclient.streamon the async client.Channel / protocol (confirmed from source)
Source of truth:
oilpriceapi-api/app/channels/+oilpriceapi-docs/docs/websocket/.wss://api.oilpriceapi.com/cable(mounted at/cableinconfig/routes.rb)EnergyPricesChannelapplication_cable/connection.rb#find_verified_user): API token via?token=query param orAuthorization: Token <key>header → resolvesApiKey.active.find_by_token; subscription further requirescurrent_user.can_access_websocket?(Reservoir Mastery / Professional+), elsereject.{"type":"welcome"}→ client sends{"command":"subscribe","identifier":"{\"channel\":\"EnergyPricesChannel\",\"api_key\":\"...\"}"}→ server{"type":"confirm_subscription"}→ broadcasts arrive as{"identifier":...,"message":{...}};{"type":"ping"}keepalives ignored.BroadcastEnergyPricesJob+ channelsend_initial_prices):welcome— initial snapshot (same shape as price_update; may carryerror)price_update—prices.oil.{brent,wti}+prices.natural_gas.{uk,us,eu}, each a normalized price blockrig_count_update—rig_count.{code,region,count,source,updated_at}Streaming API
StreamUpdate(Pydantic), with.price_update/.rig_count_updateaccessors and.rawpassthrough.auto_reconnect,max_reconnect_attempts,reconnect_base_delay/max_delay); clean server close (ConnectionClosedOK) ends iteration without reconnect.[stream]extra (websockets>=11); lazily imported so the base SDK is unaffected. Wired intoallanddev.oilpriceapi.__init__:PriceStream,StreamUpdate,PriceUpdate,RigCountUpdate,StreamingNotInstalledError.Test results (exact CI commands)
ruff check oilpriceapi/→ All checks passedmypy oilpriceapi/ --ignore-missing-imports→ Success: no issues found in 39 source files (new modules fully annotated, strict-clean)pytest tests/ --ignore=tests/integration --ignore=tests/contract -m 'not slow' --cov=oilpriceapi→ 240 passed, 9 skipped, coverage 55.9% (≥ 50%)13 new unit tests with a fully mocked websocket transport (no network): handshake/subscribe, rejected subscription, message dispatch, control-frame filtering, reconnect-on-drop, give-up after max attempts, auto-reconnect disabled, unsubscribe-on-close, namespace wiring, cable-URL derivation. New module coverage:
streaming/client.py92.6%,streaming/models.py95.4%.No version bump / tag.
🤖 Generated with Claude Code