{"id":18695802,"url":"https://github.com/rdflib/sparqlwrapper","last_synced_at":"2025-05-14T04:03:56.387Z","repository":{"id":941998,"uuid":"13525050","full_name":"RDFLib/sparqlwrapper","owner":"RDFLib","description":"A wrapper for a remote SPARQL endpoint","archived":false,"fork":false,"pushed_at":"2024-11-27T00:35:36.000Z","size":7563,"stargazers_count":534,"open_issues_count":65,"forks_count":124,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-05T01:01:35.902Z","etag":null,"topics":["pypi","python","rdf","sparql","sparql-endpoints","sparql-query","wrapper"],"latest_commit_sha":null,"homepage":"https://sparqlwrapper.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RDFLib.png","metadata":{"files":{"readme":"README.rst","changelog":"ChangeLog.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-10-12T16:45:13.000Z","updated_at":"2025-03-18T08:52:52.000Z","dependencies_parsed_at":"2023-07-06T07:28:53.155Z","dependency_job_id":"7710881e-dd06-4577-b680-bb06f0f19c80","html_url":"https://github.com/RDFLib/sparqlwrapper","commit_stats":{"total_commits":570,"total_committers":32,"mean_commits":17.8125,"dds":0.7035087719298245,"last_synced_commit":"2a6e2d3ddbc3fe38ca47d6d05f23c9b61ff82366"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RDFLib%2Fsparqlwrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RDFLib%2Fsparqlwrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RDFLib%2Fsparqlwrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RDFLib%2Fsparqlwrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RDFLib","download_url":"https://codeload.github.com/RDFLib/sparqlwrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514213,"owners_count":21116899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pypi","python","rdf","sparql","sparql-endpoints","sparql-query","wrapper"],"created_at":"2024-11-07T11:16:20.406Z","updated_at":"2025-05-14T04:03:56.351Z","avatar_url":"https://github.com/RDFLib.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. image:: docs/source/SPARQLWrapper-250.png\n\n=======================================\nSPARQL Endpoint interface to Python\n=======================================\n\n|Build Status| |PyPi version|\n\n* About_\n* `Installation \u0026 Distribution`_\n* `How to use`_\n* `SPARQL Endpoint Implementations`_\n* `Development`_\n\n\nAbout\n=====\n\n**SPARQLWrapper** is a simple Python wrapper around a `SPARQL \u003chttps://www.w3.org/TR/sparql11-overview/\u003e`_ service to\nremotely execute your queries. It helps by creating the query\ninvocation and, optionally, converting the result into more manageable\nformats.\n\nInstallation \u0026 Distribution\n===========================\n\nYou can install SPARQLWrapper from PyPI::\n\n   $ pip install sparqlwrapper\n\nYou can install SPARQLWrapper from GitHub::\n\n   $ pip install git+https://github.com/rdflib/sparqlwrapper#egg=sparqlwrapper\n\nYou can install SPARQLWrapper from Debian::\n\n   $ sudo apt-get install python-sparqlwrapper\n\n.. note::\n\n   Be aware that there could be a gap between the latest version of SPARQLWrapper\n   and the version available as Debian package.\n\nAlso, the source code of the package can be downloaded\nin ``.zip`` and ``.tar.gz`` formats from `GitHub SPARQLWrapper releases \u003chttps://github.com/RDFLib/sparqlwrapper/releases\u003e`_.\nDocumentation is included in the distribution.\n\n\nHow to use\n==========\n\nYou can use SPARQLWrapper either as a Python command line script or as a Python package.\n\nCommand Line Script\n-------------------\n\nTo use as a command line script, you will need to install SPARQLWrapper and then\na command line script called ``rqw`` (spaRQl Wrapper) will be available within the\nPython environment into which it is installed. run ``$ rql -h`` to see all the\nscript's options.\n\nPython package\n--------------\n\nHere are a series of examples of different queries executed via SPARQLWrapper\nas a python package.\n\nSELECT examples\n^^^^^^^^^^^^^^^\n\nSimple use of this module is as follows where a live SPARQL endpoint is given and the JSON return format is used:\n\n.. code-block:: python\n\n    from SPARQLWrapper import SPARQLWrapper, JSON\n\n    sparql = SPARQLWrapper(\n        \"http://vocabs.ardc.edu.au/repository/api/sparql/\"\n        \"csiro_international-chronostratigraphic-chart_geologic-time-scale-2020\"\n    )\n    sparql.setReturnFormat(JSON)\n\n    # gets the first 3 geological ages\n    # from a Geological Timescale database,\n    # via a SPARQL endpoint\n    sparql.setQuery(\"\"\"\n        PREFIX gts: \u003chttp://resource.geosciml.org/ontology/timescale/gts#\u003e\n\n        SELECT *\n        WHERE {\n            ?a a gts:Age .\n        }\n        ORDER BY ?a\n        LIMIT 3\n        \"\"\"\n    )\n\n    try:\n        ret = sparql.queryAndConvert()\n\n        for r in ret[\"results\"][\"bindings\"]:\n            print(r)\n    except Exception as e:\n        print(e)\n\n\nThis should print out something like this::\n\n    {'a': {'type': 'uri', 'value': 'http://resource.geosciml.org/classifier/ics/ischart/Aalenian'}}\n    {'a': {'type': 'uri', 'value': 'http://resource.geosciml.org/classifier/ics/ischart/Aeronian'}}\n    {'a': {'type': 'uri', 'value': 'http://resource.geosciml.org/classifier/ics/ischart/Albian'}}\n\n\nThe above result is the response from the given endpoint, retrieved in JSON, and converted to a\nPython object, ``ret``, which is then iterated over and printed.\n\nASK example\n^^^^^^^^^^^\n\nThis query gets a boolean response from DBPedia's SPARQL endpoint:\n\n.. code-block:: python\n\n   from SPARQLWrapper import SPARQLWrapper, XML\n\n   sparql = SPARQLWrapper(\"http://dbpedia.org/sparql\")\n   sparql.setQuery(\"\"\"\n       ASK WHERE {\n           \u003chttp://dbpedia.org/resource/Asturias\u003e rdfs:label \"Asturias\"@es\n       }\n   \"\"\")\n   sparql.setReturnFormat(XML)\n   results = sparql.query().convert()\n   print(results.toxml())\n\n\nYou should see something like:\n\n.. code-block::\n\n    \u003c?xml version=\"1.0\" ?\u003e\n    \u003csparql\n        xmlns=\"http://www.w3.org/2005/sparql-results#\"\n        xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n        xsi:schemaLocation=\"http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd\"\u003e\n    \u003chead/\u003e\n        \u003cboolean\u003etrue\u003c/boolean\u003e\n    \u003c/sparql\u003e\n\n\nCONSTRUCT example\n^^^^^^^^^^^^^^^^^\n\nCONSTRUCT queries return RDF, so ``queryAndConvert()`` here produces an\nRDFlib ``Graph`` object which is then serialized to the Turtle format\nfor printing:\n\n.. code-block:: python\n\n    from SPARQLWrapper import SPARQLWrapper\n\n    sparql = SPARQLWrapper(\"http://dbpedia.org/sparql\")\n\n    sparql.setQuery(\"\"\"\n        PREFIX dbo: \u003chttp://dbpedia.org/ontology/\u003e\n        PREFIX sdo: \u003chttps://schema.org/\u003e\n\n        CONSTRUCT {\n          ?lang a sdo:Language ;\n          sdo:alternateName ?iso6391Code .\n        }\n        WHERE {\n          ?lang a dbo:Language ;\n          dbo:iso6391Code ?iso6391Code .\n          FILTER (STRLEN(?iso6391Code)=2) # to filter out non-valid values\n        }\n        LIMIT 3\n    \"\"\")\n\n    results = sparql.queryAndConvert()\n    print(results.serialize())\n\n\nResults from this query should look something like this:\n\n.. code-block::\n\n    @prefix schema: \u003chttps://schema.org/\u003e .\n\n    \u003chttp://dbpedia.org/resource/Arabic\u003e a schema:Language ;\n        schema:alternateName \"ar\" .\n\n    \u003chttp://dbpedia.org/resource/Aragonese_language\u003e a schema:Language ;\n        schema:alternateName \"an\" .\n\n    \u003chttp://dbpedia.org/resource/Uruguayan_Spanish\u003e a schema:Language ;\n        schema:alternateName \"es\" .\n\n\nDESCRIBE example\n^^^^^^^^^^^^^^^^\n\nLike CONSTRUCT queries, DESCRIBE queries also produce RDF results, so this\nexample produces an RDFlib ``Graph`` object which is then serialized into\nthe JSON-LD format and printed:\n\n.. code-block:: python\n\n    from SPARQLWrapper import SPARQLWrapper\n\n    sparql = SPARQLWrapper(\"http://dbpedia.org/sparql\")\n    sparql.setQuery(\"DESCRIBE \u003chttp://dbpedia.org/resource/Asturias\u003e\")\n\n    results = sparql.queryAndConvert()\n    print(results.serialize(format=\"json-ld\"))\n\n\nThe result for this example is large but starts something like this:\n\n.. code-block::\n\n    [\n        {\n            \"@id\": \"http://dbpedia.org/resource/Mazonovo\",\n            \"http://dbpedia.org/ontology/subdivision\": [\n                {\n                    \"@id\": \"http://dbpedia.org/resource/Asturias\"\n                }\n        ],\n    ...\n\nSPARQL UPDATE example\n^^^^^^^^^^^^^^^^^^^^^\n\nUPDATE queries write changes to a SPARQL endpoint, so we can't easily show\na working example here. However, if ``https://example.org/sparql`` really\nwas a working SPARQL endpoint that allowed updates, the following code\nmight work:\n\n.. code-block:: python\n\n    from SPARQLWrapper import SPARQLWrapper, POST, DIGEST\n\n    sparql = SPARQLWrapper(\"https://example.org/sparql\")\n    sparql.setHTTPAuth(DIGEST)\n    sparql.setCredentials(\"some-login\", \"some-password\")\n    sparql.setMethod(POST)\n\n    sparql.setQuery(\"\"\"\n        PREFIX dbp:  \u003chttp://dbpedia.org/resource/\u003e\n        PREFIX rdfs: \u003chttp://www.w3.org/2000/01/rdf-schema#\u003e\n\n        WITH \u003chttp://example.graph\u003e\n        DELETE {\n           dbo:Asturias rdfs:label \"Asturies\"@ast\n        }\n        \"\"\"\n    )\n\n    results = sparql.query()\n    print results.response.read()\n\n\nIf the above code really worked, it would delete the triple\n``dbo:Asturias rdfs:label \"Asturies\"@ast`` from the graph\n``http://example.graph``.\n\n\nSPARQLWrapper2 example\n^^^^^^^^^^^^^^^^^^^^^^\n\nThere is also a ``SPARQLWrapper2`` class that works with JSON SELECT\nresults only and wraps the results to make processing of average queries\neven simpler.\n\n.. code-block:: python\n\n    from SPARQLWrapper import SPARQLWrapper2\n\n    sparql = SPARQLWrapper2(\"http://dbpedia.org/sparql\")\n    sparql.setQuery(\"\"\"\n        PREFIX dbp:  \u003chttp://dbpedia.org/resource/\u003e\n        PREFIX rdfs: \u003chttp://www.w3.org/2000/01/rdf-schema#\u003e\n\n        SELECT ?label\n        WHERE {\n            dbp:Asturias rdfs:label ?label\n        }\n        LIMIT 3\n        \"\"\"\n                    )\n\n    for result in sparql.query().bindings:\n        print(f\"{result['label'].lang}, {result['label'].value}\")\n\nThe above should print out something like:\n\n.. code-block::\n\n    en, Asturias\n    ar, أشتورية\n    ca, Astúries\n\n\nReturn formats\n--------------\n\nThe expected return formats differs per query type (``SELECT``, ``ASK``, ``CONSTRUCT``, ``DESCRIBE``...).\n\n.. note:: From the `SPARQL specification \u003chttps://www.w3.org/TR/sparql11-protocol/#query-success\u003e`_,\n  *The response body of a successful query operation with a 2XX response is either:*\n\n  * ``SELECT`` and ``ASK``: a SPARQL Results Document in XML, JSON, or CSV/TSV format.\n  * ``DESCRIBE`` and ``CONSTRUCT``: an RDF graph serialized, for example, in the RDF/XML syntax, or an equivalent RDF graph serialization.\n\nThe package, though it does not contain a full SPARQL parser, makes an attempt to determine the query type\nwhen the query is set. This should work in most of the cases, but there is a possibility to set this manually, in case something\ngoes wrong.\n\nAutomatic conversion of the results\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nTo make processing somewhat easier, the package can do some conversions automatically from the return result. These are:\n\n* for XML, the `xml.dom.minidom \u003chttp://docs.python.org/library/xml.dom.minidom.html\u003e`_ is used to convert the result stream into a ``Python representation of a DOM tree``.\n* for JSON, the `json \u003chttps://docs.python.org/library/json.html\u003e`_ package to generate a ``Python dictionary``.\n* for CSV or TSV, a simple ``string``.\n* For RDF/XML and JSON-LD, the `RDFLib \u003chttps://rdflib.readthedocs.io\u003e`_ package is used to convert the result into a ``Graph`` instance.\n* For RDF Turtle/N3, a simple ``string``.\n\n\nThere are two ways to generate this conversion:\n\n* use ``ret.convert()`` in the return result from ``sparql.query()`` in the code above\n* use ``sparql.queryAndConvert()`` to get the converted result right away, if the intermediate stream is not used\n\n\nFor example, in the code below:\n\n.. code-block:: python\n\n    try :\n        sparql.setReturnFormat(SPARQLWrapper.JSON)\n        ret = sparql.query()\n        d = ret.convert()\n    except Exception as e:\n        print(e)\n\n\nthe value of ``d`` is a Python dictionary of the query result, based on the `SPARQL Query Results JSON Format \u003chttp://www.w3.org/TR/rdf-sparql-json-res/\u003e`_.\n\n\nPartial interpretation of the results\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nFurther help is to offer an extra, partial interpretation of the results, again to cover\nmost of the practical use cases.\nBased on the `SPARQL Query Results JSON Format \u003chttp://www.w3.org/TR/rdf-sparql-json-res/\u003e`_, the :class:`SPARQLWrapper.SmartWrapper.Bindings` class\ncan perform some simple steps in decoding the JSON return results. If :class:`SPARQLWrapper.SmartWrapper.SPARQLWrapper2`\nis used instead of :class:`SPARQLWrapper.Wrapper.SPARQLWrapper`, this result format is generated. Note that this relies on a JSON format only,\nie, it has to be checked whether the SPARQL service can return JSON or not.\n\nHere is a simple code that makes use of this feature:\n\n.. code-block:: python\n\n    from SPARQLWrapper import SPARQLWrapper2\n\n    sparql = SPARQLWrapper2(\"http://example.org/sparql\")\n    sparql.setQuery(\"\"\"\n        SELECT ?subj ?prop\n        WHERE {\n            ?subj ?prop ?obj\n        }\n        \"\"\"\n    )\n\n    try:\n        ret = sparql.query()\n        print(ret.variables)  # this is an array consisting of \"subj\" and \"prop\"\n        for binding in ret.bindings:\n            # each binding is a dictionary. Let us just print the results\n            print(f\"{binding['subj'].value}, {binding['subj'].type}\")\n            print(f\"{binding['prop'].value}, {binding['prop'].type}\")\n    except Exception as e:\n        print(e)\n\n\nTo make this type of code even easier to realize, the ``[]`` and ``in`` operators are also implemented\non the result of :class:`SPARQLWrapper.SmartWrapper.Bindings`. This can be used to check and find a particular binding (ie, particular row\nin the return value). This features becomes particularly useful when the ``OPTIONAL`` feature of SPARQL is used. For example:\n\n.. code-block:: python\n\n    from SPARQLWrapper import SPARQLWrapper2\n\n    sparql = SPARQLWrapper2(\"http://example.org/sparql\")\n    sparql.setQuery(\"\"\"\n        SELECT ?subj ?obj ?opt\n        WHERE {\n            ?subj \u003chttp://a.b.c\u003e ?obj .\n            OPTIONAL {\n                ?subj \u003chttp://d.e.f\u003e ?opt\n            }\n        }\n        \"\"\"\n    )\n\n    try:\n        ret = sparql.query()\n        print(ret.variables)  # this is an array consisting of \"subj\", \"obj\", \"opt\"\n        if (\"subj\", \"prop\", \"opt\") in ret:\n            # there is at least one binding covering the optional \"opt\", too\n            bindings = ret[\"subj\", \"obj\", \"opt\"]\n            # bindings is an array of dictionaries with the full bindings\n            for b in bindings:\n                subj = b[\"subj\"].value\n                o = b[\"obj\"].value\n                opt = b[\"opt\"].value\n                # do something nice with subj, o, and opt\n\n        # another way of accessing to values for a single variable:\n        # take all the bindings of the \"subj\"\n        subjbind = ret.getValues(\"subj\")  # an array of Value instances\n        ...\n    except Exception as e:\n        print(e)\n\n\nGET or POST\n^^^^^^^^^^^\n\nBy default, all SPARQL services are invoked using HTTP **GET** verb. However,\n**POST** might be useful if the size of the query\nextends a reasonable size; this can be set in the query instance.\n\nNote that some combinations may not work yet with all SPARQL processors\n(e.g., there are implementations where **POST + JSON return** does not work).\nHopefully, this problem will eventually disappear.\n\n\nSPARQL Endpoint Implementations\n===============================\n\nIntroduction\n------------\n\nFrom `SPARQL 1.1 Specification \u003chttps://www.w3.org/TR/sparql11-protocol/#query-success\u003e`_:\n\nThe response body of a successful query operation with a 2XX response is either:\n\n- `SELECT` and `ASK`: a SPARQL Results Document in XML, JSON, or CSV/TSV format.\n- `DESCRIBE` and `CONSTRUCT`: an **RDF graph serialized**, for example, in the RDF/XML syntax, or an equivalent RDF graph serialization.\n\nThe fact is that the **parameter key** for the choice of the **output format** is not defined.\nVirtuoso uses `format`, Fuseki uses `output`, rasqual seems to use `results`, etc...\nAlso, in some cases HTTP Content Negotiation can/must be used.\n\n\nClioPatria\n----------\n\n:Website: `The SWI-Prolog Semantic Web Server \u003chttp://cliopatria.swi-prolog.org/home\u003e`_\n:Documentation: Search 'sparql' in `\u003chttp://cliopatria.swi-prolog.org/help/http\u003e`_.\n:Uses: Parameters **and** Content Negotiation.\n:Parameter key: ``format``.\n:Parameter value: MUST be one of these values: ``rdf+xml``, ``json``, ``csv``, ``application/sparql-results+xml`` or ``application/sparql-results+json``.\n\n\nOpenLink Virtuoso\n-----------------\n:Website: `OpenLink Virtuoso \u003chttp://virtuoso.openlinksw.com\u003e`_\n:Parameter key: ``format`` or ``output``.\n:JSON-LD (application/ld+json): supported (in CONSTRUCT and DESCRIBE).\n\n- Parameter value, like directly: \"text/html\" (HTML), \"text/x-html+tr\" (HTML (Faceted Browsing Links)), \"application/vnd.ms-excel\",\n  \"application/sparql-results+xml\" (XML), \"application/sparql-results+json\" (JSON), \"application/javascript\" (Javascript), \"text/turtle\" (Turtle), \"application/rdf+xml\" (RDF/XML),\n  \"text/plain\" (N-Triples), \"text/csv\" (CSV), \"text/tab-separated-values\" (TSV)\n- Parameter value, like indirectly:\n  \"HTML\" (alias text/html), \"JSON\" (alias application/sparql-results+json), \"XML\" (alias application/sparql-results+xml), \"TURTLE\" (alias text/rdf+n3), JavaScript (alias application/javascript)\n  See `\u003chttp://virtuoso.openlinksw.com/dataspace/doc/dav/wiki/Main/VOSSparqlProtocol#Additional HTTP Response Formats -- SELECT\u003e`_\n\n- For a ``SELECT`` query type, the default return mimetype (if ``Accept: */*`` is sent) is ``application/sparql-results+xml``\n- For a ``ASK`` query type, the default return mimetype (if ``Accept: */*`` is sent) is ``text/html``\n- For a ``CONSTRUCT`` query type, the default return mimetype (if ``Accept: */*`` is sent) is ``text/turtle``\n- For a ``DESCRIBE`` query type, the default return mimetype (if ``Accept: */*`` is sent) is ``text/turtle``\n\n\nFuseki\n------\n:Website: `Fuseki \u003chttps://jena.apache.org/documentation/fuseki2/\u003e`_\n:Uses: Parameters **and** Content Negotiation.\n:Parameter key: ``format`` or ``output`` (`Fuseki 1 \u003chttps://github.com/apache/jena/blob/master/jena-fuseki1/src/main/java/org/apache/jena/fuseki/HttpNames.java\u003e`_, `Fuseki 2 \u003chttps://github.com/apache/jena/blob/master/jena-arq/src/main/java/org/apache/jena/riot/web/HttpNames.java\u003e`_).\n:JSON-LD (application/ld+json): supported (in CONSTRUCT and DESCRIBE).\n\n- `Fuseki 1 - Short names for \"output=\" : \"json\", \"xml\", \"sparql\", \"text\", \"csv\", \"tsv\", \"thrift\" \u003chttps://github.com/apache/jena/blob/master/jena-fuseki1/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java\u003e`_\n- `Fuseki 2 - Short names for \"output=\" : \"json\", \"xml\", \"sparql\", \"text\", \"csv\", \"tsv\", \"thrift\" \u003chttps://github.com/apache/jena/blob/master/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/ResponseResultSet.java\u003e`_\n- If a non-expected short name is used, the server returns an \"Error 400: Can't determine output serialization\"\n- Valid alias for SELECT and ASK: \"json\", \"xml\", csv\", \"tsv\"\n- Valid alias for DESCRIBE and CONSTRUCT: \"json\" (alias for json-ld ONLY in Fuseki 2), \"xml\"\n- Valid mimetype for DESCRIBE and CONSTRUCT: \"application/ld+json\"\n- Default return mimetypes: For a SELECT and ASK query types, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json\n- Default return mimetypes: For a DESCRIBE and CONTRUCT query types, the default return mimetype (if Accept: */* is sent) is text/turtle\n- In case of a bad formed query, Fuseki 1 returns 200 instead of 400.\n\n\nEclipse RDF4J\n-------------\n:Website: `Eclipse RDF4J (formerly known as OpenRDF Sesame) \u003chttp://rdf4j.org/\u003e`_\n:Documentation: `\u003chttps://rdf4j.eclipse.org/documentation/rest-api/#the-query-operation\u003e`_, `\u003chttps://rdf4j.eclipse.org/documentation/rest-api/#content-types\u003e`_\n:Uses: Only content negotiation (no URL parameters).\n:Parameter: If an unexpected parameter is used, the server ignores it.\n:JSON-LD (application/ld+json): supported (in CONSTRUCT and DESCRIBE).\n\n- SELECT\n\n  - ``application/sparql-results+xml`` (DEFAULT if ``Accept: */*`` is sent))\n  - ``application/sparql-results+json`` (also ``application/json``)\n  - ``text/csv``\n  - ``text/tab-separated-values``\n  - Other values: ``application/x-binary-rdf-results-table``\n\n- ASK\n\n  - ``application/sparql-results+xml`` (DEFAULT if ``Accept: */*`` is sent))\n  - ``application/sparql-results+json``\n  - Other values: ``text/boolean``\n  - **Not supported**: ``text/csv``\n  - **Not supported**: ``text/tab-separated-values``\n\n- CONSTRUCT\n\n  - ``application/rdf+xml``\n  - ``application/n-triples`` (DEFAULT if ``Accept: */*`` is sent)\n  - ``text/turtle``\n  - ``text/n3``\n  - ``application/ld+json``\n  - Other acceptable values: ``application/n-quads``, ``application/rdf+json``, ``application/trig``, ``application/trix``, ``application/x-binary-rdf``\n  - ``text/plain`` (returns ``application/n-triples``)\n  - ``text/rdf+n3`` (returns ``text/n3``)\n  - ``text/x-nquads`` (returns ``application/n-quads``)\n\n- DESCRIBE\n\n  - ``application/rdf+xml``\n  - ``application/n-triples`` (DEFAULT if ``Accept: */*`` is sent)\n  - ``text/turtle``\n  - ``text/n3``\n  - ``application/ld+json``\n  - Other acceptable values: ``application/n-quads``, ``application/rdf+json``, ``application/trig``, ``application/trix``, ``application/x-binary-rdf``\n  - ``text/plain`` (returns ``application/n-triples``)\n  - ``text/rdf+n3`` (returns ``text/n3``)\n  - ``text/x-nquads`` (returns ``application/n-quads``)\n\n\nRASQAL\n------\n:Website: `RASQAL \u003chttp://librdf.org/rasqal/\u003e`_\n:Documentation: `\u003chttp://librdf.org/rasqal/roqet.html\u003e`_\n:Parameter key: ``results``.\n:JSON-LD (application/ld+json): NOT supported.\n\nUses roqet as RDF query utility (see `\u003chttp://librdf.org/rasqal/roqet.html\u003e`_)\nFor variable bindings, the values of FORMAT vary upon what Rasqal supports but include simple\nfor a simple text format (default), xml for the SPARQL Query Results XML format, csv for SPARQL CSV,\ntsv for SPARQL TSV, rdfxml and turtle for RDF syntax formats, and json for a JSON version of the results.\n\nFor RDF graph results, the values of FORMAT are ntriples (N-Triples, default),\nrdfxml-abbrev (RDF/XML Abbreviated), rdfxml (RDF/XML), turtle (Turtle),\njson (RDF/JSON resource centric), json-triples (RDF/JSON triples) or\nrss-1.0 (RSS 1.0, also an RDF/XML syntax).\n\n\nMarklogic\n---------\n:Website: `Marklogic \u003chttp://marklogic.com\u003e`_\n:Uses: Only content negotiation (no URL parameters).\n:JSON-LD (application/ld+json): NOT supported.\n\n`You can use following methods to query triples \u003chttps://docs.marklogic.com/guide/semantics/semantic-searches#chapter\u003e`_:\n\n- SPARQL mode in Query Console. For details, see Querying Triples with SPARQL\n- XQuery using the semantics functions, and Search API, or a combination of XQuery and SPARQL. For details, see Querying Triples with XQuery or JavaScript.\n- HTTP via a SPARQL endpoint. For details, see Using Semantics with the REST Client API.\n\n`Formats are specified as part of the HTTP Accept headers of the REST request. \u003chttps://docs.marklogic.com/guide/semantics/REST#id_92428\u003e`_\nWhen you query the SPARQL endpoint with REST Client APIs, you can specify the result output format (See `\u003chttps://docs.marklogic.com/guide/semantics/REST#id_54258\u003e`_. The response type format depends on the type of query and the MIME type in the HTTP Accept header.\n\nThis table describes the MIME types and Accept Header/Output formats (MIME type) for different types of SPARQL queries. (See `\u003chttps://docs.marklogic.com/guide/semantics/REST#id_54258\u003e`_ and `\u003chttps://docs.marklogic.com/guide/semantics/loading#id_70682\u003e`_)\n\n- SELECT\n\n  - application/sparql-results+xml\n  - application/sparql-results+json\n  - text/html\n  - text/csv\n\n- ASK queries return a boolean (true or false).\n\n- CONSTRUCT or DESCRIBE\n\n  - application/n-triples\n  - application/rdf+json\n  - application/rdf+xml\n  - text/turtle\n  - text/n3\n  - application/n-quads\n  - application/trig\n\n\nAllegroGraph\n------------\n:Website: `AllegroGraph \u003chttps://franz.com/agraph/allegrograph/\u003e`_\n:Documentation: `\u003chttps://franz.com/agraph/support/documentation/current/http-protocol.html\u003e`_\n:Uses: Only content negotiation (no URL parameters).\n:Parameter: The server always looks at the Accept header of a request, and tries to\n  generate a response in the format that the client asks for. If this fails,\n  a 406 response is returned. When no Accept, or an Accept of */* is specified,\n  the server prefers text/plain, in order to make it easy to explore the interface from a web browser.\n:JSON-LD (application/ld+json): NOT supported.\n\n\n- SELECT\n\n  - application/sparql-results+xml (DEFAULT if Accept: */* is sent)\n  - application/sparql-results+json (and application/json)\n  - text/csv\n  - text/tab-separated-values\n  - OTHERS: application/sparql-results+ttl, text/integer, application/x-lisp-structured-expression, text/table, application/processed-csv, text/simple-csv, application/x-direct-upis\n\n- ASK\n\n  - application/sparql-results+xml (DEFAULT if Accept: */* is sent)\n  - application/sparql-results+json (and application/json)\n  - Not supported: text/csv\n  - Not supported: text/tab-separated-values\n\n- CONSTRUCT\n\n  - application/rdf+xml (DEFAULT if Accept: */* is sent)\n  - text/rdf+n3\n  - OTHERS: text/integer, application/json, text/plain, text/x-nquads, application/trix, text/table, application/x-direct-upis\n\n- DESCRIBE\n\n  - application/rdf+xml (DEFAULT if Accept: */* is sent)\n  - text/rdf+n3\n\n\n4store\n------\n:Website: `4store \u003chttps://github.com/4store/4store\u003e`_\n:Documentation: `\u003chttps://4store.danielknoell.de/trac/wiki/SparqlServer/\u003e`_\n:Uses: Parameters **and** Content Negotiation.\n:Parameter key: ``output``.\n:Parameter value: alias. If an unexpected alias is used, the server is not working properly.\n:JSON-LD (application/ld+json): NOT supported.\n\n\n- SELECT\n\n  - application/sparql-results+xml (alias xml) (DEFAULT if Accept: */* is sent))\n  - application/sparql-results+json or application/json (alias json)\n  - text/csv (alias csv)\n  - text/tab-separated-values (alias tsv). Returns \"text/plain\" in GET.\n  - Other values: text/plain, application/n-triples\n\n- ASK\n\n  - application/sparql-results+xml (alias xml) (DEFAULT if Accept: */* is sent))\n  - application/sparql-results+json or application/json (alias json)\n  - text/csv (alias csv)\n  - text/tab-separated-values (alias tsv). Returns \"text/plain\" in GET.\n  - Other values: text/plain, application/n-triples\n\n- CONSTRUCT\n\n  - application/rdf+xml (alias xml) (DEFAULT if Accept: */* is sent)\n  - text/turtle (alias \"text\")\n\n- DESCRIBE\n\n  - application/rdf+xml (alias xml) (DEFAULT if Accept: */* is sent)\n  - text/turtle (alias \"text\")\n\n:Valid alias for SELECT and ASK: \"json\", \"xml\", csv\", \"tsv\" (also \"text\" and \"ascii\")\n:Valid alias for DESCRIBE and CONSTRUCT: \"xml\", \"text\" (for turtle)\n\n\nBlazegraph\n----------\n:Website: `Blazegraph (Formerly known as Bigdata) \u003chttps://www.blazegraph.com/\u003e`_ \u0026 `NanoSparqlServer \u003chttps://wiki.blazegraph.com/wiki/index.php/NanoSparqlServer\u003e`_\n:Documentation: `\u003chttps://wiki.blazegraph.com/wiki/index.php/REST_API#SPARQL_End_Point\u003e`_\n:Uses: Parameters **and** Content Negotiation.\n:Parameter key: ``format`` (available since version 1.4.0). `Setting this parameter will override any Accept Header that is present \u003chttps://wiki.blazegraph.com/wiki/index.php/REST_API#GET_or_POST\u003e`_\n:Parameter value: alias. If an unexpected alias is used, the server is not working properly.\n:JSON-LD (application/ld+json): NOT supported.\n\n- SELECT\n\n  - application/sparql-results+xml (alias xml) (DEFAULT if Accept: */* is sent))\n  - application/sparql-results+json or application/json (alias json)\n  - text/csv\n  - text/tab-separated-values\n  - Other values: application/x-binary-rdf-results-table\n\n- ASK\n\n  - application/sparql-results+xml (alias xml) (DEFAULT if Accept: */* is sent))\n  - application/sparql-results+json or application/json (alias json)\n\n- CONSTRUCT\n\n  - application/rdf+xml (alias xml) (DEFAULT if Accept: */* is sent)\n  - text/turtle (returns text/n3)\n  - text/n3\n\n- DESCRIBE\n\n  - application/rdf+xml (alias xml) (DEFAULT if Accept: */* is sent)\n  - text/turtle (returns text/n3)\n  - text/n3\n\n:Valid alias for SELECT and ASK: \"xml\", \"json\"\n:Valid alias for DESCRIBE and CONSTRUCT: \"xml\", \"json\" (but it returns unexpected \"application/sparql-results+json\")\n\n\nGraphDB\n-------\n:Website: `GraphDB, formerly known as OWLIM (OWLIM-Lite, OWLIM-SE) \u003chttp://graphdb.ontotext.com/\u003e`_\n:Documentation: `\u003chttps://graphdb.ontotext.com/documentation/free/\u003e`_\n:Uses: Only content negotiation (no URL parameters).\n:Note: If the Accept value is not within the expected ones, the server returns a 406 \"No acceptable file format found.\"\n:JSON-LD (application/ld+json): supported (in CONSTRUCT and DESCRIBE).\n\n- SELECT\n\n  - application/sparql-results+xml, application/xml (.srx file)\n  - application/sparql-results+json, application/json (.srj file)\n  - text/csv (DEFAULT if Accept: */* is sent)\n  - text/tab-separated-values\n\n- ASK\n\n  - application/sparql-results+xml, application/xml (.srx file)\n  - application/sparql-results+json (DEFAULT if Accept: */* is sent), application/json (.srj file)\n  - NOT supported: text/csv, text/tab-separated-values\n\n- CONSTRUCT\n\n  - application/rdf+xml, application/xml (.rdf file)\n  - text/turtle (.ttl file)\n  - application/n-triples (.nt file) (DEFAULT if Accept: */* is sent)\n  - text/n3, text/rdf+n3 (.n3 file)\n  - application/ld+json (.jsonld file)\n\n- DESCRIBE\n\n  - application/rdf+xml, application/xml (.rdf file)\n  - text/turtle (.ttl file)\n  - application/n-triples (.nt file) (DEFAULT if Accept: */* is sent)\n  - text/n3, text/rdf+n3 (.n3 file)\n  - application/ld+json (.jsonld file)\n\n\nStardog\n-------\n:Website: `Stardog \u003chttps://www.stardog.com\u003e`_\n:Documentation: `\u003chttps://www.stardog.com/docs/#_http_headers_content_type_accept\u003e`_ (looks outdated)\n:Uses: Only content negotiation (no URL parameters).\n:Parameter key: If an unexpected parameter is used, the server ignores it.\n:JSON-LD (application/ld+json): supported (in CONSTRUCT and DESCRIBE).\n\n\n- SELECT\n\n  - application/sparql-results+xml (DEFAULT if Accept: */* is sent)\n  - application/sparql-results+json\n  - text/csv\n  - text/tab-separated-values\n  - Other values: application/x-binary-rdf-results-table\n\n- ASK\n\n  - application/sparql-results+xml (DEFAULT if Accept: */* is sent)\n  - application/sparql-results+json\n  - Other values: text/boolean\n  - Not supported: text/csv\n  - Not supported: text/tab-separated-values\n\n- CONSTRUCT\n\n  - application/rdf+xml\n  - text/turtle (DEFAULT if Accept: */* is sent)\n  - text/n3\n  - application/ld+json\n  - Other acceptable values: application/n-triples, application/x-turtle, application/trig, application/trix, application/n-quads\n\n- DESCRIBE\n\n  - application/rdf+xml\n  - text/turtle (DEFAULT if Accept: */* is sent)\n  - text/n3\n  - application/ld+json\n  - Other acceptable values: application/n-triples, application/x-turtle, application/trig, application/trix, application/n-quads\n\nOntop\n-------\n:Website: `Ontop VKG \u003chttps://ontop-vkg.org\u003e`_\n:Documentation: `\u003chttps://ontop-vkg.org/guide/\u003e`\n:Uses: Only content negotiation (no URL parameters).\n:Parameter key: If an unexpected parameter is used, the server ignores it.\n\n\n- SELECT\n\n  - application/sparql-results+json (DEFAULT if Accept: */* is sent)\n  - application/sparql-results+xml\n  - text/csv (versions before Ontop 5.2 returned text/sparql-results+csv)\n  - text/tab-separated-values (versions before Ontop 5.2 returned text/sparql-results+tsv)\n\n- ASK\n\n  - application/sparql-results+json (DEFAULT if Accept: */* is sent)\n  - application/sparql-results+xml\n  - Other values: text/boolean\n\n- CONSTRUCT\n\n  - text/turtle (DEFAULT if Accept: */* is sent)\n  - application/rdf+xml\n  - text/n3\n  - application/ld+json\n  - Other acceptable values: application/n-triples, application/n-quads, rdf+json, rdf+xml\n\n- DESCRIBE\n\n  - text/turtle (DEFAULT if Accept: */* is sent)\n  - application/rdf+xml\n  - application/rdf+json\n  - text/n3\n  - application/ld+json\n  - Other acceptable values: application/n-triples, application/n-quads\n\nDevelopment\n===========\n\nRequirements\n------------\n\nThe `RDFLib \u003chttps://rdflib.readthedocs.io\u003e`_ package is used for RDF parsing.\n\nThis package is imported in a lazy fashion, i.e. only when needed. If the user never intends to use the\nRDF format, the RDFLib package is not imported and the user does not have to install it.\n\nSource code\n-----------\n\nThe source distribution contains:\n\n-  ``SPARQLWrapper``: the Python package. You should copy the directory\n   somewhere into your PYTHONPATH. Alternatively, you can also run\n   the distutils scripts: ``python setup.py install``\n\n-  ``test``: some unit and integrations tests. In order to run the tests\n   some packages have to be installed before. So please install the dev packages:\n   ``pip install '.[dev]'``\n\n-  ``scripts``: some scripts to run the package against some SPARQL endpoints.\n\n-  ``docs``: the documentation.\n\nCommunity\n---------\n\nCommunity support is available through the RDFlib developer's discussion group `rdflib-dev \u003chttp://groups.google.com/d/forum/rdflib-dev\u003e`_.\nThe `archives \u003chttp://sourceforge.net/mailarchive/forum.php?forum_name=sparql-wrapper-devel\u003e`_. from the old mailing list are still available.\n\nIssues\n------\n\nPlease, `report any issue to github \u003chttps://github.com/RDFLib/sparqlwrapper/issues\u003e`_.\n\nDocumentation\n-------------\n\nThe `SPARQLWrapper documentation is available online \u003chttps://sparqlwrapper.readthedocs.io\u003e`_.\n\nOther interesting documents are the latest `SPARQL 1.1 Specification (W3C Recommendation 21 March 2013) \u003chttps://www.w3.org/TR/sparql11-overview/\u003e`_\nand the initial `SPARQL Specification (W3C Recommendation 15 January 2008) \u003chttp://www.w3.org/TR/rdf-sparql-query/\u003e`_.\n\nLicense\n-------\n\nThe SPARQLWrapper package is licensed under `W3C license`_.\n\n.. _W3C license: https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document\n\nAcknowledgement\n---------------\n\nThe package was greatly inspired by `Lee Feigenbaum's similar package for Javascript \u003chttp://thefigtrees.net/lee/blog/2006/04/sparql_calendar_demo_a_sparql.html\u003e`_.\n\nDevelopers involved:\n\n* Ivan Herman \u003chttp://www.ivan-herman.net\u003e\n* Sergio Fernández \u003chttp://www.wikier.org\u003e\n* Carlos Tejo Alonso \u003chttp://www.dayures.net\u003e\n* Alexey Zakhlestin \u003chttps://indeyets.ru/\u003e\n\nOrganizations involved:\n\n* `World Wide Web Consortium \u003chttp://www.w3.org\u003e`_\n* `Salzburg Research \u003chttp://www.salzburgresearch.at\u003e`_\n* `Foundation CTIC \u003chttp://www.fundacionctic.org/\u003e`_\n\n.. |Build Status| image:: https://github.com/RDFLib/sparqlwrapper/actions/workflows/test.yml/badge.svg\n   :target: https://github.com/RDFLib/sparqlwrapper/actions/workflows/test.yml\n.. |PyPi version| image:: https://badge.fury.io/py/SPARQLWrapper.svg\n   :target: https://pypi.python.org/pypi/SPARQLWrapper\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdflib%2Fsparqlwrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frdflib%2Fsparqlwrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdflib%2Fsparqlwrapper/lists"}