Introduction
The Mangopay Python SDK makes working with the Mangopay API easier in a Python environment. The SDK package is available on Pythony Package Index (PyPI): mangopay4-python-sdkPrerequisitesTo run the Mangopay Python SDK, you’ll need:
- A
ClientIdand an API key – if you don’t have these, contact Sales to get access to the Mangopay Dashboard - Python 3.13 (recommended) down to 3.9 (not recommended) installed:
- pip package manager
- requests library
- blinker library
Getting started
1. Install the SDK
By installing this package with pip3, all dependencies are installed for you:2. Initialize and configure the SDK
| Key | Type | Default value | Description |
|---|---|---|---|
client_id | string | None | Your Mangopay ClientId – can be found in the Dashboard. |
apiKey | string | None | Your Mangopay API key – can be found in the Dashboard. |
api_url | string | https://api.mangopay.com/ | The API production URL. |
api_sandbox_url | string | https://api.sandbox.mangopay.com/v2.01/ | The API sandbox URL. |
sandbox | boolean | None | To set it to Sandbox, set it as True. To set it to Production, set it as False. |
timeout | float | 30.0 | Request timeout in seconds. |
storage_strategy | string | StaticStorageStrategy() | Mechanism of how the caching works. There are 2 options: StaticStorageStrategy() for in-memory cache and FileStorageStrategy() for file-based cache. |
proxies | string | None | Dictionary mapping protocol or protocol and host name to the URL of the proxy. |
SDK usage
All endpoints are documented with the related Python SDK method throughout the Mangopay documentation. You should adjust the code examples provided for your usage.API handler
When creating a new handler, there are multiple settings to specify depending on your needs.Proxy support
You can use proxies for https, http and ftp protocols:Storage strategy
There are two storage strategies that can be used for OAuth tokens:StaticStorageStrategy()saves the token in memory. If no storage strategy is specified, this method is used by default.FileStorageStrategy()saves the token in a temporary file.
Requests timeout
You can set the amount of time in seconds after that the requests will timeout:Idempotency support
To make a request with idempotency support, addidempotency_key parameter to your function.
For more information, see the Idempotency article.
Call - Create a payout with an idempotency key
Call - View an API response using idempotency key
Output
Pagination
Note - Listing elementsIf you do not specify the
page and the per_page parameters, only the first 10 elements will be displayed.page and per_page keys.
As a result, the output is paginated, and the total number of items and the total number of pages is provided.
For example, with the List all Users endpoint:
Filtering
For endpoints that support filtering, you can use an object containing the filtering parameters. For example, with the List Transaction for a Wallet endpoint:Error handling
The SDK provides theAPIError class to wrap HTTP errors returned by the API. You can use a Python try block and exception blocks to handle API errors, for example: