Mastercard API Python Core SDK

raw JSON →
1.4.12 verified Fri May 01 auth: no python

Official Mastercard SDK for Python, providing core authentication, encryption, and HTTP client utilities for interacting with Mastercard APIs. Version 1.4.12 is the latest release; updates are periodic.

pip install mastercard-api-core
error ImportError: No module named 'mastercard'
cause Importing using 'mastercard.api' instead of 'mastercard_api_core'.
fix
Change import to: from mastercard_api_core import ApiConfig
error TypeError: __init__() missing 1 required positional argument: 'consumer_key'
cause Omitting required arguments or using only positional arguments (deprecated).
fix
Use keyword arguments: ApiConfig(consumer_key='...', ...)
error FileNotFoundError: [Errno 2] No such file or directory: 'mykey.p12'
cause The p12_path points to a file that does not exist or the path is relative from the wrong working directory.
fix
Provide an absolute path to the .p12 file, e.g., os.path.abspath('mykey.p12').
error requests.exceptions.SSLError: SSL: CERTIFICATE_VERIFY_FAILED
cause Missing or invalid CA bundle or the server certificate is self-signed in test environment.
fix
Set environment variable REQUESTS_CA_BUNDLE to a PEM file, or use verify=False (not recommended for production).
gotcha The package name on PyPI is 'mastercard-api-core', but the import uses underscores: 'mastercard_api_core'. Using hyphens in import will fail.
fix Use 'pip install mastercard-api-core' and then 'import mastercard_api_core'.
deprecated Support for Python 3.6 and 3.7 may be dropped in future versions; current version is tested on 3.8+.
fix Upgrade to Python 3.8 or higher.
gotcha The SDK expects a .p12 file for mutual TLS authentication. Provide the path to the file, not the raw string content.
fix Set 'p12_path' to the file path, not the base64 or string content.
breaking In version 1.4.0, the API client initialization changed from positional arguments to keyword arguments. Direct instantiation without keyword arguments will raise TypeError.
fix Use keyword arguments: ApiConfig(consumer_key=..., key_file_path=..., p12_path=...).

Initialize the SDK with a configuration object from environment variables and make an authenticated GET request.

import os
from mastercard_api_core import ApiConfig, MasterCardApi

config = ApiConfig(
    consumer_key=os.environ.get('MASTERCARD_CONSUMER_KEY', ''),
    key_file_path=os.environ.get('MASTERCARD_KEY_FILE_PATH', ''),
    p12_path=os.environ.get('MASTERCARD_P12_PATH', '')
)
api = MasterCardApi(config)
# Example: get a resource (generic, adjust per API)
response = api.get('/api/v1/resource')
print(response.status_code, response.json())