# Wikipedia API - Article Text, Summary, Categories & Pageviews (`stas_k/wikipedia-article-api`) Actor

A Wikipedia scraper built on page HTML breaks when the layout changes and you are still charged for empty rows. This reads the official Wikimedia APIs instead: text, categories, pageviews and Wikidata, charged only per article that landed.

- **URL**: https://apify.com/stas_k/wikipedia-article-api.md
- **Developed by:** [Stas K](https://apify.com/stas_k) (community)
- **Categories:** Developer tools, SEO tools, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.80 / 1,000 articles

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

## Wikipedia API - Article Text, Summary, Categories & Pageviews

Read Wikipedia articles through the official Wikimedia APIs, not through the page HTML.
Send titles, article URLs or `lang:title` lines and get one row per article with its text,
categories, pageviews and the size of its Wikidata item.

Open source, no key, no browser, no proxy: the MediaWiki Action API, the Wikimedia
pageviews metric API and the Wikidata EntityData endpoint all answer a plain HTTP client.

### What you get per article

| field | meaning |
|---|---|
| `title`, `lang`, `url`, `pageId` | the article as the wiki sees it |
| `description` | the short description stored in the page properties |
| `wikidataId` | the Q-id of the item this article is attached to |
| `text` | the lead section, or the whole article text with `includeFullText` |
| `wordCount` | words in the text that was returned; every CJK character counts as one word |
| `categories`, `categoryCount` | every visible category, hidden maintenance ones skipped; `categoriesTruncated` says if the wiki cut the list |
| `pageviews`, `pageviewsPerDay`, `pageviewsDaily` | views from the official metric API over the window you ask for |
| `sitelinkCount`, `claimCount` | how many language editions and how many Wikidata statements the item has |
| `pageLengthBytes`, `lastEdited`, `lastEditor` | the size and the last revision |
| `redirectedFrom` | the title you sent, when the wiki redirected it |
| `actorInput`, `actorIndex`, `status`, `billable`, `source` | which line it came from, and whether it was sold |

### What it does not do

- It does not scrape the rendered page, so it never breaks on a layout change, and it does
  not read the "References", "See also" sections or the infobox as HTML.
- It does not translate, summarise or rewrite the text: it returns what Wikipedia stores.
- It does not read other wikis that are not Wikipedia projects, and it does not read a
  MediaWiki installed on some other domain.
- It does not resolve a topic. If you send an ambiguous word you get the page the wiki
  serves for that title, which may be a disambiguation page. The row says so in `status`
  of the wiki page itself, not in this actor: such a page exists, so it is billable.
- It does not give exact live view counts: pageviews are the official daily series over the
  window you ask for, not a real-time counter.

### Input

```json
{
  "articles": [
    "Python (programming language)",
    "https://de.wikipedia.org/wiki/Berlin",
    "fr:Paris"
  ],
  "lang": "en",
  "includePageviews": true,
  "includeCategories": true,
  "includeFullText": false,
  "pageviewsDays": 30,
  "maxArticles": 200
}
```

Every line may be a bare title, a full article URL (the language comes from the host) or a
`lang:title` line. `lang` is only the default used when the line carries none. A title in a
non-Latin script is fine: send it as a plain title, or as a percent-encoded URL.

`maxArticles` caps how many lines a run reads (default and maximum 200). A line past the cap
comes back as a free `NOT_CHECKED_CAP` row that names the cap, so a huge list never turns
into a silent cut.

### Money

You pay for one thing: an article that was read and delivered. The event is
`article-delivered`, and the price is on the card.

Free, with a status and a plain reason, and with no field you could mistake for data:

| status | when |
|---|---|
| `INVALID_INPUT` | the line is not a title, URL or `lang:title` line |
| `DUPLICATE` | the same article was already sent in this run (case and underscores do not matter) |
| `NOT_FOUND` | no article at this title: the page does not exist, or the title lives in another namespace (`Category:`, `File:`, `Special:`), or it is a special page |
| `NOT_CHECKED_ERROR` | the source could not be read: a timeout, a 5xx, a body that is not JSON |
| `NOT_CHECKED_CAP` | the spending limit on the run ended before this article |
| `NOT_CHECKED_BILLING` | the price list does not carry `article-delivered`, so nothing can be sold |
| `NOT_CHECKED_TIME` | the run had less than one article's worth of seconds left |

A missing article and an unreadable source are **different** statuses. A page that simply
does not exist is a verdict about your input and costs nothing. A 503 from the wiki is our
problem or theirs, and it also costs nothing, but it never pretends the article is absent.

The first row of a run with no articles at all is a failed run with an example in the
message, not a green run with zero rows.

A run is also refused when nothing could be read at all: every article that reached
Wikipedia failed and not one row was delivered. That message is about the source, never
about your titles, and it names the stop reason and the pricing state. A title that simply
does not exist is a free `NOT_FOUND` row and never fails a run.

If the platform charges for fewer rows than were written, the rest is delivered free, the
counters say so in `deliveredUncharged`, and the run stops instead of continuing to give
away the list.

### Run summary

`RUN_SUMMARY` in the run's key-value store, plus a copy under
`RUN_SUMMARY-<runId>` in the named store `wikipedia-article-summary`, so two runs at the
same time do not overwrite each other's counters. The output card links the bare
`RUN_SUMMARY` in the default store, because a run-scoped key only exists in the named one.

Status rows are written in batches of up to 100, so they may come after the paid rows:
sort the dataset by `actorIndex` to get your input order back.

Counters: `requested`, `attempted`, `delivered`, `rowsWritten`, `chargedEvents`,
`deliveredUncharged`, `deliveredUnverified`, `chargeUncertain`, `writeErrors`,
`cappedNotCharged`, `articlesNotFound`, `articlesInvalid`, `articlesDuplicate`,
`cutByDeadline`, `cutByStop`, `cutByLimit`, `byStatus`, `counterMismatch`, `stopReason`,
`datasetNote`, `firstFailure`, `billingActive`, `priceNote`, `source`.

`counterMismatch` is true when the input lines do not add up to the statuses counted. It is
there so that a lost line shows up by itself instead of looking like a short input.

If a paid write fails, the answer is never "nothing was delivered". The dataset counter is
read before and after, and the three outcomes are named separately: the rows landed and the
charge failed (`chargeUncertain`), the write was refused, or the counter lags and both
delivery and the charge are unknown. In every case `datasetNote` says what is known and
what is not, and no second row is written.

### Source and licence

Wikipedia text is CC BY-SA 4.0 and Wikidata is CC0. This actor reads them and hands you the
fields; if you republish the text, keep the attribution that the licence requires. Every row
carries the article `url`, which is the attribution the licence asks for.

### Notes

- A page that exists but is a redirect comes back resolved, with `redirectedFrom` naming
  what you sent.
- One article costs three requests (the page, the pageviews series and the Wikidata item),
  and a measured run takes about 1 s per article with pageviews on, about 0.4 s with them
  off. The remaining run time is divided between those three requests, so a slow source
  ends in a free `NOT_CHECKED_TIME` row instead of a killed run with no summary.
- `includeFullText` really returns the whole article: the request simply omits the intro
  flag that MediaWiki reads as "lead section only".

# Actor input Schema

## `articles` (type: `array`):

Articles: a title such as "Python (programming language)", a full URL such as https://de.wikipedia.org/wiki/Berlin, or a lang:title line such as de:Berlin.

## `lang` (type: `string`):

Wikipedia language code used when the line carries none. Default en.

## `includeFullText` (type: `boolean`):

Return the full plain-text article instead of the lead section only. Off by default.

## `includePageviews` (type: `boolean`):

Add the total and the daily series of views from the Wikimedia pageviews API. On by default.

## `includeCategories` (type: `boolean`):

Add the visible categories of the article. On by default.

## `pageviewsDays` (type: `integer`):

How many days of views to sum. Default 30, maximum 365.

## `maxArticles` (type: `integer`):

How many lines of the list this run reads. Default and maximum 200; a line past the cap comes back as a free NOT_CHECKED_CAP row that names the cap.

## Actor input object example

```json
{
  "articles": [
    "Python (programming language)",
    "https://de.wikipedia.org/wiki/Berlin",
    "https://example.com/wiki/Berlin"
  ],
  "lang": "en",
  "includeFullText": false,
  "includePageviews": true,
  "includeCategories": true,
  "pageviewsDays": 30,
  "maxArticles": 200
}
```

# Actor output Schema

## `dataset` (type: `string`):

One row per article. Paid rows carry the article fields and billable true; every other row is a free status row with a reason and no article data. Status rows are written in batches of up to 100, so sort by actorIndex to get the input order back.

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

Counters of the run: requested, attempted, delivered, chargedEvents, deliveredUncharged, deliveredUnverified, chargeUncertain, cutByLimit, byStatus, counterMismatch, stopReason, datasetNote, firstFailure and priceNote. The bare RUN_SUMMARY lives in the default store of the run; a copy under RUN_SUMMARY-<runId> is kept in the named store wikipedia-article-summary so two runs do not overwrite each other.

# 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 = {
    "articles": [
        "Python (programming language)",
        "https://de.wikipedia.org/wiki/Berlin",
        "https://example.com/wiki/Berlin"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("stas_k/wikipedia-article-api").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 = { "articles": [
        "Python (programming language)",
        "https://de.wikipedia.org/wiki/Berlin",
        "https://example.com/wiki/Berlin",
    ] }

# Run the Actor and wait for it to finish
run = client.actor("stas_k/wikipedia-article-api").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 '{
  "articles": [
    "Python (programming language)",
    "https://de.wikipedia.org/wiki/Berlin",
    "https://example.com/wiki/Berlin"
  ]
}' |
apify call stas_k/wikipedia-article-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,stas_k/wikipedia-article-api"
        }
    }
}
```

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/VWsuG4rGso7bEqbqc/builds/hRDlRLQhJg3ZEFo4z/openapi.json
