Skip to main content

WikiBase Data Connector

This repository contains a Python library that provides a connector to the WikiBase database. WikiBase is a free and open knowledge base that can be read and edited by both humans and machines, and that contains structured data and metadata about a wide range of topics.

Installation

To install the library, you can use pip:

pip install wikibasedataconnector

Usage

To use the library, you need to create an instance of the WikiBaseDataConnector class, and then call its methods to process data into the WikiBase. For example:

import json
import csv
import asyncio
from wikibasedataconnector import WBDC

conf_filepath = 'conf'
site_name = <SITE>
PATH = f'{conf_filepath}/import_properties_add.json'
with open(PATH, 'r', encoding='utf-8') as f:
        mapping_config = json.load(f)

bot = WBDC(site_name)
bot.set_mapping_config(mapping_config)

FILEPATH = 'data/properties.csv'
with open(FILEPATH, 'r', encoding='utf-8') as file:
    csv_file = csv.reader(file)
    next(csv_file)
    await asyncio.gather(*[bot.process(row) for row in csv_file])

This code will read and process the properties.csv file according to the import_properties_add.json configuration file. More examples can be found in example/example_upsert.ipynb.

This uses the Pywikibot library, so it is required to create a family file and generated user files if you're using a custom wikibase.

To create family and user files

  • create <family-filename> family using command pwb generate_family_file

    • set url and a desired name for family
    • add the following code to your familyfile i.e. <family-filename>_family.py
        def default_globe(self, code) -> str:
        """Default globe for Coordinate datatype."""
        return 'earth'
    
    def globes(self, code):
        """Supported globes for Coordinate datatype."""
        return {
            'earth': 'http://www.wikidata.org/entity/Q2'
        }
    
  • ensuring that you are in the same directory as where you generated the family file, create user config and password files with command pwb generate_user_files

    • selected yes on adding a BotPassword
    • used same name for bot when it was created within the wikibase instance
    • add password provided by wikibase instance
    • It will prompt on whether to add additional options in the user-config.py file. They're not necessary to set up for the connection to the wikibase to be established.
  • change user-config file to read only by running chmod 0444 user-config.py (Set-ItemProperty -Path ./user-config.py -Name IsReadOnly -Value $true for Windows)

  • run pwb login to test connection

Troubleshooting

It is possible that the path was not added to the environment. If that is the case, a warning such as this will pop up: WARNING: The script pwb.exe is installed in 'your/path/to/local-packages/Python310/Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

You can add the path by running export PATH=$PATH:/some/new/path

Note: If you are on Windows, instructions to add the path can be found here

you can test to see if pywikibot is working by running the command `pwb`

License

This library is released under the MIT License. Please refer to the LICENSE file for more information.

Metadata

Release files for wikibasedataconnector 0.0.3

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

Source distribution (sdist)

Source distribution for wikibasedataconnector 0.0.3
File Size Uploaded
wikibasedataconnector-0.0.3.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wikibasedataconnector 0.0.3
File Interpreter ABI Platform
wikibasedataconnector-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / wikibasedataconnector-0.0.3.tar.gz

Download URL wikibasedataconnector-0.0.3.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8f6bb4dc7e173c47fa195e40c55fc69d1c17a3681401edc5dcb3e9111afbc2ec
BLAKE2b-256 checksum
How to use checksums
6f7bb79639172a8c69631e8d091ecc18a16aa88276c808ed0b2690be944d426a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release files / wikibasedataconnector-0.0.3-py3-none-any.whl

Download URL wikibasedataconnector-0.0.3-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8eb6d4b9839bc3fd724819764e5bdbb321d1f76b9f04b2013bd84052495942b2
BLAKE2b-256 checksum
How to use checksums
4874dff8e86946af4e132b7c7b7d9b6a1558b5636335bb8576f372da6a43232d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.1

2 release files

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