{"library":"mercadopago","title":"Mercado Pago Python SDK","description":"The Mercado Pago SDK for Python provides developers with a simple set of bindings to integrate with the Mercado Pago API and process payments. It is actively maintained with frequent minor releases, currently at version 2.3.0, and simplifies server-side operations like creating and managing payment preferences, processing transactions, and handling refunds or chargebacks.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install mercadopago"],"cli":null},"imports":["import mercadopago\nsdk = mercadopago.SDK(\"YOUR_ACCESS_TOKEN\")","from mercadopago.config import RequestOptions"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport mercadopago\nfrom mercadopago.config import RequestOptions\n\nACCESS_TOKEN = os.environ.get('MERCADO_PAGO_ACCESS_TOKEN', 'YOUR_ACCESS_TOKEN')\n\nif not ACCESS_TOKEN or ACCESS_TOKEN == 'YOUR_ACCESS_TOKEN':\n    print(\"Error: MERCADO_PAGO_ACCESS_TOKEN environment variable is not set or is default.\")\n    print(\"Please set it with your actual Mercado Pago Access Token.\")\nelse:\n    try:\n        sdk = mercadopago.SDK(ACCESS_TOKEN)\n\n        # Example: Create a payment preference\n        preference_data = {\n            \"items\": [\n                {\n                    \"title\": \"My Product\",\n                    \"quantity\": 1,\n                    \"currency_id\": \"BRL\",\n                    \"unit_price\": 75.56\n                }\n            ],\n            \"payer\": {\n                \"email\": \"test_user_123456@testuser.com\"\n            },\n            \"back_urls\": {\n                \"success\": \"https://www.your-site.com/success\",\n                \"failure\": \"https://www.your-site.com/failure\",\n                \"pending\": \"https://www.your-site.com/pending\"\n            },\n            \"auto_return\": \"approved\"\n        }\n\n        # Optional: Per-request configuration for custom headers or different credentials\n        # request_options = RequestOptions()\n        # request_options.custom_headers = { 'X-Idempotency-Key': 'some_unique_value' }\n        # result = sdk.preference().create(preference_data, request_options)\n\n        result = sdk.preference().create(preference_data)\n\n        if result[\"status\"] == 201:\n            preference = result[\"response\"]\n            print(\"Preference created successfully:\")\n            print(f\"ID: {preference['id']}\")\n            print(f\"Init Point: {preference['init_point']}\")\n            print(f\"Sandbox Init Point: {preference['sandbox_init_point']}\")\n        else:\n            print(f\"Error creating preference: {result['status']} - {result['response']}\")\n\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the Mercado Pago SDK with your access token and create a basic payment preference. Replace 'YOUR_ACCESS_TOKEN' with your actual production access token or set it as an environment variable `MERCADO_PAGO_ACCESS_TOKEN` for security. The example creates a checkout preference for a single item and prints the resulting payment links.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}