Wikipedia in Python 🌐

Wikipedia in Python: Wikipedia is an awesome place to complete assignments right. And with Wikipedia being one of the largest and most popular sources for information on the Internet.

Wikipedia is a multilingual online encyclopedia created and maintained as an open collaboration project by a community of volunteer editors using a wiki-based editing system.

Today we bring wikipedia in our python program. Let’s see.


In order to extract data from Wikipedia, we must first install the Python Wikipedia library, which wraps the official Wikipedia API. This can be done by entering the command below in your command prompt or terminal:

pip install wikipedia


Example #1: Extract the summary with summary method.

# Extract the summary with summary method
import wikipedia

result = wikipedia.summary("India", sentences = 2)

# Follow @code_snail

Here, sentences = 2 refers to numbers of line.


wikipedia in python

Example #2: Searching title and suggestions

# getting suggestions 
import wikipedia 
result ="python programming", results = 5) 

#Follow @code_snail


python wikipedia module

Example #3: Getting Full Wikipedia Page Data

The page() method is used to get the contents, categories, coordinates, images, links and other metadata of a Wikipedia page.

import wikipedia 
# wikipedia page object is created 
page_object ="facebook") 

# printing title 
# printing 5 links on that page object 


image 9

Example #4: Wikipedia page in Other langauges

The language can be changed to your native language if the page exists in your native language. Set_lang() method is used for the same.

import wikipedia 

# in greek language

# printing the summary 

#Follow @code_snail


wikipedia in python

More about module:

I hope you like this wikipedia in python code. Must try and share it with your friends. For more codes be connected with us and press the bell icon.

Also see,

Support CodeSnail

If you appreciate my work, or if it has helped you along your journey. It would mean a lot to me if you could write a message on my wall and share a cup of coffee (or tea) with me.

Buy Me A Coffee
Your subscription could not be saved. Please try again.
Your subscription has been successful.


Subscribe to our newsletter and stay updated.

Leave a Comment