Library used for mapping data easily into Wikibase Systems
Project description
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 commandpwb 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 $truefor Windows) -
run
pwb loginto 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wikibasedataconnector-0.0.3.tar.gz.
File metadata
- Download URL: wikibasedataconnector-0.0.3.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f6bb4dc7e173c47fa195e40c55fc69d1c17a3681401edc5dcb3e9111afbc2ec
|
|
| MD5 |
3fc5b596baeaa1dbe70bb39f4dc99a48
|
|
| BLAKE2b-256 |
6f7bb79639172a8c69631e8d091ecc18a16aa88276c808ed0b2690be944d426a
|
File details
Details for the file wikibasedataconnector-0.0.3-py3-none-any.whl.
File metadata
- Download URL: wikibasedataconnector-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8eb6d4b9839bc3fd724819764e5bdbb321d1f76b9f04b2013bd84052495942b2
|
|
| MD5 |
2e4ad87343d1a01d92149785ce150e04
|
|
| BLAKE2b-256 |
4874dff8e86946af4e132b7c7b7d9b6a1558b5636335bb8576f372da6a43232d
|