Skip to main content

Mercado Pago SDK for Python

PyPI PyPI Downloads APM

This library provides developers with a simple set of bindings to help you integrate Mercado Pago API to a website and start receiving payments.

💡 Requirements

Python 3.9 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, OrderPayerRequest
from mercadopago.resources.order_item import OrderItemRequest

sdk = mercadopago.SDK("YOUR_ACCESS_TOKEN")

order = OrderCreateRequest(
    type="online",
    total_amount="100.00",
    external_reference="ext_ref_1234",
    payer=OrderPayerRequest(email="test_user_123456@testuser.com"),
    items=[OrderItemRequest(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

Visit our Dev Site for further information regarding:

Check our official code reference to explore all available functionalities.

🤝 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mercadopago-3.5.0.tar.gz (67.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mercadopago-3.5.0-py3-none-any.whl (81.3 kB view details)

Uploaded Python 3

File details

Details for the file mercadopago-3.5.0.tar.gz.

File metadata

  • Download URL: mercadopago-3.5.0.tar.gz
  • Upload date:
  • Size: 67.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for mercadopago-3.5.0.tar.gz
Algorithm Hash digest
SHA256 11268a28d8a14758fbabdc895a7aa4869c6d5dbbe878dcd3f982000172e5b78e
MD5 d196351eefa012fe7ad2cc86ef5156e9
BLAKE2b-256 f6bbc88df5e7dcc0531f31a722e7d23297dd03328b5c701e780b07cea0d756f6

See more details on using hashes here.

File details

Details for the file mercadopago-3.5.0-py3-none-any.whl.

File metadata

  • Download URL: mercadopago-3.5.0-py3-none-any.whl
  • Upload date:
  • Size: 81.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for mercadopago-3.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c40dc5d24365807c155234a6d6ed28672d1d29c75c6c9ec58d7ae94d9ba5c68f
MD5 aeb463094fcdb0a695ee99614a339100
BLAKE2b-256 fbee360c261e9c2acc26d5860d1592baf3c1823493500230e709037e9bcdff75

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.5.0 This release

2 files

3.4.0

2 files

3.3.1

2 files

3.3.0

2 files

3.2.0

2 files

3.1.1

2 files

3.1.0

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.4.0

2 files

2.3.0

2 files

2.2.3

2 files

2.2.2

1 file

2.2.1

2 files

2.2.0

3 files

2.1.0

2 files

2.0.10

2 files

2.0.9

2 files

2.0.8

2 files

2.0.7

2 files

2.0.6

2 files

1.2.1

2 files

1.2.0

2 files

1.1.1

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.8

2 files

0.1.5

0.0.2

1 file

0.0.1

1 file

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