Registry / http-networking / pywikibot

pywikibot

JSON →
library11.3.0pypypi✓ verified 87d ago

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 pywikibot
INSTALL
IMPORT
SIG · PYWIKIBOT
P
pywikibot
http-networkingpythonv11.3.0
Install
2.6s avg
Import
1324ms
Disk
27MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v11.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 1.404s · 28.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.6s · import 1.244s · 29MB
27MB installed
● package 27MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Site, Page
import pywikibot # then pywikibot.Site(), pywikibot.Page()
from pywikibot.site import Site
While technically possible, direct imports from submodules like `pywikibot.site` or `pywikibot.page` are discouraged. `Site` and `Page` are exposed at the top level of `pywikibot` and internal submodule paths can change.

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.

import pywikibot import os # --- Pywikibot requires a user-config.py file for site configuration and credentials --- # Create a user-config.py in your bot's directory or the pywikibot installation directory. # Example user-config.py content (replace with your actual info): # family = 'wikipedia' #mylang = 'en' #usernames['wikipedia']['en'] = 'YourBotUsername' #password_file = 'user-password.py' # or password['wikipedia']['en'] = 'YourBotPassword' # Use 'en', 'wikipedia' for the English Wikipedia, or other codes for different sites. site = pywikibot.Site(os.environ.get('PYWIKIBOT_LANG', 'en'), os.environ.get('PYWIKIBOT_FAMILY', 'wikipedia')) try: site.login() # Attempt to log in based on user-config.py print(f"Successfully logged in to {site.family.name}:{site.lang} as {site.user().name}") except pywikibot.exceptions.LoginError as e: print(f"Login failed: {e}. Check user-config.py and ensure credentials are correct.") # Fallback to anonymous for read-only actions if login isn't strictly needed print("Proceeding with anonymous access for read-only operations.") page = pywikibot.Page(site, os.environ.get('PYWIKIBOT_PAGE', 'Pywikibot')) if page.exists(): print(f"\n--- Page Info for '{page.title()}' ---") print(f"URL: {page.full_url()}") print(f"Page ID: {page.pageid}") print(f"Last edited by: {page.last_updated_by.name}") print("Content snippet (first 200 chars):") print(page.text[:200]) else: print(f"\nPage '{page.title()}' does not exist on {site.family.name}:{site.lang}.")
pwb --version
Debug
Known issues
gotchaEssential Configuration via `user-config.py`. Many basic operations, especially write actions, fail without proper configuration of your username, password, and default wiki site in `user-config.py`. This file is not automatically created and is critical for operation.
fix
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`.
affects: All versions
gotchaExplicit Login Required. For most write operations (and even some read operations on private wikis), you must explicitly call `site.login()`. Forgetting this leads to permission errors or unexpected behavior.
fix
After initializing `site = pywikibot.Site(...)`, always call `site.login()` before attempting operations that require user authentication.
affects: All versions
breakingSignificant API Changes from v9.0.0 onwards. Pywikibot underwent a major rewrite, especially affecting how `Site` and `Page` objects are handled, method names, and return types. Scripts written for older versions (e.g., v8.x) will likely require substantial updates.
fix
Consult the official Pywikibot documentation for the version you are using. Specifically review the migration guides if upgrading from pre-9.0.0 versions.
affects: 9.0.0 and later
gotchaMediaWiki API Rate Limits. Aggressive or poorly designed bots can quickly hit MediaWiki API rate limits, leading to temporary blocks from the wiki. While Pywikibot has internal throttling, it's not foolproof against rapid, high-volume requests.
fix
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.
affects: All versions
deprecatedThe `pywikibot.bot.Robot` class and related modules are deprecated. Developers are encouraged to use `pywikibot.Site`, `pywikibot.Page`, and other core Pywikibot objects directly.
fix
Refactor scripts to use the direct `pywikibot.Site()` and `pywikibot.Page()` object interaction patterns instead of relying on the older `Robot` framework.
affects: 9.0.0 and later
Errors
Common errors & fixes
pywikibot.exceptions.LoginError: Login failed for user 'your_username'.
Incorrect credentials or site specified in `user-config.py`, `site.login()` not called, or Two-Factor Authentication/CAPTCHA awaiting input.
fix
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.
ImportError: cannot import name 'Site' from 'pywikibot.site'
Attempting to import internal components directly. `Site` and `Page` are exposed at the top level of `pywikibot` for convenience.
fix
Use `import pywikibot` and then access objects via `pywikibot.Site()` and `pywikibot.Page()`.
pywikibot.exceptions.NoPageError: No page 'NonExistentPage' on site 'en:wikipedia'.
The specified page title does not exist on the target wiki, or there's a typo in the title.
fix
Verify the page title and confirm its existence on the wiki (case sensitivity matters for some wikis).
TypeError: Page() got an unexpected keyword argument 'title'
Using an outdated `Page` constructor signature from an older major version of Pywikibot.
fix
Consult the latest documentation for `pywikibot.Page` constructor arguments. Typically, `pywikibot.Page(site_object, 'Page Title')` is the correct form.
Upgrade
Version history
11.3.0latest on PyPI · released May 17, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources