Skip to main content
Mercado Pago

Mercado Pago SDK for Python

The official Mercado Pago SDK for Python applications.

Integrate Mercado Pago APIs into your Python application and start receiving payments.

CI status PyPI package version Python 3.10 or later MIT license

Installation · Getting started · Documentation · Contributing


💡 Requirements

Python 3.10 or higher.

📲 Installation

Run pip3 install mercadopago

🌟 Getting Started

First time using Mercado Pago? Create your Mercado Pago account.

Copy your Access Token in the credentials panel and replace the text YOUR_ACCESS_TOKEN with it.

Simple usage — Orders API

The Orders API (/v1/orders) is the recommended way to accept payments. sdk.order().create() accepts either a plain dict or the optional typed request dataclasses (OrderCreateRequest and friends). Both routes produce the exact same JSON body.

import mercadopago

sdk = mercadopago.SDK("YOUR_ACCESS_TOKEN")

request_options = mercadopago.config.RequestOptions()
request_options.custom_headers = {
    'x-idempotency-key': '<SOME_UNIQUE_VALUE>'
}

order_data = {
    "type": "online",
    "total_amount": "100.00",
    "external_reference": "ext_ref_1234",
    "transactions": {
        "payments": [
            {
                "amount": "100.00",
                "payment_method": {
                    "id": "master",
                    "type": "credit_card",
                    "token": "CARD_TOKEN",
                    "installments": 1,
                },
            }
        ]
    },
    "payer": {
        "email": "test_user_123456@testuser.com"
    },
}
result = sdk.order().create(order_data, request_options)
order = result["response"]

print(order)

Typed request classes (optional)

Instead of a dict, you can build the request with the typed dataclasses. None fields are omitted from the JSON body automatically, matching the dict route.

import mercadopago
from mercadopago.resources.order_create import OrderCreateRequest
from mercadopago.resources.payer import PayerRequest
from mercadopago.resources.item import ItemRequest

sdk = mercadopago.SDK("YOUR_ACCESS_TOKEN")

order = OrderCreateRequest(
    type="online",
    total_amount="100.00",
    external_reference="ext_ref_1234",
    payer=PayerRequest(email="test_user_123456@testuser.com"),
    items=[ItemRequest(title="A book", unit_price="100.00", quantity=1)],
)

result = sdk.order().create(order)
print(result["response"])

For a complete recurring / Automatic Payments example (stored credential, subscription data, integration data), see examples/order/create_order_automatic_payment.py.

Creating a payment (legacy Payments API)

import mercadopago

sdk = mercadopago.SDK("YOUR_ACCESS_TOKEN")

request_options = mercadopago.config.RequestOptions()
request_options.custom_headers = {
    'x-idempotency-key': '<SOME_UNIQUE_VALUE>'
}

payment_data = {
    "transaction_amount": 100,
    "token": "CARD_TOKEN",
    "description": "Payment description",
    "payment_method_id": 'visa',
    "installments": 1,
    "payer": {
        "email": 'test_user_123456@testuser.com'
    }
}
result = sdk.payment().create(payment_data, request_options)
payment = result["response"]

print(payment)

Per-request configuration

All methods that make API calls accept an optional RequestOptions object. This can be used to configure some special options of the request, such as changing credentials or custom headers.

import mercadopago
from mercadopago.config import RequestOptions

request_options = RequestOptions(access_token='YOUR_ACCESS_TOKEN')
# ...

result = sdk.payment().create(payment_data, request_options)
payment = result["response"]

📚 Documentation

  • SDK guides: configuration, errors, retries, pagination, and webhooks.
  • Examples: runnable integration flows supported by this SDK.
  • API resources: SDK clients and their common operations.
  • API reference: request fields and response schemas.

🤝 Contributing

All contributions are welcome, ranging from people wanting to triage issues, others wanting to write documentation, to people wanting to contribute code.

Please read and follow our contribution guidelines. Contributions not following this guidelines will be disregarded. The guidelines are in place to make all of our lives easier and make contribution a consistent process for everyone.

❤️ Support

If you require technical support, please contact our support team at developers.mercadopago.com.

🏻 License

MIT license. Copyright (c) 2021 - Mercado Pago / Mercado Libre
For more information, see the LICENSE file.

Metadata

Release files for mercadopago 3.6.1

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

Source distribution (sdist)

Source distribution for mercadopago 3.6.1
File Size Uploaded Provenance Actions
mercadopago-3.6.1.tar.gz 68.0 kB Without provenance Details for mercadopago-3.6.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mercadopago 3.6.1
File Interpreter ABI Platform Actions
mercadopago-3.6.1-py3-none-any.whl Python 3 none any Details for mercadopago-3.6.1-py3-none-any.whl

Total release size: 149.7 kB

Release files / mercadopago-3.6.1.tar.gz

Download URL mercadopago-3.6.1.tar.gz
Size 68.0 kB
Tags Source
SHA-256 checksum
How to use checksums
03a306111cabb8398926ee60450db871e2facdf37db545303df19112ef789964
BLAKE2b-256 checksum
How to use checksums
f9af4dc0f15cc5dad12497a14b6ea7ca0266b5e4ae605e18315b0e9faed6e62f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mercadopago-3.6.1-py3-none-any.whl

Download URL mercadopago-3.6.1-py3-none-any.whl
Size 81.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10510d8c000e9863a2e9ab238e16f0fabea658b200c4baf93f6e7d32fdb2cb79
BLAKE2b-256 checksum
How to use checksums
86a80b3f52eec24725ac4d44cad58443a648c78cc35365978696a9fbe7bcf54d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.16

Security for mercadopago 3.6.1

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.

Release history Release notifications | RSS feed

This release

3.6.1 This release

2 release files No provenance

0.1.5

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