{"library":"sparqlwrapper","title":"SPARQLWrapper","type":"library","description":"SPARQLWrapper is a Python library that provides a simple wrapper around a SPARQL service to remotely execute queries. It helps in creating the query invocation and, optionally, converting the result into a more manageable format like JSON or an RDFLib Graph. The current major version is 2.0.0, which was a significant update focusing on Python 3 compatibility. Releases occur periodically, with the last major release in March 2022.","language":"python","status":"active","last_verified":"Fri May 22","install":{"commands":["pip install sparqlwrapper"],"cli":null},"imports":["from SPARQLWrapper import SPARQLWrapper","from SPARQLWrapper import JSON"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"http://rdflib.github.io/sparqlwrapper","github":"https://github.com/RDFLib/sparqlwrapper","docs":"https://sparqlwrapper.readthedocs.io","changelog":null,"pypi":"https://pypi.org/project/sparqlwrapper/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import os\nfrom SPARQLWrapper import SPARQLWrapper, JSON\n\n# Use a placeholder for the endpoint URL, expecting an environment variable\n# or defaulting to a known public endpoint if available (e.g., DBpedia or a test endpoint)\nSPARQL_ENDPOINT = os.environ.get('SPARQL_ENDPOINT', 'http://dbpedia.org/sparql')\n\nsparql = SPARQLWrapper(SPARQL_ENDPOINT)\n\n# Example: Query for the first 5 English labels of DBPedia resources\nsparql.setQuery(\"\"\"\n    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n    SELECT ?resource ?label\n    WHERE {\n        ?resource rdfs:label ?label .\n        FILTER (lang(?label) = 'en')\n    }\n    LIMIT 5\n\"\"\")\n\nsparql.setReturnFormat(JSON)\n\ntry:\n    # queryAndConvert() directly returns a Python object (e.g., dict for JSON)\n    results = sparql.queryAndConvert()\n    \n    print(\"Query Results:\")\n    for result in results[\"results\"][\"bindings\"]:\n        resource_uri = result[\"resource\"][\"value\"]\n        label = result[\"label\"][\"value\"]\n        print(f\"Resource: {resource_uri}, Label: {label}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize SPARQLWrapper with an endpoint, set a SPARQL SELECT query, specify JSON as the return format, and process the results. It retrieves 5 English labels from a generic SPARQL endpoint, defaulting to DBpedia if no `SPARQL_ENDPOINT` environment variable is set.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-22","installed_version":"2.0.0","pypi_latest":"2.0.0","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.2,"avg_import_s":0.16,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.15,"mem_mb":8.3,"disk_size":"23.4M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.12,"mem_mb":8.3,"disk_size":"24M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.2,"mem_mb":8.8,"disk_size":"26.1M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.18,"mem_mb":8.8,"disk_size":"27M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.17,"mem_mb":8.8,"disk_size":"17.7M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0.18,"mem_mb":8.8,"disk_size":"18M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.17,"mem_mb":8.8,"disk_size":"17.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0.17,"mem_mb":8.8,"disk_size":"18M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.15,"mem_mb":8.3,"disk_size":"22.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"sparqlwrapper","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":0.13,"mem_mb":8.3,"disk_size":"23M"}]}}