Skip to main content

Pythonic wrapper around the Wikidata SPARQL API for quick creation of datasets from Wikidata

Project description

wikidataloader

Easy pythonic wrapper around the Wikidata SPARQL API for quick creation of datasets from Wikidata.

Only supports simple, non-recursive queries - for complex queries please directly use the SPARQL API provided by Wikidata.

It does not support complex operators (ordering, datetime conversion, string/numeric filtering etc.), because these can be substituted by preprocessing the dataset in Python after retrieval.

Usage

Look up the URIs for properties (e.g. P31) and objects (e.g. Q5) on Wikidata's search engine.

from wikidataloader import WikidataQuery

# Linguists from Germany with birth places and gender

results = WikidataQuery.search(
    # {is_instance:human, country_of_origin:Germany, profession:linguist}
    filters={"P31": "Q5", "P27": "Q183", "P106": "Q14467526"}, 

    # selects the properties "Gender" and "Birth Place" as columns in the dataframe and names them "Gender" and "City of Birth"
    select=[("P21", "Gender"), ("P19", "City of Birth")],

    # returns a maximum of 5 results
    limit=5,

    # retrieves labels in English, if available
    default_language="en" 
).to_pandas()

results

>>>                                    item Gender        City_of_Birth
>>> 0                        Hermann Weller   male     Schwäbisch Gmünd
>>> 1                             Hans Wehr   male              Leipzig
>>> 2                       Theodor Haecker   male            Mulfingen
>>> 3                   Gottfried Bernhardy   male  Gorzów Wielkopolski
>>> 4                    Wilhelm Streitberg   male   Rüdesheim am Rhein

For more examples, see example.ipynb

Install

Install using pip:

pip install wikidataloader

Limitations

  • Does not support recursive queries
  • Does not support Senses and Forms for Lexeme queries

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

wikidataloader-0.0.5.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wikidataloader-0.0.5-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

Details for the file wikidataloader-0.0.5.tar.gz.

File metadata

  • Download URL: wikidataloader-0.0.5.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for wikidataloader-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a471dd40c57bc29dd97a181f5d2262e9d85dd78595b41832d0839c45092f56e7
MD5 497567c40dbb3d528fd3c1508023ad07
BLAKE2b-256 bbd520e4588cacaf05d86372c8e2111c57ff8eae4ab6484819aa3e37b2c6ad1d

See more details on using hashes here.

File details

Details for the file wikidataloader-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: wikidataloader-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for wikidataloader-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 96c76a4ad7b32d1fc68ce4174c226261decf39aa46d6fe740b5ae06e895ee66a
MD5 76828a42d3a36376a52778f813701a4c
BLAKE2b-256 0b23524e7c9efaa57383c7134efc25c93507e43227db20d57a0457135c1a5e4c

See more details on using hashes here.

Supported by

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