Coder Social home page Coder Social logo

python-sdk's Introduction

No longer maintained

[DEPRECATED] This repository is no longer maintained

From the first week of April 2021 we will stop maintaining our SDKs.

This project is not functional, the dependencies will not be updated to latest ones.

We recommend you read our documentation.

Mercado Libre Developers

Mercado Libre Developers

MercadoLibre's Python SDK

This is the official Python SDK for MercadoLibre's Platform.

Requirements.

Python 2.7 and 3.4+

Installation

pip install

If the python package is hosted on a repository, you can install directly using:

pip install git+https://github.com/mercadolibre/python-sdk.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/mercadolibre/python-sdk.git)

Then import the package:

import meli

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import meli

Usage

# Auth URLs Options by country

# 1:  "https://auth.mercadolibre.com.ar"
# 2:  "https://auth.mercadolivre.com.br"
# 3:  "https://auth.mercadolibre.com.co"
# 4:  "https://auth.mercadolibre.com.mx"
# 5:  "https://auth.mercadolibre.com.uy"
# 6:  "https://auth.mercadolibre.cl"
# 7:  "https://auth.mercadolibre.com.cr"
# 8:  "https://auth.mercadolibre.com.ec"
# 9:  "https://auth.mercadolibre.com.ve"
# 10: "https://auth.mercadolibre.com.pa"
# 11: "https://auth.mercadolibre.com.pe"
# 12: "https://auth.mercadolibre.com.do"
# 13: "https://auth.mercadolibre.com.bo"
# 14: "https://auth.mercadolibre.com.py"

# For example in your app, you can make some like this to get de auth
import urllib

params = urllib.urlencode({'response_type':'code', 'client_id':'your_client_id', 'redirect_uri':'your_redirect_uri'})
f = urllib.urlopen("https://auth.mercadolibre.com.ar/authorization?%s" % params)
print f.geturl()

his will give you the url to redirect the user. You need to specify a callback url which will be the one that the user will redirected after a successfull authrization process.

Once the user is redirected to your callback url, you'll receive in the query string, a parameter named code. You'll need this for the second part of the process

Examples for OAuth - get token

from __future__ import print_function
import time
import meli
from meli.rest import ApiException
from pprint import pprint
# Defining the host, defaults to https://api.mercadolibre.com
# See configuration.py for a list of all supported configuration parameters.
configuration = meli.Configuration(
    host = "https://api.mercadolibre.com"
)


# Enter a context with an instance of the API client
with meli.ApiClient() as api_client:
# Create an instance of the API class
    api_instance = meli.OAuth20Api(api_client)
    grant_type = 'authorization_code' # str
    client_id = 'client_id_example' # Your client_id
    client_secret = 'client_secret_example' # Your client_secret
    redirect_uri = 'redirect_uri_example' # Your redirect_uri
    code = 'code_example' # The parameter CODE
    refresh_token = 'refresh_token_example' # Your refresh_token

try:
    # Request Access Token
    api_response = api_instance.get_token(grant_type=grant_type, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, code=code, refresh_token=refresh_token)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling OAuth20Api->get_token: %s\n" % e)

Example using the RestClient with a POST Item

from __future__ import print_function
import time
import meli
from meli.rest import ApiException
from pprint import pprint
# Defining the host, defaults to https://api.mercadolibre.com
# See configuration.py for a list of all supported configuration parameters.
configuration = meli.Configuration(
    host = "https://api.mercadolibre.com"
)


# Enter a context with an instance of the API client
with meli.ApiClient() as api_client:
    # Create an instance of the API class
    api_instance = meli.RestClientApi(api_client)
    resource = 'resource_example' # A resource like items, search, etc
    access_token = 'access_token_example' # Your access token

    # A body example to post a item in Argentina
    body = {
      "title": "Item de test - No Ofertar",
      "category_id": "MLA5991",
      "price": "350",
      "currency_id": "ARS",
      "available_quantity": "12",
      "buying_mode": "buy_it_now",
      "listing_type_id": "bronze",
      "condition": "new",
      "description": "Item de Teste. Mercado Livre SDK",
      "video_id": "RXWn6kftTHY",
      "pictures": [
        {
          "source": "https://http2.mlstatic.com/storage/developers-site-cms-admin/openapi/319968615067-mp3.jpg"
        }
      ],
      "attributes": [
        {
          "id": "DATA_STORAGE_CAPACITY",
          "name": "Capacidad de almacenamiento de datos",
          "value_id": "null",
          "value_name": "8 GB",
          "value_struct": {
            "number": 8,
            "unit": "GB"
          },
          "values": [
            {
              "id": "null",
              "name": "8 GB",
              "struct": {
                "number": 8,
                "unit": "GB"
              }
            }
          ],
          "attribute_group_id": "OTHERS",
          "attribute_group_name": "Otros"
        }
      ],
      "variations": [
        {
          "price": 350,
          "attribute_combinations": [
            {
              "name": "Color",
              "value_id": "283165",
              "value_name": "Gris"
            }
          ],
          "available_quantity": 2,
          "sold_quantity": 0,
          "picture_ids": [
            "882629-MLA40983876214_032020"
          ]
        }
      ]
    }

    try:
        # Resourse path POST
        api_response = api_instance.resource_post(resource, access_token, body)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling RestClientApi->resource_post: %s\n" % e)

Documentation & Important notes

The URIs are relative to https://api.mercadolibre.com
The Authorization URLs (set the correct country domain): https://auth.mercadolibre.{country_domain}
All docs for the library are located here
Check out our examples codes in the folder examples
Don’t forget to check out our developer site

python-sdk's People

Contributors

adrianbeloqui avatar diazmartin avatar fjcapdevila avatar ldelelis avatar lifacciolo avatar phaael avatar pmolina avatar prenzier avatar williamd1k0 avatar yokomizor avatar zeusmode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-sdk's Issues

hello guys, i need some help

hello guys, i need some help, can i use this API without a website? i wanned to make an local app with pyqt5, and connect to the API, can i do that?

ERROR 400 Backslash problem Replacement of / with %2F (SOLVED temporarily)

Hi !

I have a problem when i try:

resource=orders/search/recent?seller=$SELLER_ID

this:
https://api.mercadolibre.com/orders/search/recent?seller=$SELLER_ID&access_token=$ACCESS_TOKEN
became this:
https://api.mercadolibre.com/orders%2Fsearch%2Frecent%3Fseller%3D$SELLER_ID
and throw error 400 (backslash problem)

SOLVED editing in file: rest.py

url=url.replace("%2F",'/')
url=url.replace("%3F",'?')
url=url.replace("%3D",'=')

saludos

Not Python3 compatible

This line is not Python3 compatible... why you still using Python2 in mind?

raise Exception, "Offline-Access is not allowed."

Refer to existing #11 and #23 (and pull request #31) which does not have any response at all.

This seems like a very "abandoned/not care" SDK...

Timeout

Bom dia,

Ativei o envio de notificações para a minha aplicação.
No começo estava recebendo timeout quando consultava o feed e não recebia os POST´s das notificações.
Depois de um dia ou dois passei a receber OK os POST´s, porém com reqtime elevado, cerca de 2~3s mesmo que eu estivesse tratando e enviando 200 imediatamente.
Agora voltou a dar timeout.
Alguém já passou por isto?
Minha aplicação está rodando no raspberry pi na empresa, utilizando dns do google domains na rede da Vivo.

Subi um serviço da Clouflare chamado Workers, e redirecionei as notificações para lá apenas para testar se desta vez funciona ok.

Obrigado.

Support no longer available? Problema at GET myfeeds

Hi, tried to open a new ticket at support.
But receive the message that is only for partners now.
It´s true? How can I became partner?

I would like to ask about GET on myfeeds, I´m receiving [] at return.

Issue on generating the token

Hi,

I tried to call authorize function for generating the token founding the error below.

Can you please help me on it.

Thanks
Arpit

meli.authorize('TG-5a58c14fe4b0ff39be25d772-295295916', redirect_URI="https://bb6b4a5f.ngrok.io")
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/melipy/core.py", line 49, in inner
File "build/bdist.linux-x86_64/egg/melipy/core.py", line 89, in authorize
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 840, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.mercadolibre.com/oauth/token?code=TG-5a58c14fe4b0ff39be25d772-295295916&client_secret=Fn9k3FXuyPw921whwdtXJDAbGp2Ax4t9&grant_type=authorization_code&client_id=5961429306344932&redirect_uri=https%3A%2F%2Fbb6b4a5f.ngrok.io

Issue In Redirect URI

Hi,

I have an issue related with redirect uri. currently i am trying to integrate my application which is running on my local with url 'http://localhost:8069' .

Error: i am getting RedirectURI is not define.

Can you please provide some suggesation on how can i define the redirect URI while calling the auhorize function of mercadolibre. and application i already created on mercadolibre.

Thanks

Problem redirect getting authorization token

When i try to run the example of the authorization code it redirect me into a login page like this one:
https://www.mercadolibre.com/jms/mla/lgz/login/?go=https%3A%2F%2Fauth.mercadolibre.com.ar%2Fauthorization%3Fclient_id%3D479%26redirect_uri%3Durl.com.ar%26response_type%3Dcode&platform_id=ml&application_id=479939650732
This one contains fake parameters, but is where https://auth.mercadolibre.com.ar/authorization requesting this url leads me.
Is there a way to make that login with a request?
For the moment i solved it using Selenium, but i think is no the best way.

Please, make this Python 3 compatible

Hi!,

I think the code should be more compatible with Python3 these days, since Python2 "only" is getting old...

Also seems this SDK is the "less maintained" than all others SDK offered by ML...

Using resource_get for currency_conversion, classified_locations and other modules

When resource_get for currency_conversion, classified_locations and other modules:

def get_local_currency_by_country_id( country_id ):

	query = "/classified_locations/countries/{}".format( country_id )

	try:

		response = api_instance.resource_get(query, CLIENT_SECRET)

		return json.dumps( response )

	except ApiException as e:

		pass

	return None

I get the following error message:

{"message":"{\"message\":\"Malformed access_token: MY-SECRET-TOKEN TEST\",\"error\":\"bad_request\",\"status\":400,\"cause\":[]}","error":"","status":400,"cause":[]}

Uploading images using python-sdk's resource_post

How do I pass the "content-type" and "file" parameters using the .resource_post method?
As in :

curl -X POST  -H 'Authorization: Bearer $ACCESS_TOKEN'  \
-H 'content-type: multipart/form-data' \
-F 'file=@FILE' \
https://api.mercadolibre.com/pictures/items/upload

Better support for files upload

Since this API SDK is using requests, I think would be better to post files as requests way: http://docs.python-requests.org/en/master/user/quickstart/#post-a-multipart-encoded-file

Using this method, requests will send a multipart/form-data.

EDIT: temporary I had to create a own method by using pycurl (which works), since using requests (from this API) and param files (added to the post method), the response status is 500.

The code for pycurl: https://stackoverflow.com/a/53547438/6696269

No apparent way of passing extra headers to get method

With the implementation of the shopping cart coming soon, we need to pass the extra header x-format-new: true to be able to parse the new orders JSON. However, there doesn't seem to be a way to do this at the moment of writing this.

get_access_token performs unnecessary requests to oauth service

The oauth service returns:

{"access_token":"APP_USR-35766...90-102411-54bb20457...c10b5a230138dec__D_A__-108758138",
"token_type":"bearer",
"expires_in":10800,
"scope":"offline_access read write",
"refresh_token":"TG-5269...b0a34eb0ddf3a9"}

The access_token has an expiration (10800), at least during that time it shouldn't be necessary to send a new POST to the oauth service and get the token again. Implementing this will lower the load of MELI's oauth service and make the python-sdk faster to use since for most actions it's sending 2 HTTP requests (oauth+real action) and if the expiration is taken into account only 1 HTTP request will be sent in most cases.

Absolute changes of this SDK without any notice

As I can see, the code has changed absolutely and no notice even in readme.md so now many old issues will die in the air.

What is going on with you guys at Mercado Libre? That bad is the developers team organization and you don't event know how software development steps must be?

I just notice this and that now (for better) is a python package. You should be more informative about this big change (I don't event know when this happened. Just browsing this repos is there was any changes, just by chance).

Put your house in order ML...

is there a way to get an article search ?.

Hi everyone
I would like to know if there is a way to consult the API and obtain for example a property search, or some sports article. I would also like to get sales and visits. I use anaconda and Jupyternotebook, python 3. Can anyone help me?

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.