Visualizing Wikidata with Python
For this project, we used Python to run SPARQL queries against Wikidata and turn the results into interactive visualizations. The main tools are SPARQLWrapper for querying and Plotly for visualization.
Setup
The notebooks were built in Google Colab, so setup is minimal:
from SPARQLWrapper import SPARQLWrapper, JSON
import pandas as pd
sparql = SPARQLWrapper("https://query.wikidata.org/sparql")
Running a Query
After defining a SPARQL query string (see the SPARQL post for examples), you send it to Wikidata and convert the JSON response into a pandas DataFrame: