refactor: modernize SDK with idiomatic patterns, structured exceptions, and expanded tests#57
Merged
LegendEvent merged 1 commit intodevfrom Apr 14, 2026
Merged
refactor: modernize SDK with idiomatic patterns, structured exceptions, and expanded tests#57LegendEvent merged 1 commit intodevfrom
LegendEvent merged 1 commit intodevfrom
Conversation
…s, and expanded tests - Migrate all 27 endpoint modules to use idiomatic BaseEndpoint helpers (_get, _post_json, _post_form, _delete) instead of manual header/request calls - Add structured exception hierarchy (darktrace/exceptions.py) with 8 purpose-built HTTP error classes wrapping requests.HTTPError - Add _raise_for_status() to BaseEndpoint for consistent error handling - Expand CI matrix to Python 3.8-3.12 in lint workflow - Add 28 HMAC signature tests (tests/test_auth.py) - Add 47 POST/DELETE mock tests (tests/test_post_delete.py) - Remove legacy setup.py (pyproject.toml is sole build config) - Fix README: remove false async-ready claim, add exceptions docs - Full backward compatibility maintained: no public API signature changes
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
Comprehensive SDK modernization covering all 27 endpoint modules, error handling, CI, and test coverage — while maintaining full backward compatibility (no public API signature changes).
Changes
Idiomatic Endpoint Migration (all 27 modules)
_get_headers()+_make_request()calls to idiomaticBaseEndpointhelpers:_get(),_post_json(),_post_form(),_delete()dt_*.pyfile and ensures consistent request handlingStructured Exception Hierarchy
darktrace/exceptions.pywith 8 purpose-built exception classes (BadRequestError,AuthenticationError,ForbiddenError,NotFoundError,RateLimitError,ServerError,ConnectionError, baseDarktraceError) wrappingrequests.HTTPErrorBaseEndpoint._raise_for_status()maps HTTP status codes to specific exceptions for cleaner error handling by SDK consumersCI Improvements
Test Coverage
tests/test_auth.py— 28 HMAC signature generation teststests/test_post_delete.py— 47 POST/DELETE mock teststests/test_mock.pyfor new patternsCleanup
setup.py—pyproject.tomlis now the sole build configurationTest plan
pytest tests/— 168 passed, 3 skipped, 0 failedruff check .— cleanruff format --check .— clean