{"library":"pywikibot","title":"Pywikibot","description":"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pywikibot"],"cli":{"name":"pwb","version":"Pywikibot: pywikibot/__init__.py (, -1 (unknown), 2026/05/16, 15:07:20, UNKNOWN)"}},"imports":["import pywikibot\n# then pywikibot.Site(), pywikibot.Page()"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pywikibot\nimport os\n\n# --- Pywikibot requires a user-config.py file for site configuration and credentials ---\n# Create a user-config.py in your bot's directory or the pywikibot installation directory.\n# Example user-config.py content (replace with your actual info):\n# family = 'wikipedia'\n#mylang = 'en'\n#usernames['wikipedia']['en'] = 'YourBotUsername'\n#password_file = 'user-password.py' # or password['wikipedia']['en'] = 'YourBotPassword'\n\n# Use 'en', 'wikipedia' for the English Wikipedia, or other codes for different sites.\nsite = pywikibot.Site(os.environ.get('PYWIKIBOT_LANG', 'en'), os.environ.get('PYWIKIBOT_FAMILY', 'wikipedia'))\n\ntry:\n    site.login() # Attempt to log in based on user-config.py\n    print(f\"Successfully logged in to {site.family.name}:{site.lang} as {site.user().name}\")\nexcept pywikibot.exceptions.LoginError as e:\n    print(f\"Login failed: {e}. Check user-config.py and ensure credentials are correct.\")\n    # Fallback to anonymous for read-only actions if login isn't strictly needed\n    print(\"Proceeding with anonymous access for read-only operations.\")\n\npage = pywikibot.Page(site, os.environ.get('PYWIKIBOT_PAGE', 'Pywikibot'))\n\nif page.exists():\n    print(f\"\\n--- Page Info for '{page.title()}' ---\")\n    print(f\"URL: {page.full_url()}\")\n    print(f\"Page ID: {page.pageid}\")\n    print(f\"Last edited by: {page.last_updated_by.name}\")\n    print(\"Content snippet (first 200 chars):\")\n    print(page.text[:200])\nelse:\n    print(f\"\\nPage '{page.title()}' does not exist on {site.family.name}:{site.lang}.\")","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}