This page looks best with JavaScript enabled

mwcleric, my Python MediaWiki client library

 ·  ☕ 2 min read

My Python library mwcleric now has docs on readthedocs.io! This library is a wrapper for mwclient and to an extent mwparserfromhell.

Docs overview

I’ve been meaning to make these docs happen for over half a year, and I finally did it! (Blog post coming about everything that went wrong with configuring sphinx.) The module index contains automatically-generated docs based on the docstrings of all of the classes in the package. The ones you probably care about the most are wiki_client, auth_credentials, and cargo_client.

You can also use the PageModifier and TemplateModifier classes to easily perform edits on your wiki that would otherwise be extremely difficult to do in AWB or PWB. At my EMWCon 2021 talk in April this year I gave an example of using the TemplateModifier class to make an edit to a template on all pages on a wiki (it’s really easy!).

You can also check out my example_wiki_scripts repo for some simple example scripts using these classes. (That repo uses mwrogue instead of mwcleric, but the functionality is mostly the same, just extended for use on my esports wikis.)

You may also find mwparserfromhell’s docs useful, particularly the template node, as they will show you the available actions on templates that you can use with the TemplateModifier class.

Library advantages

In addition to providing TemplateModifier and PageModifier classes, mwcleric improves the architecture of mwclient by putting all client actions directly on the Site object, instead of using a client object attached to the page object. This way:

  • The page object acts as a simple data container and so
  • There is no confusion about whether a method on a page object is “expensive” or not; it never will be. Furthermore,
  • If a site object needs to be thrown away and recreated, there are no cumbersome references to worry about left behind on existing page objects

And so the architecture is a significant improvement. Notably, the third bullet point represents a situation that arises a lot when working with the Fandom wiki farm, since tokens expire frequently and sessions need to be re-established. My site methods also take care of this automatically (both on Fandom and on any wiki farm).

The mwclient client is still exposed as WikiClient.client so if you need any method from that library, you may still use it directly.

Installation

With pip you can simply:

pip install mwcleric

Contributing

If you want to contribute patches, including documentation updates, or tickets, feel free! You can also star the repo if you find the library helpful :)

Share on

river
WRITTEN BY
River
River is a developer most at home in MediaWiki and known for building Leaguepedia. She likes cats.


What's on this Page