# Wikidata SPARQL Query — Export to JSON/CSV \[$0.50/1K] (`zinin/wikidata-sparql-query`) Actor

Run any read-only Wikidata SPARQL SELECT query and get flat rows you can export to JSON, CSV or Excel, with Q-IDs split out. Official Wikidata Query Service, CC0 data. $0.50 per 1,000 rows, no start fee.

- **URL**: https://apify.com/zinin/wikidata-sparql-query.md
- **Developed by:** [Tim Zinin](https://apify.com/zinin) (community)
- **Categories:** Developer tools, AI, Education
- **Features:** Limited permissions
- **Stats:** 4 total users, 3 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.35 / 1,000 result delivereds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Wikidata SPARQL Query — Export Results to JSON, CSV & Excel

Run any read-only Wikidata SPARQL SELECT query and get the results as flat rows — one column per variable, with Wikidata Q-IDs split into their own columns — ready to export to JSON, CSV or Excel, schedule, or call from an AI agent. It uses the official Wikidata Query Service (all data CC0), so there is no login or key.

**$0.5 per 1,000 rows, no start fee.** Tested 2026-11-14: a run with the example input finished in a few seconds and returned real rows (see Output).

### What you get

- Any SELECT query you can run on query.wikidata.org, as table rows
- One column per SPARQL variable; `<var>Id` columns with bare Q-IDs for entity links
- Labels in your language via the standard `wikibase:label` service
- A hard row limit (`maxItems`) applied on top of your query, so the bill is predictable
- Ready example: countries with capital and population
- Runs on Apify: schedule it, monitor it, call it from the API or an AI agent (MCP), export to JSON/CSV/Excel or push straight into your own pipeline.

### How to run it

1. Click **Try for free** — no card needed on the free plan.
2. Paste a SPARQL SELECT query into **SPARQL query** (or keep the example).
3. Hit **Start** and pull the results from the dataset (UI, API or webhook).

### Pricing

Pay-per-event: **$0 per run start + $0.0005 per row** ($0.5 per 1,000 rows). No monthly seat.
Status rows (source error, nothing found) are returned for free; you pay only for delivered rows.
100 rows = $0.05; 10,000 rows = $5.00. Apify plan discounts apply automatically.

### Input

| Field | Required | What it does |
|---|---|---|
| `query` | no | A SPARQL SELECT query (up to 10,000 characters). Default: countries with capital and population. |
| `maxItems` | no | Row cap, 1–1,000 (default 100). Applied as LIMIT even if your query has none. |

```json
{
  "maxItems": 5
}
```

### Output

```json
{
  "found": true,
  "country": "http://www.wikidata.org/entity/Q148",
  "countryId": "Q148",
  "countryLabel": "People's Republic of China",
  "capitalLabel": "Beijing",
  "population": "1404890000",
  "source": "Wikidata Query Service (CC0)",
  "retrievedAt": "2026-11-14T15:34:05.612Z"
}
```

| Field | Meaning |
|---|---|
| `<your variables>` | One column per SELECT variable, values as strings |
| `<var>Id` | Q-ID when the value is a Wikidata entity |
| `found, source, retrievedAt` | Row status, source and time of the query |

### For AI agents & LLM apps

Call it as a tool through the Apify MCP server (`https://mcp.apify.com`, Actor `zinin/wikidata-sparql-query`): small inputs, flat JSON rows, a hard row cap and no start fee make it cheap to call many times.

### Other tools we built

Need the rest of the picture?

| Actor | What it does |
|---|---|
| [openalex-works-search](https://apify.com/zinin/openalex-works-search) | Scholarly works, citations and open-access links (OpenAlex) |
| [wikipedia-article-table-extractor](https://apify.com/zinin/wikipedia-article-table-extractor) | Wikipedia article text and tables as rows |
| [company-lookup](https://apify.com/zinin/company-lookup) | Company website and GLEIF LEI evidence |
| [sec-edgar-watcher](https://apify.com/zinin/sec-edgar-watcher) | New SEC filings by company |

### FAQ / Limitations

**My query times out.** The Wikidata Query Service stops queries after 60 seconds. Add filters or a LIMIT, or split by year or type.

**Can I update Wikidata with this?** No. Only read-only SELECT queries are accepted; updates and federated SERVICE calls to other endpoints are refused.

**What this is NOT.** It does not edit Wikidata, does not run CONSTRUCT/ASK/DESCRIBE queries and does not call other SPARQL endpoints.

Data: Wikidata Query Service, CC0. This Actor is not affiliated with Wikimedia or Wikidata.

Found a bug or need a custom version? Open an issue on the Actor page.

# Changelog

This Actor's version history is a separate document: https://apify.com/zinin/wikidata-sparql-query/changelog.md

# Actor input Schema

## `query` (type: `string`):

Read-only SPARQL SELECT query (10–10,000 characters). Leave empty for the example: countries with capital and population.

## `maxItems` (type: `integer`):

Paid rows to return, 1–1,000 (applied as LIMIT).

## Actor input object example

```json
{
  "maxItems": 5
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "maxItems": 5
};

// Run the Actor and wait for it to finish
const run = await client.actor("zinin/wikidata-sparql-query").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "maxItems": 5 }

# Run the Actor and wait for it to finish
run = client.actor("zinin/wikidata-sparql-query").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "maxItems": 5
}' |
apify call zinin/wikidata-sparql-query --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,zinin/wikidata-sparql-query"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/11COLqtBtsYRNysXg/builds/UioEodM0TT6I82YVd/openapi.json
