Search code examples
pythonsparqlwikidata-query-service

How to integrate Wikidata query in python


I am currently using Wikidata Query Service to run my Wikidata queries.

For example, one of my Wikidata queries looks as follows.

SELECT ?sLabel {
    SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:api "EntitySearch".
        bd:serviceParam wikibase:endpoint "www.wikidata.org".
        bd:serviceParam mwapi:search "natural language processing".
        bd:serviceParam mwapi:language "en".
        ?item wikibase:apiOutputItem mwapi:item.
        ?num wikibase:apiOrdinal true.
    }
    ?s wdt:P279|wdt:P31 ?item .
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY ?num
LIMIT 10

I would like to know if we can use these queries in a python program? If so, how can we integrate the queries in python?

I am happy to provide more details if needed.


Solution

  • sparqlwrapper can handle that. You can find more information here