Skip to content

Add rate limiting handling with automatic retry#156

Merged
beaufour merged 1 commit intomasterfrom
feature/rate-limit-handling
Jan 25, 2026
Merged

Add rate limiting handling with automatic retry#156
beaufour merged 1 commit intomasterfrom
feature/rate-limit-handling

Conversation

@beaufour
Copy link
Collaborator

Summary

  • Add FlickrRateLimitError exception for HTTP 429 responses
  • Implement automatic retry with exponential backoff on rate limit errors
  • Parse Retry-After header when available
  • Add configurable retry settings via set_retry_config() and get_retry_config()
  • Default: 3 retries, 1s base delay, 60s max delay

Usage

The retry behavior can be configured or disabled:

import flickr_api

# Disable retries (raise immediately on rate limit)
flickr_api.set_retry_config(max_retries=0)

# Custom retry settings
flickr_api.set_retry_config(max_retries=5, base_delay=2.0, max_delay=120.0)

# Check current settings
config = flickr_api.get_retry_config()

When rate limited and retries are exhausted, raises FlickrRateLimitError with:

  • retry_after: Suggested wait time from server (or None)
  • content: Error message content

Background

Flickr returns HTTP 429 when the API rate limit (~3600 requests/hour) is exceeded. Previously this was not handled, causing JSON parsing to fail or return unexpected errors. Now the library automatically retries with backoff, or raises a clear exception when limits are exceeded.

Test plan

  • All 254 tests pass
  • 17 new tests for rate limit handling
  • flake8 passes

🤖 Generated with Claude Code

- Add FlickrRateLimitError exception for HTTP 429 responses
- Implement automatic retry with exponential backoff on rate limit
- Parse Retry-After header when available
- Add configurable retry settings: set_retry_config(), get_retry_config()
- Default: 3 retries, 1s base delay, 60s max delay

The retry behavior can be configured or disabled:
  flickr_api.set_retry_config(max_retries=0)  # Disable retries
  flickr_api.set_retry_config(max_retries=5, base_delay=2.0)

When rate limited and retries are exhausted, raises FlickrRateLimitError
with retry_after attribute containing the suggested wait time.

Includes 17 new tests for rate limit handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@beaufour beaufour merged commit 76b404b into master Jan 25, 2026
5 checks passed
@beaufour beaufour deleted the feature/rate-limit-handling branch January 25, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant