In [ ]:
import pywikibot
from pywikibot import pagegenerators
import requests
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
with open('lexemes.rq', 'r') as query_file:
    QUERY = query_file.read().replace('\n', '')

generator = pagegenerators.WikidataSPARQLPageGenerator(QUERY, site=repo)
for item in generator:
    item_dict = item.get()
    print(item_dict)