GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing public-paws.wmcloud.org — Notebook

No description has been provided for this image   Wikimedia API Docs - Wikifeeds API
  Home | Discuss | Fork this notebook on PAWS

Getting featured content from Wikipedia¶

Many Wikipedias include a daily featured article and other curated content on their homepages. You can see an example of this on English Wikipedia and Hebrew Wikipedia. The Wikifeeds API lets you access this content programmatically, adding high-quality, multilingual content to your apps. In this tutorial, you'll use the API to extract information about today's featured article, featured image, and latest news.

→ Download this tutorial as a Jupyter Notebook

The Wikifeeds API supports featured content in over 12 languages based on the type of content. You can see language availability for each type of featured content by calling the availability endpoint from any Wikimedia project domain. While a Wikipedia may include featured content on its main page, not all Wikipedias are integrated into the Wikifeeds API.

Client identification: These examples use a User Agent header to identify the source of the request as required by the API access policies. To use this sample code, update the user agent header with your information.

Today's featured article¶

To access a wiki's daily featured article, you'll need today's date in YYYY-MM-DD format and the language code from the availability endpoint. Language codes are usually two or three letters, such as en for English, he for Hebrew, and fa for Persian. To get the language code for your language, visit the site matrix on Meta-Wiki.

In [5]:
# Python 3
# Get today's date in YYYY-MM-DD format.
import datetime

today = datetime.datetime.now()
date = today.strftime('%Y/%m/%d')

# Choose your language, and get today's featured content.
import requests
import json

language = 'en' # English Wikipedia
headers = {
  'User-Agent': 'YOUR_APP_OR_USER_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)'
}

url = 'https://api.wikimedia.org/feed/v1/wikipedia/' + language + '/featured/' + date
response = requests.get(url, headers=headers)
data = response.json()

Once you've made the request, you can extract information about today's featured article (tfa) from the JSON response. This example uses the title of the article, the link to the original article on Wikipedia, a short extract, and a thumbnail of the article's lead image. To satisfy the attribution requirements for Wikipedia's CC BY-SA license, make sure to include a link back to the original article.

In [6]:
from IPython.display import HTML, Image

# Get the featured article's title, URL, extract, and thumbnail.
tfa = data.get('tfa', {})
display_title = tfa.get('titles', {}).get('display')
desktop_url = tfa.get('content_urls', {}).get('desktop', {}).get('page')
extract_html = tfa.get('extract_html')
thumbnail_url = tfa.get('thumbnail', {}).get('source')

# Display a featured article widget using IPython
display(HTML('<h3>Featured article from Wikipedia</h3>'))
display(HTML(f'<a href="{desktop_url}">{display_title}</a>'))

if thumbnail_url:
    display(Image(url=thumbnail_url, width=150))

display(HTML(extract_html))

Featured article from Wikipedia

2025 World Figure Skating Championships
No description has been provided for this image

The 2025 World Figure Skating Championships were held from March 26 to 30 at the TD Garden in Boston, Massachusetts, in the United States. Sanctioned by the International Skating Union (ISU), the World Championships are considered the most prestigious event in figure skating. Medals were awarded in men's singles, women's singles, pair skating, and ice dance. The competition determined the entry quotas for each skating federation to the 2026 Winter Olympics. Ilia Malinin and Alysa Liu, both of the United States, won the men's and women's events, respectively. Riku Miura and Ryuichi Kihara of Japan won the pairs event, and Madison Chock and Evan Bates of the United States won the ice dance event.

Latest news stories¶

Some Wikipedias feature the latest news stories on their homepages, which you can also access using the featured content endpoint. Note that in-the-news content is only available for the current date. For example, to get the news stories featured on the main page of English Wikipedia:

In [8]:
# Get a list of headlines
headlines = []

for story in data['news']:
  headline = story['story']
  headline = headline.replace('"./', '"https://en.wikipedia.org/wiki/') # Replace relative URLs with absolute URLs
  headlines.append(headline)

# Display with IPython
display(HTML('<h3>Latest news from Wikipedia</h3>'))
for headline in headlines:
    display(HTML(headline))

Latest news from Wikipedia

The Social Democrats, led by Prime Minister Mette Frederiksen (pictured), remain the largest party after the Danish general election, with no political bloc winning a majority of seats.
In Italy, voters reject a reform of the judicial system in a constitutional referendum.
A Colombian Aerospace Force Lockheed C-130 crashes during take-off in Puerto Leguízamo, killing 70 people.
In mathematics, Gerd Faltings is awarded the Abel Prize for his work in arithmetic geometry.

Get content in another language¶

The availability endpoint tells us that today's featured article and latest news stories are also available from Vietnamese Wikipedia. Try changing the project to vi.wikipedia.org and re-running the code above to get featured content in Vietnamese. You can edit and re-run this notebook by uploading the source to Wikimedia PAWS.

Note that the featured content isn't consistent between languages. This is because each Wikipedia is an independently managed community, and the content featured depends on available articles and cultural context. You may also notice slight formatting differences between wikis.

Today's featured image¶

Wikimedia Commons is a collection of millions of freely usable media files, many of which are used in Wikipedia articles. The featured content endpoint includes information about the daily featured image from Wikimedia Commons.

When reusing a free image, review the license to provide the correct attribution information. For most free content licenses, you can correctly attribute the work by listing the artist, license, and linking to the file page on Wikimedia Commons.

In [9]:
# Get the featured image's thumbnail, description, license, and attribution information.
featured_image = data.get('image', {})
thumbnail_url = featured_image.get('thumbnail', {}).get('source')
description_html = featured_image.get('description', {}).get('html')
artist_name = featured_image.get('artist', {}).get('text')
attribution_url = featured_image.get('file_page', {})
license_name = featured_image.get('license', {}).get('type')
license_url = featured_image.get('license', {}).get('url')

# Display using IPython
from IPython.display import HTML, Image

display(HTML('<h3>Featured image from Wikimedia Commons</h3>'))
display(Image(url=thumbnail_url, width=150))

if description_html:
    display(HTML(description_html))

license_link = ''
attribution_link = ''

if license_url and license_name:
    license_link = f'<a href="{license_url}">{license_name}</a>'
elif license_name:
    license_link = license_name

if attribution_url and artist_name:
    attribution_link = f'<a href="{attribution_url}">{artist_name}</a>'
elif artist_name:
    attribution_link = artist_name

if license_link and attribution_link:
    display(HTML(f'{license_link} by {attribution_link}'))
elif license_link:
    display(HTML(license_link))
elif attribution_link:
    display(HTML(attribution_link))

Featured image from Wikimedia Commons

No description has been provided for this image
Sand dunes of the Thar Desert in the Indian state of Rajasthan. On this day in 1949, the state was formed after a merger of several Rajput princely states into the Indian Union following India's independence from British colonial rule.
CC BY-SA 4.0 by Clément Bardot

Although the featured content endpoint returns the same featured image from Wikimedia Commons for every Wikipedia domain, some domains offer an image description in the local language. For example, calling the featured content endpoint for German Wikipedia (de.wikipedia.org) for 2026/01/22 returns the following description:

"description": {
  "html": "Luftaufnahme der Zelte der \u003Ca rel=\"mw:WikiLink/Interwiki\" href=\"https://de.wikipedia.org/wiki/Bishwa%20Ijtema\" title=\"de:Bishwa Ijtema\" class=\"extiw\"\u003EBishwa Ijtema\u003C/a\u003E 2023 in Bangladesch. Mit 5 Millionen Teilnehmern ist sie die zweitgrößte muslimische Versammlung der Welt.",
  "text": "Luftaufnahme der Zelte der Bishwa Ijtema 2023 in Bangladesch. Mit 5 Millionen Teilnehmern ist sie die zweitgrößte muslimische Versammlung der Welt.",
  "lang": "de"
}

You can check for the presence of a localized description by examining the image.description.lang property.

More featured content¶

You should now be able to use the Wikifeeds API to get featured content from Wikipedias. For more information about these endpoints, see the API documentation.

To fork, edit, and re-run this Jupyter Notebook, download the source, and upload to PAWS using your Wikimedia account.


This tutorial is licensed under the Creative Commons Attribution-ShareAlike License.

You are visitor 01402639 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.