Skip to main content

Wikipedia API

This package provides python API for accessing Wikipedia.

build status Documentation Status Code Climate Issue Count

Installation

pip3 install wikipedia-api

Usage

import wikipedia

# Extract data in Wiki format
wiki_wiki = wikipedia.Wikipedia('en')

page_py = wiki_wiki.article('Python_(programming_language)')

print("Page - Exists: %s" % page_py.exists())
# Page - Exists: True

print("Page - Id: %s" % page_py.pageid)
# Page - Id: 23862

print("Page - Title: %s" % page_py.title)
# Page - Title: Python (programming language)

print("Page - Summary: %s" % page_py.summary[0:60])
# Page - Summary: Python is a widely used high-level programming language for


def print_sections(sections, level=0):
        for s in sections:
                print("%s: %s - %s" % ("*" * (level + 1), s.title, s.text[0:40]))
                print_sections(s.sections, level + 1)


print_sections(page_py.sections)
# *: History - Python was conceived in the late 1980s,
# *: Features and philosophy - Python is a multi-paradigm programming l
# *: Syntax and semantics - Python is meant to be an easily readable
# **: Indentation - Python uses whitespace indentation, rath
# **: Statements and control flow - Python's statements include (among other
# **: Expressions - Some Python expressions are similar to l
# ...

section_py = page_py.section_by_title('Features and philosophy')
print("Section - Title: %s" % section_py.title)
# Section - Title: Features and philosophy

print("Section - Text: %s" % section_py.text[0:60])
# Section - Text: Python is a multi-paradigm programming language. Object-orie

# Now lets extract texts with HTML tags
wiki_html = wikipedia.Wikipedia(
        language='cs',
        extract_format=wikipedia.ExtractFormat.HTML
)

page_ostrava = wiki_html.article('Ostrava')

print("Page - Exists: %s" % page_ostrava.exists())
# Page - Exists: True

print("Page - Id: %s" % page_ostrava.pageid)
# Page - Id: 7667

print("Page - Title: %s" % page_ostrava.title)
# Page - Title: Ostrava

print("Page - Summary: %s" % page_ostrava.summary[0:60])
# Page - Summary: <p><b>Ostrava</b> (polsky <span lang="pl" title="polština" x

print_sections(page_ostrava.sections)
# *: Znak a logo -
# **: Heraldický znak - <p>Městský znak je blasonován: <i>V modr
# **: Marketingové logo - <p>V roce 2008 bylo představeno nové log
# *: Historie - <dl><dd><i>Související informace nalezne
# **: Zemské hranice - <p>Zemské hranice zde tvoří řeky Odra a
# *: Obyvatelstvo - <ul class="gallery mw-gallery-traditiona

section_ostrava = page_ostrava.section_by_title('Heraldický znak')
print("Section - Title: %s" % section_ostrava.title)
# Section - Title: Heraldický znak

print("Section - Text: %s" % section_ostrava.text[0:60])
# Section - Text: <p>Městský znak je blasonován: <i>V modrém štítě na zeleném

page_nonexisting = wiki_wiki.article('Wikipedia-API-FooBar')
print("Page - Exists: %s" % page_nonexisting.exists())
# Page - Exists: False

print("Page - Id: %s" % page_nonexisting.pageid)
# Page - Id: -1

print("Page - Title: %s" % page_nonexisting.title)
# Page - Title: Wikipedia-API-FooBar

print("Page - Summary: %s" % page_nonexisting.summary[0:60])
# Page - Summary:

Changelog

0.2.0

  • Use properties instead of functions

  • Added support for property Info

0.1.6

  • Support for extracting texts with HTML markdown

  • Added initial version of unit tests

0.1.4

  • It’s possible to extract summary and sections of the page

  • Added support for property Extracts

Metadata

Release files for Wikipedia-API 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Wikipedia-API 0.2.0
File Size Uploaded Provenance Actions
Wikipedia-API-0.2.0.tar.gz 8.1 kB Without provenance Details for Wikipedia-API-0.2.0.tar.gz

Release files / Wikipedia-API-0.2.0.tar.gz

Download URL Wikipedia-API-0.2.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
98a7a10d9de38f19bc050440b466a17f72684bb0c60c625107c41c0dac614c85
BLAKE2b-256 checksum
How to use checksums
96210162f032ac44c4f780b8d72fe24466b1b456596138a0aa705b520d5ceed9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for Wikipedia-API 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page