Skip to content

Add typed models, mock client, logging, User-Agent, and rate-limit headers#30

Merged
jackparnell merged 2 commits intomainfrom
feature/sdk-improvements
Apr 11, 2026
Merged

Add typed models, mock client, logging, User-Agent, and rate-limit headers#30
jackparnell merged 2 commits intomainfrom
feature/sdk-improvements

Conversation

@ColonistOne
Copy link
Copy Markdown
Collaborator

Summary

Five SDK improvements for v1.7.0:

  1. Typed response models (colony_sdk.models) — Post, Comment, User, Message, Notification, Colony, Webhook, PollResults, RateLimitInfo as frozen dataclasses with from_dict()/to_dict(). Zero new dependencies.

  2. Request/response logging — stdlib logging via logger "colony_sdk". DEBUG for requests/responses, WARNING for errors.

  3. User-Agent header — all requests now send colony-sdk-python/1.7.0. Both sync and async clients.

  4. Rate-limit header exposure — parses X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset from responses. Available via client.last_rate_limit after each call.

  5. Mock client for testing (colony_sdk.testing) — MockColonyClient drop-in that returns canned responses, records calls for assertions, supports custom/callable responses. Full method parity.

Changes

  • 2 new modules: models.py (399 lines), testing.py (260 lines)
  • 2 new test files: test_models.py (234 lines), test_testing.py (124 lines)
  • Updated client.py and async_client.py with logging, User-Agent, rate-limit parsing
  • Version bump 1.6.0 → 1.7.0

Test plan

  • All 281 tests pass (54 new + 227 existing)
  • ruff check clean
  • ruff format clean
  • mypy strict clean
  • CI matrix (Python 3.10/3.12/3.13)

🤖 Generated with Claude Code

…aders

1. Typed response models (colony_sdk.models)
   - Post, Comment, User, Message, Notification, Colony, Webhook,
     PollResults, RateLimitInfo — all frozen dataclasses with
     from_dict()/to_dict() methods
   - Zero new dependencies — pure stdlib dataclasses

2. Request/response logging
   - Uses stdlib logging module via logger "colony_sdk"
   - DEBUG level: logs every request/response with method, URL, size
   - WARNING level: logs HTTP errors and network failures

3. User-Agent header
   - All requests now send "colony-sdk-python/{version}" in User-Agent
   - Both sync and async clients

4. Rate-limit header exposure
   - Parses X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset
   - Available via client.last_rate_limit after each API call
   - Supports both capitalized and lowercase header names

5. Mock client for testing (colony_sdk.testing)
   - MockColonyClient — drop-in replacement that returns canned responses
   - Records all calls for assertions via client.calls
   - Supports custom responses and callable response factories
   - Full method parity with ColonyClient

Bump version to 1.7.0. All 281 tests pass.

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!

- Add to_dict() tests for all models with optional fields set
- Add tests for MockColonyClient.get_all_comments, iter_comments,
  update_profile, directory
- Remove unused _get() helper from models.py

All 293 tests pass with 100% coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jackparnell jackparnell merged commit e5331b8 into main Apr 11, 2026
7 checks passed
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