sparql_query
Execute SPARQL SELECT queries against any SPARQL endpoint and retrieve results as a Markdown table or JSON array. Supports custom headers for authenticated endpoints and adjustable timeout for complex queries.
Instructions
Execute a SPARQL SELECT query against a SPARQL endpoint.
Runs a SELECT query and returns results as a Markdown table or JSON array.
Supports custom HTTP headers for authenticated endpoints.
For long-running queries (large datasets, complex joins), increase the
timeout parameter — default is 30s, maximum is 3600s (1 hour).
Args:
params: Query parameters including endpoint URL, SPARQL query, timeout,
output format, optional headers, and max rows limit.
Returns:
Query results formatted as a Markdown table or JSON string.
Examples:
>>> # Query Wikidata for items
>>> sparql_query(SparqlQueryInput(
... endpoint="https://query.wikidata.org/sparql",
... query="SELECT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q5 . ?item rdfs:label ?itemLabel . FILTER(LANG(?itemLabel) = 'en') } LIMIT 5"
... ))
"| `item` | `itemLabel` |
| --- | --- |
| http://www.wikidata.org/entity/Q5 | human |
..."
>>> # Query with authentication
>>> sparql_query(SparqlQueryInput(
... endpoint="https://my-endpoint.example.com/sparql",
... query="SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10",
... headers={"Authorization": "Bearer my-token"}
... ))
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |