Pywikibot is a Python library and framework for automating interactions with MediaWiki sites. It provides classes and functions to access, modify, and manage content programmatically, enabling developers to create bots for tasks like editing pages, managing categories, and extracting data. The current stable version is 11.1.0, and it follows a semi-regular release cadence, often aligning with MediaWiki updates.
pip install pywikibotVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a Pywikibot site, attempt to log in (essential for most operations), and retrieve basic information and content from a specified page. Before running, you MUST create a `user-config.py` file with your bot's credentials and site preferences as outlined in the official documentation.
Create and correctly configure `user-config.py` in your bot's working directory or the Pywikibot installation directory. Refer to `https://www.mediawiki.org/wiki/Manual:Pywikibot/user-config.py`.
After initializing `site = pywikibot.Site(...)`, always call `site.login()` before attempting operations that require user authentication.
Consult the official Pywikibot documentation for the version you are using. Specifically review the migration guides if upgrading from pre-9.0.0 versions.
Design your bot with appropriate delays (e.g., `time.sleep()`) between actions, especially for write operations or iterating over many pages. Monitor bot activity and adhere to the wiki's bot policy.
Refactor scripts to use the direct `pywikibot.Site()` and `pywikibot.Page()` object interaction patterns instead of relying on the older `Robot` framework.
Ensure `user-config.py` has correct `usernames`, `password` (or `password_file`), and `family` settings. Call `site.login()` after creating the `Site` object. Manually log in via browser for CAPTCHA/2FA if necessary, then try again.
Use `import pywikibot` and then access objects via `pywikibot.Site()` and `pywikibot.Page()`.
Verify the page title and confirm its existence on the wiki (case sensitivity matters for some wikis).
Consult the latest documentation for `pywikibot.Page` constructor arguments. Typically, `pywikibot.Page(site_object, 'Page Title')` is the correct form.
No dependency data recorded yet.