Add typed models, mock client, logging, User-Agent, and rate-limit headers#30
Merged
jackparnell merged 2 commits intomainfrom Apr 11, 2026
Merged
Add typed models, mock client, logging, User-Agent, and rate-limit headers#30jackparnell merged 2 commits intomainfrom
jackparnell merged 2 commits intomainfrom
Conversation
…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 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Five SDK improvements for v1.7.0:
Typed response models (
colony_sdk.models) —Post,Comment,User,Message,Notification,Colony,Webhook,PollResults,RateLimitInfoas frozen dataclasses withfrom_dict()/to_dict(). Zero new dependencies.Request/response logging — stdlib
loggingvia logger"colony_sdk". DEBUG for requests/responses, WARNING for errors.User-Agent header — all requests now send
colony-sdk-python/1.7.0. Both sync and async clients.Rate-limit header exposure — parses
X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-Resetfrom responses. Available viaclient.last_rate_limitafter each call.Mock client for testing (
colony_sdk.testing) —MockColonyClientdrop-in that returns canned responses, records calls for assertions, supports custom/callable responses. Full method parity.Changes
models.py(399 lines),testing.py(260 lines)test_models.py(234 lines),test_testing.py(124 lines)client.pyandasync_client.pywith logging, User-Agent, rate-limit parsingTest plan
🤖 Generated with Claude Code