Skip to main content

Import tables from any Wikipedia article

Project description

Documentation Status PyPI version

Import tables from any Wikipedia article as a dataset in Python

Installing

pip install wikitables

Usage

Importing all tables from a given article:

from wikitables import import_tables
tables = import_tables('List of cities in Italy') #returns a list of WikiTable objects

To import an article from a different language, simply add the Wikipedia language code as an argument to import_tables

tables = import_tables('İtalya\'daki_şehirler_listesi', 'tr') #returns a list of WikiTable objects

Iterate over a table’s rows:

print(tables[0].name)
for row in tables[0].rows:
    print('{City}: {Area(km2)}'.format(**row))

output:

List of cities in Italy[0]
Milan: 4,450.11
Naples: 3,116.52
Rome: 3,340.41
Turin: 1,328.40
...

Or return the table encoded as JSON:

tables[0].json()

output:

[
    {
        "City": "Milan",
        "Population January 1, 2014": "6,623,798",
        "Density(inh./km2)": "1,488",
        "Area(km2)": "4,450.11"
    },
    {
        "City": "Naples",
        "Population January 1, 2014": "5,294,546",
        "Density(inh./km2)": "1,699",
        "Area(km2)": "3,116.52"
    },
    ...

Full documentation available here

Roadmap

Some planned and wishlist features:

  • Type guesing from MediaWiki template values

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wikitables-0.3.2.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file wikitables-0.3.2.tar.gz.

File metadata

  • Download URL: wikitables-0.3.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wikitables-0.3.2.tar.gz
Algorithm Hash digest
SHA256 383aef06f4254a37d6e8213c207bf7171a79573ee34a5d8bdab2a2ff3cc532eb
MD5 5eee5d9b91727055dc067607dd668366
BLAKE2b-256 25a44329b39c9e24cc71bb0d449907bf06af31126e99e618f596ae6bd57ebbf6

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page