Package: pymercadopago
PyMercadoPago is user-friendly library to interact with the MercadoPago API. Python 3 only.To install it from PyPI, simply run:pip install pymercadopagoIf you haven’t done so already, obtain yourCLIENT_IDandCLIENT_SECREThere.QuickstartCreate a newmercadopago.Clientinstance and pass it your credentials:importmercadopagoCLIENT_ID='XXX'CLIENT_SECRET='XXX'mp=mercadopago.Client(CLIENT_ID,CLIENT_SECRET)You can navigate the full API from the client methods. Try running the above
code in a Python shell and explore them.# Get the invoice with ID 1234mp.invoices.get('1234')# Get the current user account balancemp.users.account_balance()# Create a new customer instancemp.customers.create(first_name='Federico'last_name='Bond',# ...)In general, assumingmpis amercadopago.Clientinstance and there is
an endpoint documented at (for example)/customersor/v1/customers,
you can do:mp.customers.list()List all customers. Pass pagination parameters via keyword arguments.mp.customers.create(**data)Create a new Customer.mp.customers.delete(id)Delete a Customer.mp.customers.update(**data)Update a Customer, includeìdin your keyword arguments.mp.customers.search(**params)Search for customers matching params.Not all methods are available for all resources, and some additional
convenience methods have been added to some. To learn more, check out the
official docs and/or the code from themercadopago.apimodule.Nested resources like are usually accessed by following the corresponding
resource paths. For example:# GET /v1/customers/:id/cards# ----mp.customers.cards(id).list()All methods return aResponseobject if successful (HTTP status code in the
2XX range) or raise an instance ofmercadopago.Errorotherwise.ResponseEvery API call you make will return aResponseinstance with the following
attributes:AttributeDescriptionstatus_codeThe HTTP status_code returned by the API.dataThe decoded JSON response returned by the API.urlThe requested URL.If MercadoPago returns a response with pagination information, aPaginatedResponsewill be returned instead. Paginated responses have the
following additional methods:response.totalTotal amount of records in this collection.response.limitMaximum number of records for this page.response.offsetNumber of records skipped to reach this page.response.resultsList of records in this request. This is different from.datawhich
contains the full body of the response, with the pagination info.response.has_prev()Whether there are any preceding pages.response.has_next()Whether there are any following pages.response.prev()Requests the previous page and returns aPaginatedResponse.response.next()Requests the next page and returns aPaginatedResponse.response.auto_paging_iter()Returns a generator of records that will automatically request new pages
when necessary.ErrorIf there is a connection error or the HTTP response contains a non-2XX status
code, the method will raise an instance ofmercadopago.Error. The error
object contains the following attributes:AttributeDescriptionhttp_statusThe HTTP status_code returned by the API, if applicable.codeThe error code returned by the API, if applicable.json_dataThe full JSON response returned by the API, if applicable.The specific subclass raised depends on the HTTP status code.StatusClass400mercadopago.BadRequestError401mercadopago.AuthorizationError404mercadopago.NotFoundError*mercadopago.ErrorRunning the testsMake sure tests pass before contributing a bugfix or a new feature.
To run the test suite, execute this in your terminal:python setup.py testThis will execute the tests with your default Python interpreter.
Usetoxto run the tests in all supported Python versions.To DoImplement idempotency headers in POST/PUT requests.Implement retry request from error.For more information about the API, refer to theofficial docs.AuthorFederico BondLicenseApache-2.0