Blog

Wikipedia pageviews API in Python

Pull Wikipedia article pageviews in Python with one REST call: monthly index plus raw views, parsed into pandas with growth windows.

Trends API team Published Data as of 2026-11-26

Line chart of monthly Wikipedia pageviews for the Grand Theft Auto VI article through October 2026

One REST call to https://api.trendsmcp.ai/api with a Bearer key, mode get_time_series and source Wikipedia returns Wikipedia pageviews for an article as monthly points with two numbers per point: a 0 to 100 index in value and the raw view count in volume. The call below was run on November 26, 2026 for the article "Grand Theft Auto VI" and returned 60 monthly points. The latest point, October 2026, reads 47.5 on the index with 489,581 raw views. Parse the response body as JSON a second time, load the points into pandas, and growth windows come from the same endpoint with mode set to get_growth.

One call returns 60 monthly points for a tracked article

The verified pull used the exact article title "Grand Theft Auto VI". A same day pull for "Thanksgiving" returned no data, and this run establishes no coverage rule for which titles hold a series. The code sends language as "en" explicitly; the run does not establish the API default.

import json
import os

import pandas as pd
import requests

API_URL = "https://api.trendsmcp.ai/api"
HEADERS = {"Authorization": f"Bearer {os.environ['TRENDS_API_KEY']}"}


def pageviews(article: str, language: str = "en") -> pd.DataFrame:
    body = {
        "mode": "get_time_series",
        "keyword": article,
        "source": "Wikipedia",
        "language": language,
    }
    resp = requests.post(API_URL, headers=HEADERS, json=body, timeout=30)
    resp.raise_for_status()
    payload = resp.json()
    points = json.loads(payload["body"]) if isinstance(payload.get("body"), str) else payload
    if not isinstance(points, list) or not points:
        return pd.DataFrame(columns=["date", "value", "volume"])
    df = pd.DataFrame(points)
    df["date"] = pd.to_datetime(df["date"])
    return df.sort_values("date")


df = pageviews("Grand Theft Auto VI")
print(df.tail(3)[["date", "value", "volume"]])

October 2026 read 47.5 with 489,581 raw views

The November 26 pull for "Grand Theft Auto VI" returned 60 monthly points, one per month, from November 2021 to October 2026. In this pull the points are monthly, not weekly. The last four months show why both numbers matter:

Month Index (value) Raw views (volume)
Jul 2026 26.3 271,378
Aug 2026 58.1 599,381
Sep 2026 38.9 400,855
Oct 2026 47.5 489,581

The index is scaled to the series peak: December 2023 holds 100.0 with 1,031,403 views, and 489,581 divided by 1,031,403 gives the October reading of 47.5. A future higher peak would rescale index values while volumes hold. The volume is the count a report can quote. A chart for readers can use either. A capacity or traffic estimate needs volume.

Index and volume growth agreed within 0.2 points

The get_growth mode returns point to point change for the windows requested, with volume change beside index change when the source carries volume:

def growth(article: str, windows=("1M", "3M")) -> dict:
    body = {
        "mode": "get_growth",
        "keyword": article,
        "source": "Wikipedia",
        "percent_growth": list(windows),
        "language": "en",
    }
    resp = requests.post(API_URL, headers=HEADERS, json=body, timeout=30)
    resp.raise_for_status()
    payload = resp.json()
    return json.loads(payload["body"]) if isinstance(payload.get("body"), str) else payload


result = growth("Grand Theft Auto VI")
for row in result.get("results", []):
    print(row["period"], row["growth"], row["volume_growth"])
# 1M 22.11 22.13
# 3M 80.61 80.41

For "Grand Theft Auto VI" on November 26, the 1M window read +22.11% on the index and +22.13% on volume, from 400,855 views in September to 489,581 in October. The 3M window read +80.61% on the index and +80.41% on volume, from 271,378 views in July. Index and volume growth track closely here because the index is a rescale of the same counts. That agreement is a useful sanity check in a pipeline: a gap wider than a chosen tolerance, for example 1 percentage point, flags a scaling or parsing error. The verified pull agreed within 0.02 percentage points on the 1M window and 0.20 points on the 3M window.

The trending board names the next article to track

The get_top_trends mode with type Wikipedia Trending returned a ranked article list on November 26, with "Grand Theft Auto VI" at No. 5. The run recorded the rank; it did not establish the ranking metric. The call:

def trending(limit: int = 10) -> dict:
    body = {"mode": "get_top_trends", "type": "Wikipedia Trending", "limit": limit}
    resp = requests.post(API_URL, headers=HEADERS, json=body, timeout=30)
    resp.raise_for_status()
    payload = resp.json()
    return json.loads(payload["body"]) if isinstance(payload.get("body"), str) else payload

A pipeline pattern follows from the recorded pull: read the top 10 board, then pull pageviews for articles inside that cutoff instead of polling a fixed list.

Two limits belong in any pipeline built on this. First, the keyword must match an article the source holds. A pull for "Thanksgiving" on November 26 returned no data, so code should treat a no_data response as a skip, not a crash. Second, monthly points suit trend work, not intraday monitoring. The November 26 pull ended at October 2026, so this run shows no partial current month point.

Raw volume, not the index, compares two articles

Pageview comparisons need the volume column, because each series carries its own index scale. Two articles can both read 50 on the index while their raw counts differ by an order of magnitude. The pattern below pulls two articles, keeps only date and volume, and merges on date:

def volumes(article: str) -> pd.DataFrame:
    df = pageviews(article)[["date", "volume"]]
    return df.rename(columns={"volume": article})


both = volumes("Grand Theft Auto VI").merge(
    volumes("Miss Universe 2026"), on="date", how="outer"
)

A same day growth pull verified the second title holds a series: 16 points, with 169,043 views in October 2026. The outer merge keeps months where only one article has a point. A young article starts later, and an inner merge would silently drop the older article's early history. Fill gaps only after deciding what a missing month means for the use case: zero views and no data are different statements, and the API returning no point is the second one.

A no_data result is a skip, not a crash

Three response shapes need explicit handling. A no_data result, like the "Thanksgiving" pull on November 26, means the source holds no series for that keyword and language pair. Log the keyword and move on. An HTTP error means the call itself failed; retry once with backoff, then surface the failure rather than writing an empty frame. A successful call with fewer points than expected usually means a young article, so code should assert on the date range it needs instead of assuming a fixed length.

for article in ["Grand Theft Auto VI", "Thanksgiving"]:
    try:
        df = pageviews(article)
    except requests.HTTPError:
        print(f"pageviews call failed for {article!r}")
        continue
    if df.empty:
        print(f"no Wikipedia series for {article!r}; skipping")
        continue

Exact article titles matter. Titles carry disambiguation in parentheses where Wikipedia uses it, and a near miss title can return a different article or no data at all. A title check against the Wikipedia Trending board output, which returns exact titles, removes one source of mismatch.

Daily board reads and monthly series pulls split the schedule

Monthly points make daily polling wasteful for history, and useful for discovery. A sound schedule splits the two jobs. The board call runs daily and costs one request per ten rows, so a top 10 board read costs 1 request. The series call runs when an article first appears on the board and again after each month closes. That split keeps a watchlist current without re pulling 60 points that cannot have changed.

Storage stays simple. One row per article, month and language, keyed on those three fields, lets a rerun overwrite the current month safely as its count settles. The October 2026 figure of 489,581 views for "Grand Theft Auto VI" is a closed month in this pull. The current month row is the one a scheduler refreshes.

One more check belongs in the pipeline. The index value and the volume should move together, since one rescales the other. In the verified pull, October rose 22.11% on the index and 22.13% on volume, a 0.02 point gap; the 3M gap was 0.20 points. A pipeline that asserts those two growth figures agree within a small tolerance catches parse errors, such as reading the index column as volume, before they reach a report.

The Wikipedia trends page lists the dataset details, the docs cover every mode and field, and plan limits sit on the pricing page. Keyword Planner returned no search volume for this tutorial's target query during the run, so no demand figure is claimed here.