Skip to main content

Mangopay Python SDK

MangopaySDK is a Python client library to work with Mangopay REST API.

Installation

mangopaysdk requires Python >=3.10,<3.15 and the following runtime dependencies:

To install the package:

    pip install mangopay4-python-sdk

By installing this package with pip, all dependencies will be installed for you.

Development install

The project is managed with Poetry. To set up a local development environment:

    poetry install --extras dev

This installs the runtime dependencies as well as the dev extras (test runner, coverage, mocking, TLS helpers) defined in pyproject.toml. The resolved versions are pinned in poetry.lock.

To run the test suite (same command used in CI):

    poetry run coverage run -m unittest discover
    poetry run coverage xml

Test credentials

The test suite reads its MangoPay sandbox credentials from environment variables (no secrets are hardcoded). The suite fails fast with a clear message if any required variable is missing.

Environment variable Description
MANGOPAY_CLIENT_ID Client ID of the primary sandbox test client.
MANGOPAY_CLIENT_PASSWORD API key / password of the primary sandbox test client.
MANGOPAY_CLIENT_ID_2 Client ID of a second sandbox client (used to assert token isolation).
MANGOPAY_CLIENT_PASSWORD_2 API key / password of the second sandbox client.

Documentation

For documentation and examples of usage for the Mangopay API please refer to: API references

See the docs/ directory to find examples.

mTLS certificates

Set the base URL for mTLS

Using mTLS authentication requires your integration to call a base URL with a different hostname from the standard API:

  • Sandbox: https://api-mtls.sandbox.mangopay.com
  • Production: https://api-mtls.mangopay.com

If using mTLS, your integration should use the api-mtls URLs for all API calls, including OAuth token generation.

Caution: Ensure you set the mTLS base URL, as shown in the configuration examples below. If you don’t, the mTLS certificate will not be transferred to Mangopay. When mTLS is enforced, your integration will result in an error.

Configure the SDK’s mTLS properties

The Python SDK allows you to load the .pem and .key file paths in the global configuration or in the per-request handler.

| Property (global / per-request) | Type   | Description                          |
| ------------------------------- | ------ | ------------------------------------ |
| `mtls_cert` / `cert`            | string | Path to the certificate `.pem` file. |
| `mtls_private_key` / `key`      | string | Path to the private `.key` file.     |

Caution: The per-request properties cert and key take precedence if set and the global ones are ignored (mangopay.mtls_cert and mangopay.mtls_private_key).

The certificate files must be accessible at runtime; the SDK does not validate their content at initialization time.

When both are provided, the SDK sets session.cert = (cert, key) on the underlying requests.Session. If a combined certificate is provided (bundling the key), the SDK sets session.cert = cert.

Global configuration

The global properties allow you to set the certificate and key before making any API calls. The certificate is used for all requests made through the default handler.

    import mangopay

    mangopay.client_id = 'your-mangopay-client-id'
    mangopay.apikey = 'your-mangopay-api-key'
    mangopay.api_sandbox_url = 'https://api-mtls.sandbox.mangopay.com/v2.01/'
    sandbox = True
    # mangopay.api_url = 'https://api-mtls.mangopay.com/v2.01/'
    mangopay.mtls_cert = '/path/to/certificate.pem'
    mangopay.mtls_private_key = '/path/to/private.key'

Per-request handler

Caution: The per-request values take precedence over the global values.

Each APIRequest instance maintains its own requests.Session, so mTLS certificates are scoped to that instance and do not leak between handlers.

    from mangopay.api import APIRequest

    handler = APIRequest(
        client_id='your-mangopay-client-id',
        apikey='your-mangopay-api-key',
        api_sandbox_url = 'https://api-mtls.sandbox.mangopay.com/v2.01/' # mTlS base URL
    	sandbox = True
    	# mangopay.api_url = 'https://api-mtls.mangopay.com/v2.01/'
        cert='/path/to/certificate.pem',
        key='/path/to/private.key'
    )

Then pass the handler when making API calls:

    from mangopay.resources import NaturalUser, Wallet

    user = NaturalUser.get(user_id, handler=handler)
    wallet = Wallet.get(wallet_id, handler=handler)

License

MangopaySDK is distributed under MIT license, see LICENSE file.

Inspiration

The data model of python-mangopay is highly inspired by peewee.

Credits

The inital basis of this SDK was generously coded and donated by Ulule

Metadata

Release files for mangopay4-python-sdk 4.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mangopay4-python-sdk 4.4.0
File Size Uploaded Provenance Actions
mangopay4_python_sdk-4.4.0.tar.gz 60.4 kB Without provenance Details for mangopay4_python_sdk-4.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mangopay4-python-sdk 4.4.0
File Interpreter ABI Platform Actions
mangopay4_python_sdk-4.4.0-py3-none-any.whl Python 3 none any Details for mangopay4_python_sdk-4.4.0-py3-none-any.whl

Total release size: 122.9 kB

Release files / mangopay4_python_sdk-4.4.0.tar.gz

Download URL mangopay4_python_sdk-4.4.0.tar.gz
Size 60.4 kB
Tags Source
SHA-256 checksum
How to use checksums
44b38fa933e7525248f5606ca8319cdb714493f5acd2ec66e9f6fc63d09736d0
BLAKE2b-256 checksum
How to use checksums
b5588b46df87d8c0096b1c00f11b2660be098b05a42d2c81317aca399dc80d38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.13 Linux/6.12.94-123.190.amzn2023.x86_64

Release files / mangopay4_python_sdk-4.4.0-py3-none-any.whl

Download URL mangopay4_python_sdk-4.4.0-py3-none-any.whl
Size 62.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63c381f70bbd949177e5b7c1440b553921df30078f680a2c7d39c7b51d5464b6
BLAKE2b-256 checksum
How to use checksums
ec23fffdb0a10f1298b9cbad0b3625e4a1071183acd79172492aa0f66ef76f93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.13 Linux/6.12.94-123.190.amzn2023.x86_64

Security for mangopay4-python-sdk 4.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page