PTHMINT-94: Introduce HTTPTransport interface to decouple HTTP Client#50
Merged
PTHMINT-94: Introduce HTTPTransport interface to decouple HTTP Client#50
Conversation
Add a pluggable HTTP transport layer so callers can inject custom HTTP clients. Introduces src/multisafepay/transport (HTTP transport interface, RequestsTransport and underlying http transport), updates SDK and client to accept/select a transport, and adds example transports for httpx, requests.Session and urllib3 (including a response adapter). Includes new unit/e2e tests and test helpers for transport selection and mocks, plus minor README/pyproject tweaks.
Annotate client methods' context parameter as Optional[dict[str, Any]] and standardize parameter/type annotations in HTTPTransport and RequestsTransport docstrings (consistently use parenthetical param types and shorter, PEP-484-like type expressions). These edits improve typing clarity and make the transport docs consistent and easier to read.
Add copyright, Open Software License (OSL) v3.0 and disclaimer header comments to several test and support modules for legal/attribution purposes. Affected files: tests/multisafepay/e2e/examples/transport/test_custom_httpx_transport.py, tests/multisafepay/e2e/examples/transport/test_custom_requests_session_transport.py, tests/multisafepay/e2e/examples/transport/test_custom_urllib3_transport.py, tests/multisafepay/unit/transport/test_unit_transport_selection.py, tests/support/alt_http_transports.py, tests/support/mock_transport.py. No functional code changes.
Expand README with an optional HTTP transport section detailing the transport abstraction, how to use the built-in RequestsTransport (multisafepay[requests]) or provide a custom transport, and a small example. Update example import to use from multisafepay import Sdk. Tweak RequestsTransport's ModuleNotFoundError message to also suggest installing requests directly. Update poetry.lock to reflect the new optional extra and lockfile checksum.
danielcivit
approved these changes
Mar 5, 2026
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.
This pull request refactors the MultiSafepay Python SDK to introduce a flexible HTTP transport abstraction, allowing users to choose or inject their preferred HTTP client (such as
requests,httpx, orurllib3). The default dependency onrequestsis now optional, and the SDK can be used with custom transports. The documentation and examples have been updated to guide users through these new options.Transport Abstraction & SDK Refactor
requests.Sessiondependency inClientandSdkclasses with a genericHTTPTransportinterface, allowing custom transport implementations. The SDK now defaults toRequestsTransportonly if no transport is provided. (src/multisafepay/client/client.py,src/multisafepay/sdk.py,src/multisafepay/transport/__init__.py) [1] [2] [3] [4] [5] [6] [7] [8]Dependency Management
requestsan optional dependency inpyproject.toml, introduced arequestsextra for users who want the default transport, and updated dev dependencies to includepython-dotenv,requests,urllib3, andhttpxfor testing and examples. (pyproject.toml) [1] [2]Documentation Updates
README.mdto explain the new transport abstraction, installation options, and how to use custom HTTP clients. Added detailed instructions and code snippets for injecting custom transports. (README.md)Example Implementations
httpx,urllib3, and customrequests.Sessionwith retry logic, demonstrating how to inject them into the SDK. (examples/transport/httpx_transport.py,examples/transport/urllib3_transport.py,examples/transport/request_transport.py) [1] [2] [3]Code Cleanups
__all__declarations for clarity and consistency. (src/multisafepay/__init__.py)