Skip to content

Add proxy, hooks, circuit breaker, cache, batch helpers, and examples#32

Merged
jackparnell merged 3 commits intomainfrom
feature/sdk-v170-final
Apr 12, 2026
Merged

Add proxy, hooks, circuit breaker, cache, batch helpers, and examples#32
jackparnell merged 3 commits intomainfrom
feature/sdk-v170-final

Conversation

@ColonistOne
Copy link
Copy Markdown
Collaborator

Summary

Completes the v1.7.0 feature set with 9 additions:

# Feature Details
1 Proxy support proxy="http://proxy:8080" param on both clients
2 Idempotency keys X-Idempotency-Key header on POST requests to prevent duplicate creates
3 SDK-level hooks on_request(callback) / on_response(callback) for custom metrics/logging
4 Circuit breaker enable_circuit_breaker(5) — fail fast after N consecutive failures
5 Response caching enable_cache(ttl=60) — in-memory cache for GET requests with TTL
6 Batch helpers get_posts_by_ids() / get_users_by_ids() — fetch multiple, skip 404s
7 py.typed verified Confirmed downstream type checkers see all models
8 Examples 6 runnable scripts: basic, typed, async, webhook, mock testing, hooks
9 CHANGELOG + README Updated with all new features

All features available on both sync (ColonyClient) and async (AsyncColonyClient).

Changes

  • client.py — +168 lines (proxy, hooks, circuit breaker, cache, batch helpers)
  • async_client.py — +76 lines (hooks, circuit breaker, batch helpers)
  • tests/test_advanced.py — 28 new tests
  • examples/ — 6 new files
  • CHANGELOG + README updated

Test plan

  • 342 tests pass (28 new + 314 existing)
  • 99% code coverage
  • ruff check clean
  • ruff format clean
  • mypy strict clean
  • CI matrix (Python 3.10/3.12/3.13)

🤖 Generated with Claude Code

Features:
1. Proxy support — proxy= param routes requests through HTTP/HTTPS proxies
2. Idempotency keys — X-Idempotency-Key header on POST requests
3. SDK-level hooks — on_request/on_response callbacks for custom metrics
4. Circuit breaker — enable_circuit_breaker(N) fails fast after N failures
5. Response caching — enable_cache(ttl) caches GET responses in memory
6. Batch helpers — get_posts_by_ids/get_users_by_ids with 404 skipping
7. py.typed marker verified
8. Examples directory — 6 runnable scripts (basic, typed, async, webhook,
   mock testing, hooks)

All features on both sync and async clients. 342 tests, 99% coverage.
Updated CHANGELOG and README.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

ColonistOne and others added 2 commits April 12, 2026 08:11
- Test proxy code path uses ProxyHandler + build_opener
- Test async on_request and on_response hooks fire correctly
- Test async get_posts_by_ids skips 404s

346 tests pass, 100% coverage across all modules.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New file: tests/integration/test_v170_features.py (16 tests)
- TestTypedModeIntegration — confirms Post/User/Comment models populate
  correctly from real API responses (catches schema drift that mocked
  unit tests miss)
- TestRateLimitHeadersIntegration — confirms server emits X-RateLimit-*
  headers and we parse them as ints
- TestBatchHelpersIntegration — get_posts_by_ids / get_users_by_ids
  against real IDs, including 404 skip behaviour

Expanded: tests/integration/test_async.py (+19 tests)
- TestAsyncComments, TestAsyncVotingAndReactions, TestAsyncNotifications,
  TestAsyncColonies, TestAsyncFollowing, TestAsyncWebhooks, TestAsyncProfile
- Plus async coverage for v1.7.0: TestAsyncBatchHelpers,
  TestAsyncRateLimitHeaders, TestAsyncTypedMode

Closes the major async parity gaps identified in the audit (was ~10 tests
covering core methods only; now 27 tests covering comments, voting,
reactions, notifications, colonies, following, webhooks, profile updates,
batch helpers, rate limits, and typed mode).

Also: extend items_of() helper in conftest to recognise the "data" key,
which AsyncColonyClient uses to wrap bare-list responses.

All 43 new+existing integration tests pass against the live API
(3 skip when COLONY_TEST_API_KEY_2 is unset).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jackparnell jackparnell merged commit 9ffb08e into main Apr 12, 2026
7 checks passed
@jackparnell jackparnell deleted the feature/sdk-v170-final branch April 12, 2026 07:25
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.

2 participants