Skip to main content

Py SPARQL Transformer

Write your SPARQL query directly in the JSON-LD you would like to have in output.

Looking for the JavaScript Version?

News

  • It is now possible to set a different merging anchor instead of id/@id using the $anchor modifier.

Table of Contents

Query in JSON

The core idea of this module is writing in a single file the query and the expected output in JSON.

Two syntaxes are supported: plain JSON and JSON-LD. Here the examples in the 2 formats for the query of cities.

  • plain JSON
{
  "proto": [{
    "id" : "?id",
    "name": "$rdfs:label$required",
    "image": "$foaf:depiction$required"
  }],
  "$where": [
    "?id a dbo:City",
    "?id dbo:country dbr:Italy"
  ],
  "$limit": 100
}
  • JSON-LD
{
  "@context": "http://schema.org/",
  "@graph": [{
    "@type": "City",
    "@id" : "?id",
    "name": "$rdfs:label$required",
    "image": "$foaf:depiction$required"
  }],
  "$where": [
    "?id a dbo:City",
    "?id dbo:country dbr:Italy"
  ],
  "$limit": 100
}

For the list of all properties and modifiers, read the full documentation.

How to use

Install by pip.

pip install SPARQLTransformer

Use in your JS application (node or browser).

from SPARQLTransformer import sparqlTransformer

out = sparqlTransformer(query, options)

The first parameter (query) is the query in the JSON format. The JSON can be:

  • an already parsed (or defined real time) dict,
  • the local path of a JSON file (that will then be read and parsed).

The options parameter is optional, and can define the following:

OPTION DEFAULT NOTE
context http://schema.org/ The value in @context. It overwrites the one in the query.
sparqlFunction None A function receiving in input the transformed query in SPARQL, returning a Promise. If not specified, the module performs the query on its own1 against the specified endpoint.
endpoint http://dbpedia.org/sparql Used only if sparqlFunction is not specified.
debug False Enter in debug mode. This allow to print in console the generated SPARQL query.

See tests.py for further examples.

Credits

If you use this module for your research work, please cite:

Pasquale Lisena, Albert Meroño-Peñuela, Tobias Kuhn and Raphaël Troncy. Easy Web API Development with SPARQL Transformer. In 18th International Semantic Web Conference (ISWC), Auckland, New Zealand, October 26-30, 2019.

BIB file

Pasquale Lisena and Raphaël Troncy. Transforming the JSON Output of SPARQL Queries for Linked Data Clients. In WWW'18 Companion: The 2018 Web Conference Companion, April 23–27, 2018, Lyon, France. https://doi.org/10.1145/3184558.3188739

BIB file

Metadata

Release files for SPARQLTransformer 2.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SPARQLTransformer 2.4.0
File Size Uploaded
SPARQLTransformer-2.4.0.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for SPARQLTransformer 2.4.0
File Interpreter ABI Platform
SPARQLTransformer-2.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.8 kB

Release files / SPARQLTransformer-2.4.0.tar.gz

Download URL SPARQLTransformer-2.4.0.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a5796d76e7e56f47ea6880055a00032adc9b7729f2b03c6d50b1813b5d2a4967
BLAKE2b-256 checksum
How to use checksums
b6af0ef7933efc5d8b83e613234f6c5315195a72b7e72d3cc63b283cc4574178
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / SPARQLTransformer-2.4.0-py3-none-any.whl

Download URL SPARQLTransformer-2.4.0-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5263718c2b51a9a2d4c85ddbbcde3cff089faa4dc6455dde4dca2999ab35e68e
BLAKE2b-256 checksum
How to use checksums
c42945a85be012ffa16d03769aa6cf10a837ffb33968b1d500460698f6cf9d32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release history Release notifications | RSS feed

This release

2.4.0 This release

2 release files

2.3.0

1 release file

2.2.2

1 release file

2.2.1

1 release file

2.2.0

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.0

1 release file

1.10.0

1 release file

1.9.0

1 release file

1.8.2

1 release file

1.8.1

1 release file

1.7.1

1 release file

1.7.0

1 release file

1.6.13

1 release file

1.6.12

1 release file

1.6.11

1 release file

1.6.10

1 release file

1.6.9

1 release file

1.6.8

1 release file

1.6.7

1 release file

1.6.6

1 release file

1.6.5

1 release file

1.6.4

1 release file

1.6.3

1 release file

1.6.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page