Python
Introduction
The Mangopay Python SDK makes working with the Mangopay API easier in a Python environment. This SDK is open-source and available on GitHub.
Mangopay Python SDKPrerequisites
To run the Mangopay Python SDK, you’ll need:
- A
ClientId
and an API key – if you don’t have these, contact Sales to get access to the Mangopay Dashboard - Python 3.2.5 (or any version until Python 3.11) 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
The configuration object of the SDK supports all the following properties:
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. |
uk_header_flag | boolean | False | Platforms that have contracted with Mangopay’s UK entity (MANGOPAY U.K. LIMITED) must include the following header in all requests. If you’re using an SDK, you need to set it to true . |
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, add idempotency_key
parameter to your function.
For more information, see the Idempotency article.
In order to retrieve the request made using this idempotency:
Pagination
Note - Listing elements
If you do not specify the page
and the per_page
parameters, only the first 10 elements will be displayed.
For endpoints that support pagination, you can use an object containing the 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:
Report an issue
Found a problem with the SDK? Create an issue on GitHub:
Report an issue →