Skip to content

Commit 2590152

Browse files
committed
Document transport options and add requests extra
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.
1 parent b9e0ecf commit 2590152

3 files changed

Lines changed: 49 additions & 10 deletions

File tree

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,57 @@ your transactions in one place!
2020

2121
## Installation
2222

23-
Here's how to use pip to put the MultiSafepay library into your Python.
23+
If you want to use the built-in default transport, install with the `requests` extra.
24+
25+
```bash
26+
pip install "multisafepay[requests]"
27+
```
28+
29+
If you want to provide your own transport implementation, install the base package.
30+
31+
```bash
32+
pip install multisafepay
33+
```
34+
35+
## HTTP client / transport (optional dependency)
36+
37+
**WARNING:** This SDK does not have a hard dependency on a specific HTTP client.
38+
39+
The SDK uses a small transport abstraction so you can choose (and swap) the underlying HTTP implementation without affecting the rest of your integration.
40+
41+
### How it works
42+
43+
- The SDK expects an object implementing the `HTTPTransport` / `HTTPResponse` protocols defined in `src/multisafepay/transport/http_transport.py`.
44+
- If you do not provide a transport, the SDK defaults to `RequestsTransport`.
45+
- `requests` is an optional extra:
46+
- To use the default transport, install `multisafepay[requests]`.
47+
- To avoid `requests`, inject your own transport (for example, `httpx` or `urllib3`).
48+
49+
### Custom transport example
2450

2551
```bash
2652
pip install multisafepay
2753
```
2854

55+
```python
56+
from multisafepay import Sdk
57+
58+
59+
sdk = Sdk(
60+
api_key="<api_key>",
61+
is_production=False,
62+
transport=my_custom_transport, # must implement HTTPTransport
63+
)
64+
```
65+
66+
See transport examples in `examples/transport/` (`httpx_transport.py`, `urllib3_transport.py`, `request_transport.py`).
67+
2968
## Getting started
3069

3170
### Initialize the client
3271

3372
```python
34-
from multisafepay.sdk import Sdk
73+
from multisafepay import Sdk
3574

3675
multisafepay_sdk: Sdk = Sdk(api_key='<api_key>', is_production=True)
3776
```

poetry.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/multisafepay/transport/requests_transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
def _raise_requests_missing() -> None:
3535
raise ModuleNotFoundError(
3636
"Optional dependency 'requests' is required for RequestsTransport. "
37-
"Install it via 'pip install multisafepay[requests]' (or add the Poetry extra 'requests'), "
37+
"Install it via 'pip install multisafepay[requests]' or 'pip install requests', "
3838
"or pass a custom HTTPTransport implementation to Sdk(..., transport=...).",
3939
) from _REQUESTS_IMPORT_ERROR
4040

0 commit comments

Comments
 (0)