https://www.mediawiki.org/wiki/API:Opensearch

def wikipedia_search(query, lang="en", max_result=1):
    """
        https://www.mediawiki.org/wiki/API:Opensearch
    """
    query = any2unicode(query)
    params = {
        "action":"opensearch",
        "search": query,
        "format":"json",
        #"formatversion":2,
        #"namespace":0,
        "suggest":"true",
        "limit": 10
    }
    urlBase = "https://{}.wikipedia.org/w/api.php?".format(lang)
    url = urlBase + urllib.urlencode(any2utf8(params))
    #logging.info(url)
    r = requests.get(url)
    jsonData = json.loads(r.content)
    #logging.info(jsonData)

    items = []
    ret = {"query":query, "itemList":items}
    for idx, label in enumerate(jsonData[1][0:max_result]):
        description = jsonData[2][idx]
        url = jsonData[3][idx]

        item = {
            "name": label,
            "description":description,
            "url": url,
        }
        items.append(item)

    return ret