Giter VIP home page Giter VIP logo

meli-python-sdk's Introduction

MercadoLibre's Python SDK

Python SDK for MercadoLibre's Platform.

NOTE: we DO NOT have any rights on Mercado Libre trademark. This work is just to contribute to the Open Source community using public MeLi APIs.

How do I install it?

1) Download or clone repository 
   https://github.com/joacoRamone/meli-python-sdk.git
2) cd meli-pythonSDK
3) python setup.py install

NOTE: it requires requests>=1.1.0

Design considerations

This module has two main components:

How do I use it?

We use MeliPy in our Django projects, but it also integrates within any other framework out there (tested in Web2Py, for instance).

Create an instance of MeliCore class

CLIENT_ID = 'your app id'
CLIENT_SECRET = 'your app secret'

meli = MeliCore(client_id=CLIENT_ID,client_secret=CLIENT_SECRET)

You can create an instance of MeliCore without client credentials, but on this case you'll be not allowed to call resources where access token is required.

Authorization

meli-python-sdk provides the server side authorization using OAuth2. For more details see http://developers.mercadolibre.com/authentication-and-authorization/

Step 1: Obtain a code

auth_url = meli.get_auth_url("your_redirect_URI")

If the user grants your application the requested data permission the OAuth Dialog will redirect the user's browser to the URL you specified in the redirect_url together with an authorization code. This redirect uses the HTTP 302 status code. The URL will look like this:

http://YOUR_URL?code=SERVER_GENERATED_AUTHORIZATION_CODE

Catch this URL and get the SERVER_GENERATED_AUTHORIZATION_CODE to use it in next step.

Step 2: Exchange the code for a token

By using this code you can perform the next step: app authentication.

meli.authorize(SERVER_GENERATED_AUTHORIZATION_CODE, redirect_URI="your_redirect_URI")

Calling resources

All calls to MELi resources are executed by generic query_url() method. This returns a JSONobject. Some examples:

GET method

categories = meli.query_url(resource_part=meliresources.CATEGORY_DETAILS,
                                    method='GET',
                                    ids={'categ_id':category},
                                    attributes=['name','children_categories'])
print categories

POST method

# add new description example
item_id = 'item id'
body = {'text':'new description'}
result = meli.query_url(resource_part=meliresources.ITEM_DESCRIPTION,
                                    method='POST',
                                    ids={'item_id':item_id},
                                    access_token=True,  # we need the access token for data update
                                    body=body)
print result

PUT method

# add one payment method
USERID = 'user id'
body = {'id':'redlink',
        'name':'RedLink',
        'payment_type_id':'atm',
        'thumbnail':'http://img.mlstatic.com/org-img/MP3/API/logos/redlink.gif',
        'secure_thumbnail':'https://www.mercadopago.com/org-img/MP3/API/logos/redlink.gif'}
result = meli.query_url(resource_part=meliresources.USER_PAYMENT_METHODS_DETAILS,
                                 method='PUT',
                                 ids={'user_id':USERID,'pay_id':'redlink'},
                                 access_token=True,  # we need the access token for data update
                                 body=body)
print result

DELETE method

# remove one payment method
USERID = 'user id'
result = meli.query_url(resource_part=meliresources.USER_PAYMENT_METHODS_DETAILS,
                                     method='DELETE',
                                     ids={'user_id':USERID,'pay_id':'redlink'},
                                     access_token=True)  # we need the access token for data update
print result

Contribution

Feel free to get the code and play around with it. Any contribution is fully appreciated.

Contact

  • Joaquin Orbe
  • e-mail: joaquinorbe (at) gmail (dot) com
  • Twitter: @joacOrbe

License

See LICENSE.txt

meli-python-sdk's People

Contributors

joaquinorbe avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.