# Wikidata SPARQL Query — Companies, People, Geography & Science (`gochujang/wikidata-sparql-query`) Actor

Query Wikidata's SPARQL endpoint to retrieve structured knowledge data. Use preset queries for tech companies, world leaders, Nobel laureates, unicorn startups, or top universities. Supports custom SPARQL. PPE $0.002/record.

- **URL**: https://apify.com/gochujang/wikidata-sparql-query.md
- **Developed by:** [Hojun Lee](https://apify.com/gochujang) (community)
- **Categories:** Education, AI
- **Stats:** 2 total users, 1 monthly users, 66.7% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 item processeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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 — Companies, People, Geography & Science

**Wikidata SPARQL Query** lets you query **Wikidata's structured knowledge base** using either preset templates or custom SPARQL — returning companies, people, places, scientific concepts, and more as clean structured records. Five built-in presets cover tech companies, world leaders, Nobel laureates, unicorn startups, and top universities. For advanced use cases, write any SPARQL SELECT query against Wikidata's public endpoint. No API key required.

Wikidata is the machine-readable backbone behind Wikipedia, containing 100M+ items with structured properties — founding dates, headquarters, founders, revenue, country, and hundreds of other attributes — all queryable via SPARQL.

***

### Why use Wikidata SPARQL Query?

1. **Tech company data enrichment** — Pull founding year, headquarters, CEO, country, and industry for thousands of tech companies. Perfect for enriching CRM data or building a startup intelligence database.
2. **Academic research datasets** — Get structured data on Nobel laureates, Fields Medal winners, or top universities with country, founding year, and student population — ready for analysis.
3. **Custom knowledge graph queries** — Wikidata supports complex SPARQL: federated queries, property paths, aggregations. Write once, run repeatedly with this actor to keep data fresh.
4. **Unicorn startup tracking** — The unicorn preset returns all startups with valuation >$1B, with founding year, country, and sector classification.
5. **Geographic and political data** — World leaders, heads of state, and political entities with position start/end dates — ideal for geopolitical research and risk monitoring.

***

### How to use

1. Open the actor on Apify Store and click **Try for free**.
2. Set `mode` to `preset` and pick a `preset` template — or set `mode` to `custom` and paste your SPARQL query.
3. Set `limit` to control how many records to return.
4. Optionally change `language` for entity labels in your preferred language (default: English).
5. Click **Start**. Returns structured records from Wikidata matching your query.

***

### Input

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `mode` | string | `"preset"` | `preset` (built-in template) or `custom` (your SPARQL query) |
| `preset` | string | `"tech_companies"` | Template: `tech_companies`, `world_leaders`, `nobel_laureates`, `unicorn_startups`, `top_universities` |
| `customQuery` | string | `""` | SPARQL SELECT query (used when `mode: "custom"`) |
| `limit` | integer | `100` | Maximum records to return (1–1000) |
| `offset` | integer | `0` | Records to skip (for pagination) |
| `language` | string | `"en"` | BCP-47 language code for entity labels (`"de"`, `"ja"`, etc.) |

***

### Preset queries

| Preset | What it returns | Key fields |
|--------|----------------|-----------|
| `tech_companies` | Technology companies on Wikidata | name, founded, headquarters, country, employees |
| `world_leaders` | Current heads of state and government | name, country, position, start date |
| `nobel_laureates` | Nobel Prize winners | name, prize, year, country |
| `unicorn_startups` | Startups with valuation >$1B | name, founded, country, valuation, sector |
| `top_universities` | Universities ranked by student count | name, country, founded, students |

***

### Output

**Tech companies preset:**

```json
{
  "company": "Google LLC",
  "wikidata_id": "Q95",
  "founded": "1998-09-04",
  "headquarters": "Mountain View",
  "country": "United States",
  "employees": 190234,
  "industry": "Internet"
}
```

**Nobel laureates preset:**

```json
{
  "laureate": "Katalin Karikó",
  "wikidata_id": "Q76682864",
  "prize": "Nobel Prize in Physiology or Medicine",
  "year": "2023",
  "country": "Hungary"
}
```

**Custom query (any SPARQL SELECT):**

```sparql
SELECT ?company ?companyLabel ?revenue WHERE {
  ?company wdt:P31 wd:Q4830453;
           wdt:P2139 ?revenue.
  FILTER(?revenue > 1000000000)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?revenue)
LIMIT 50
```

***

### Cost estimation

**Pay-Per-Event: $0.005 per actor start + $0.002 per record returned.**

| Use case | Records | Estimated cost |
|----------|---------|----------------|
| 100 tech companies | 100 | ~$0.20/run |
| All Nobel laureates (1000) | 1000 | ~$2.00/run |
| 50 unicorn startups | 50 | ~$0.10/run |
| Custom query, 500 results | 500 | ~$1.00/run |

***

### FAQ

**What is Wikidata?**
Wikidata is a free, collaborative knowledge base maintained by the Wikimedia Foundation. It stores structured data that powers Wikipedia's infoboxes and is fully queryable via SPARQL. It contains 100M+ entities with millions of properties.

**How do I write a custom SPARQL query?**
Wikidata provides a free [SPARQL Query Service](https://query.wikidata.org) where you can test queries interactively. Write and test there, then paste into this actor's `customQuery` field. The endpoint is `https://query.wikidata.org/sparql`.

**How current is the Wikidata data?**
Wikidata is continuously updated by volunteers. Most major companies, public figures, and scientific entities are current within days to weeks. Obscure entities may lag.

**Can I get labels in languages other than English?**
Yes — set `language: "de"` for German, `"ja"` for Japanese, etc. Labels fall back to English when the entity has no label in the requested language.

***

### Related actors

- [GitHub Repository Stats Tracker](https://apify.com/gochujang/github-repo-stats) — Complement Wikidata tech company data with live GitHub repo stats
- [Startup Funding Tracker](https://apify.com/gochujang/startup-funding-tracker) — Recent funding rounds to enrich Wikidata unicorn data
- [Wikipedia Pageviews Tracker](https://apify.com/gochujang/wikipedia-pageviews-tracker) — Measure public interest in the entities you find in Wikidata

### Feedback

If this actor is useful, a quick review helps other researchers find it: [Leave a review on Apify Store](https://apify.com/gochujang/wikidata-sparql-query#reviews)

***

**Keywords:** Wikidata SPARQL query, structured knowledge data extractor, Wikidata API scraper, knowledge graph query, SPARQL endpoint automation, Wikidata entity data, tech company database, world leaders data, Nobel laureate data, unicorn startup list, open knowledge base, linked data scraper, Wikidata bulk export, PPE per record pricing

# Actor input Schema

## `mode` (type: `string`):

Use 'preset' to select a built-in query template, or 'custom' to provide your own SPARQL query.

## `preset` (type: `string`):

Predefined query template to run. Only used when mode is 'preset'. Options: 'tech\_companies' (tech businesses), 'world\_leaders' (heads of state), 'nobel\_laureates' (prize winners), 'unicorn\_startups' ($1B+ startups), 'top\_universities' (major universities).

## `customQuery` (type: `string`):

A valid SPARQL SELECT query to run against the Wikidata endpoint. Only used when mode is 'custom'. Must include a SERVICE wikibase:label clause for label resolution.

## `limit` (type: `integer`):

Maximum number of records to return (1–1000). Applied as a SPARQL LIMIT clause for preset queries.

## `offset` (type: `integer`):

Number of records to skip before returning results. Used for pagination of preset queries.

## `language` (type: `string`):

BCP-47 language code for entity labels (e.g. 'en', 'de', 'ja'). Falls back to English if the label is unavailable in the requested language.

## Actor input object example

```json
{
  "mode": "preset",
  "preset": "tech_companies",
  "customQuery": "",
  "limit": 100,
  "offset": 0,
  "language": "en"
}
```

# Actor output Schema

## `results` (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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("gochujang/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 = {}

# Run the Actor and wait for it to finish
run = client.actor("gochujang/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 '{}' |
apify call gochujang/wikidata-sparql-query --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,gochujang/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/EgbapDeUHxicEh9eh/builds/saIKqFEM9CxpPLdhl/openapi.json
