Skip to main content

WBMaker

PyPI version License: MIT

This alpha package helps establish an authenticated connection with a Wikibase instance and provides functions for building items using the wikibaseintegrator package and working with Wikimedia pages (e.g., "item talk" pages) using the mwclient package. While it is simple enough to work with these packages separately, wbmaker provides a lightweight layer of abstraction for many of the tasks needed in developing bot-based applications and data processing pipelines.

Features

  • 🔐 Easy authentication with Wikibase instances (including Wikidata)
  • 🔧 Simplified item creation and editing
  • 📝 MediaWiki page management (talk pages, etc.)
  • 🔍 SPARQL query execution with result formatting
  • 🧩 Property mapping and caching
  • 🌐 Path analysis for Wikidata classification

Installation

pip install wbmaker

Or install from source:

git clone https://github.com/skybristol/wbmaker
cd wbmaker
poetry install

Environment Variables

The WB class operates on a set of environment variables that set up and authorize interactions with a Wikibase instance, including Wikidata. These variables are required by one or both of the underlying packages, wikibaseintegrator and mwclient used in wbmaker. Instantiating the class will prompt for the following basic variables and set them if not supplied in the operating environment.

Required Variables

Optional Variables (for editing)

If you will be making edits, the following are also required. If these are not provided, the login section of the class will not be invoked, and you will be limited to read-only operations.

  • WB_BOT_USER: bot user name authorized to operate on the Wikibase instance
  • WB_BOT_PASS: bot user's password

Using .env file

You can create a .env file in your project root:

WB_URL=https://www.wikidata.org/
WB_SPARQL_ENDPOINT=https://query.wikidata.org/sparql
MEDIAWIKI_API=https://www.wikidata.org/w/api.php
WB_BOT_USER_AGENT=MyBot/1.0 (https://github.com/myusername/mybot)
WB_BOT_USER=MyBotUsername
WB_BOT_PASS=MyBotPassword

Basic Usage

from wbmaker import WB, Item

# Initialize connection (read-only if no credentials provided)
wb = WB()

# Run a SPARQL query
query = """
SELECT ?item ?itemLabel WHERE {
  ?item wdt:P31 wd:Q5.  # instances of human
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 10
"""
results = wb.sparql_query(query, output='dataframe')
print(results)

# Create or update an item
item_data = {
    'qid': 'Q123456',  # Leave empty for new items
    'label': 'Example Item',
    'description': 'An example item for demonstration',
    'aliases': ['Demo Item', 'Test Item'],
    'claims': [
        {
            'property_name': 'instance of',
            'value': 'Q5',  # human
        }
    ]
}

item = Item(item_data, wb=wb, commit=True, summary='Created example item')

Development Status

This package is in alpha status. Additional functionality is planned based on common patterns in Wikidata/Wikibase bot development.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for wbmaker 0.1.0

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

Source distribution (sdist)

Source distribution for wbmaker 0.1.0
File Size Uploaded Provenance Actions
wbmaker-0.1.0.tar.gz 8.8 kB Without provenance Details for wbmaker-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 18.2 kB

Release files / wbmaker-0.1.0.tar.gz

Download URL wbmaker-0.1.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
96017323744982903fd4573dcd8879991a5d6415943d3d626922d44ee3fea1c4
BLAKE2b-256 checksum
How to use checksums
6cdc2dd5ba6658bf7618f45dd24f63893aeaa22cf2ba4e42abbf8a869ba8f0d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.12 Linux/6.11.0-1018-azure

Release files / wbmaker-0.1.0-py3-none-any.whl

Download URL wbmaker-0.1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e6dcc055d782f9256f6b1557f8d18ce31b9bac028fc53e990fe5960e85c7390
BLAKE2b-256 checksum
How to use checksums
4ccb7730c7d71482e77c29404bb05b502081130c2f4acfc2db1aaa35311d0033
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.12 Linux/6.11.0-1018-azure

Security for wbmaker 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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