Skip to content

PTHMINT-94: Introduce HTTPTransport interface to decouple HTTP Client#50

Merged
zulquer merged 6 commits intomasterfrom
PTHMINT-94
Mar 5, 2026
Merged

PTHMINT-94: Introduce HTTPTransport interface to decouple HTTP Client#50
zulquer merged 6 commits intomasterfrom
PTHMINT-94

Conversation

@zulquer
Copy link
Collaborator

@zulquer zulquer commented Mar 5, 2026

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, or urllib3). The default dependency on requests is 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

  • Replaced the fixed requests.Session dependency in Client and Sdk classes with a generic HTTPTransport interface, allowing custom transport implementations. The SDK now defaults to RequestsTransport only 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

  • Made requests an optional dependency in pyproject.toml, introduced a requests extra for users who want the default transport, and updated dev dependencies to include python-dotenv, requests, urllib3, and httpx for testing and examples. (pyproject.toml) [1] [2]

Documentation Updates

  • Updated README.md to 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

  • Added new example transport implementations for httpx, urllib3, and custom requests.Session with 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

  • Minor code improvements and cleanups, such as updating imports, type hints, and __all__ declarations for clarity and consistency. (src/multisafepay/__init__.py)

zulquer and others added 6 commits March 3, 2026 14:15
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 danielcivit changed the title Pthmint 94 PTHMINT-94: Introduce HTTPTransport interface to decouple HTTP Client Mar 5, 2026
@zulquer zulquer merged commit ee15a54 into master Mar 5, 2026
12 checks passed
@zulquer zulquer deleted the PTHMINT-94 branch March 5, 2026 16:23
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