Skip to main content

Query WikiData in plain SPARQL

Project description

WikiData Plain SPARQL Client

This package allows to query the WikiData database. For example this package is intended for people who need to be able to query WikiData in plain SPARQL while staying whithin a Jupyter Notebook.

Currently data can be returned as a dataframe or as a map. See examples

Install

pip install wikidata_plain_sparql

Usage

The module only has one function which is named query which has two parameters:

  • query: a sparql query
  • view: should data be displayed as a map, function will return a data frame if view is None (see examples for map use)
# import the module
import wikidata_plain_sparql as wikidata

wikidata.query(query, view=None)

Examples

Data Frame

# query WikiData
wikidata.query('''
SELECT ?actor ?actorLabel
WHERE
{
  # tv series "Person of Interest" has actor
  wd:Q564345 wdt:P161 ?actor.
  # actor has won a Golden Globe Award
  ?actor wdt:P166 wd:Q1011547.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')

Which will result in the following pandas data frame:

actor actorLabel
http://www.wikidata.org/entity/Q3295000 Sterling K. Brown

Map

The following query was copied from the offical WikiData Examples and shows all places within 1km of the Empire State Building:

# query WikiData
wikidata.query('''
#Places within 1km of the Empire State Building
SELECT ?place ?placeLabel ?location ?instanceLabel
WHERE
{
  wd:Q9188 wdt:P625 ?loc .
  SERVICE wikibase:around {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:center ?loc .
      bd:serviceParam wikibase:radius "1" .
  }
  OPTIONAL {    ?place wdt:P31 ?instance  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  BIND(geof:distance(?loc, ?location) as ?dist)
} ORDER BY ?dist
''', view='map')

Which will result in the following map: Map Example

Credits

  • requests - used for sending query to WikiData server
  • bokeh - used for displaying map data
  • pandas - used for returning data as data frame
  • @jelleschutter - development of this package

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

wikidata_plain_sparql-0.0.4.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

wikidata_plain_sparql-0.0.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file wikidata_plain_sparql-0.0.4.tar.gz.

File metadata

  • Download URL: wikidata_plain_sparql-0.0.4.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for wikidata_plain_sparql-0.0.4.tar.gz
Algorithm Hash digest
SHA256 2effbb6bad712f9ce220a0a075a8d4a03585c4b8f30dc856f26cffe0b2453df5
MD5 26ef1ee2c8aaf7fb364d0855c1e5ad81
BLAKE2b-256 29e90e97fbc2d28dc4cf73d9633aae9f0823be76461154b2802e6e57735d25c2

See more details on using hashes here.

File details

Details for the file wikidata_plain_sparql-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: wikidata_plain_sparql-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for wikidata_plain_sparql-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e33ee8d66289290b29a41403e5894482fdf3e11e6fa2755446811c9cca9a124d
MD5 f3f35086891f822085d8108d3812af69
BLAKE2b-256 474f6ddce4983672ce0a4b2909ae2cec896388060d477e21228084d8a3b73485

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