SPARQL Playground (RDF Playground)

About the tool

This interactive tool allows you to experiment with running SPARQL queries against RDF datasets. You can use SPARQL federation to effectively join in the data from external SPARQL endpoints.

Despite it using Python-based RDFLib for its core functionality, this tool runs entirely in the browser thanks to Pyodide.

Demo

The RDF dataset to query.
The SPARQL query to execute.
Press the Run query button to execute the query.

What are SPARQL and RDF?

The Resource Description Framework (RDF) is a format for structured data that uses triples to represent information. A set of RDF triples, a.k.a. an RDF dataset, can be stored in a database or file and queried using the SPARQL query language (similar to how SQL works for relational databases).

What is SPARQL federation?

Federation is one of the key features of SPARQL that allows you to extend your queries to external data sources on the web and combine the results with your local data. This is done using the SERVICE keyword in SPARQL queries.

Here's a simple example of a federated query that retrieves additional data from an external endpoint:

PREFIX ex: <http://example.org/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?friend ?friendOfFriend
WHERE {
ex:Alice foaf:knows ?friend .

SERVICE <http://thirdparty.org/sparql> {
?friend foaf:knows ?friendOfFriend .
}
}

Motivation

I believe that there is a lot of untapped potential in RDF/SPARQL and RDF-based knowledge graphs to solve complex data problems, so I built this as an interative demo/showcase for the power and elegance of these technologies. With this online playground, it is super easy to run one-off, ad-hoc, experimental SPARQL queries, and this is what I think makes the tool special.

In addition to being a playground, this tool can also be used to learn about RDF and SPARQL or to troubleshoot production queries. My focus will remain on making this tool as simple and engaging as possible, and I'm open to feedback and suggestions for improvements.

How does it work?

This tool is built on top of RDFLib, a Python library that provides a simple way to manipulate and query RDF using SPARQL. I'm also using Pyodide to move the entire tool to the browser to remove server-side dependencies and simplify the deployment process. I had to slightly customize RDFLib to make it work with browser-initiated network requests to SERVICE endpoints since Pyodide does not support the urllib.request.urlopen method.

Executing SPARQL queries on the client also means that the SERVICE queries can be blocked if the external SPARQL endpoint does not support CORS (Cross-Origin Resource Sharing). I might add a toggle to use a proxy server to forward these requests in the future.

I've also looked into using JavaScript libraries (e.g. rdflib.js) for the RDF/SPARQL logic. They are all very powerful but don't currently support SPARQL federation.

See also

Made by Anton Vasetenkov.

If you want to say hi, you can reach me on LinkedIn or via email. If you like my work, you can support me by buying me a coffee.