Deep dives for features that go beyond the basics. Pair this with EXPLAINER.md for rate-limit math and rationale.
-
Snapshots: Grab a single bucket’s latest state.
state = client.rate_limit_snapshot("core") print(state.limit, state.remaining, state.reset_ts)
-
Listeners: Subscribe to live updates whenever headers change.
def handle_update(bucket, state): print(f"{bucket} remaining: {state.remaining}") client.add_rate_limit_listener(handle_update) # ... later client.remove_rate_limit_listener(handle_update)
Keep a bucket fresh even when idle:
client.start_rate_limit_polling(interval_seconds=90, bucket="core")
# ...
client.stop_rate_limit_polling()The poller calls GET /rate_limit on a cadence and backs off whenever normal
requests deliver fresh headers.
Use as a last-resort brake for runaway jobs. Full behavior and rationale live in EXPLAINER.md.
import time
client.schedule_killswitch(after_seconds=3600, reason="end-of-batch")
client.set_killswitch(until_epoch=time.time() + 60, reason="maintenance window")While active, new requests raise RuntimeError until cleared or the timeout
expires.
- Textual UI (
gk-dash): buckets, Actions, presets, and visibility controls are documented indocs/dashboard-bucket-visibility.md(themes, Active-only, digit toggles, Actions hide/show, etc.). - Legacy table UI: use
--ui tableif you prefer the minimal Rich table. - Socket bridge: default
/tmp/gratekeeper.sockaccepts local updates; disable with--socket none(see README Security notes). On Windows the bridge is disabled automatically.
Importing GRatekeeper attaches a Rich RichHandler to the gratekeeper logger
unless you already configured handlers. Customize logging by configuring your
own handlers before importing the library.
- Local setup, linting, and test commands live in CONTRIBUTING.md.
- Demo/testing helpers: see
scripts/run_demo_scenarios.pyandmake demo/make demo-testfor live API demos;make demo-uifor the Textual UI VHS capture.