How do you respect API rate limits proactively?
AdvancedConceptData formats, HTTP & REST APIs
Answer
- Read rate-limit headers (
X-RateLimit-Remaining,X-RateLimit-Reseton GitHub;Retry-Afteron 429) and sleep until reset when near zero. - Bound concurrency (a fixed worker pool or
asyncio.Semaphore), because parallelism multiplies request rate. - Use a token-bucket limiter for steady pacing (
limits,aiolimiter, or a small class). - Cache responses (ETags with
If-None-Match; GitHub does not count 304s against the limit). - Prefer bulk or GraphQL endpoints to reduce call count.
More on Data formats, HTTP & REST APIs
How do you read and write JSON, and what are the common gotchas?BeginnerWhy must you use `yaml.safe_load` rather than `yaml.load`?BeginnerHow do you load a multi-document Kubernetes YAML file?IntermediateHow do you read and write CSV files properly?BeginnerHow do you make an HTTP request with `requests` the right way?BeginnerWhy use a `requests.Session`?Intermediate