Skip to main content

mwcli

CLI wrapper around mwclient. Built for Agents.

Exposes mwclient methods from 3 targets:

  • site -> mwclient.Site
  • page -> mwclient.page.Page
  • image -> mwclient.image.Image

Install

From project dir:

pip install mwclient-cli

Command shape

python -m mwcli [connection flags] <site|page|image> <target args> <method> [--arg ...] [--kw ...] [--markdown]

Connection flags:

  • --host required (or MWCLI_HOST)
  • --scheme default https
  • --path default /w/
  • --ext default .php
  • --username, --password optional auth

Method args:

  • --arg VALUE positional arg, JSON-parsed when possible
  • --kw KEY=VALUE keyword arg, value JSON-parsed when possible
  • --max-items N cap iterator/list output
  • --stream print list/tuple one JSON per line
  • --markdown convert content-read output to Markdown (see below)

Tip: quote strings with spaces/pipes.

Discover available methods

python -m mwcli methods all
python -m mwcli methods site
python -m mwcli methods page
python -m mwcli methods image

All commands

Top-level commands:

  • python -m mwcli methods {all|site|page|image}
  • python -m mwcli site <method> [--arg ...] [--kw ...]
  • python -m mwcli page "<title>" <method> [--arg ...] [--kw ...]
  • python -m mwcli image "<title>" <method> [--arg ...] [--kw ...]

site methods (mwclient 0.11.0):

  • allcategories, allimages, alllinks, allpages, allusers
  • api, ask, blocks, checkuserlog, chunk_upload, clientlogin
  • deletedrevisions, email, expandtemplates, exturlusage
  • get, get_token, handle_api_result, logevents, login
  • parse, patrol, post, random, raw_api, raw_call, raw_index
  • recentchanges, require, revisions, search, site_init
  • upload, usercontributions, users, version_tuple_from_generator, watchlist

page methods:

  • append, backlinks, can, categories, delete, edit, embeddedin
  • extlinks, get_token, handle_edit_error, images, iwlinks, langlinks, links
  • move, normalize_title, prepend, purge, redirects_to, resolve_redirect
  • revisions, save, strip_namespace, templates, text, touch

image methods:

  • all page methods, plus:
  • download, duplicatefiles, imagehistory, imageusage

To confirm runtime command surface on your installed version:

python -m mwcli methods all

Main usage examples

Get page content

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  page "Main Page" text

Read one section:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  page "Main Page" text --kw section=1

Read as Markdown (page text uses site parse + html2text):

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  page "Main Page" text --markdown

The markdown output starts with:

# Main Page

Full text search:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site search --arg "space" --kw what=text --max-items 10

Title-only search:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site search --arg "Main" --kw what=title --max-items 10

Authentication + edit

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  --username "Admin" --password "secret" \
  page "Sandbox" edit \
  --arg "Edited from mwcli ~~~~" \
  --kw summary="mwcli test edit" \
  --kw bot=false

File upload

Local file upload:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  --username "Admin" --password "secret" \
  site upload \
  --kw file="/tmp/example.png" \
  --kw filename="Example.png" \
  --kw description="Uploaded by mwcli"

Upload from URL:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  --username "Admin" --password "secret" \
  site upload \
  --kw url="https://example.com/example.png" \
  --kw filename="ExampleFromURL.png"

Semantic MediaWiki ask API

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site ask --arg '[[Category:Item]]|?Has author|?Has status' --max-items 20

With an explicit title context:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site ask --arg '[[Category:Item]]|?Has author' --kw title="Main Page" --max-items 20

Fetch all SMW properties for a page (smwbrowse):

python -m mwcli --indent 2 --host host.docker.internal --scheme http --path /w/ \
  site raw_api --arg smwbrowse --arg GET --kw browse=subject \
  --kw params='"{\"subject\":\"Main Page\",\"ns\":0}"'

Note: smwbrowse expects params as a JSON string, so pass a JSON object wrapped as a quoted string (double-encoded).

Arbitrary API calls

Use get / post / api / raw_api directly.

Get siteinfo:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site get --arg query --kw meta=siteinfo --kw siprop='general|namespaces'

Generic api call with GET method:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site api --arg query --arg GET --kw prop=info --kw titles="Main Page"

Raw API (no extra wrapper logic):

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site raw_api --arg query --arg GET --kw list=search --kw srsearch=space

Parse wikitext/HTML directly as Markdown:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site parse --kw text=$'== Header ==\n\nBody' --markdown

--markdown currently applies to:

  • page text
  • site parse

Implementation uses html2text: https://pypi.org/project/html2text/

Page and image list iterators

Recent changes:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  site recentchanges --kw prop='title|timestamp|user|comment' --max-items 5

Image usage:

python -m mwcli --host host.docker.internal --scheme http --path /w/ \
  image "Example.png" imageusage --max-items 10

Env vars

You can use env vars instead of flags:

  • MWCLI_HOST
  • MWCLI_PATH (default /w/)
  • MWCLI_EXT (default .php)
  • MWCLI_SCHEME (default https)
  • MWCLI_USERNAME
  • MWCLI_PASSWORD
  • MWCLI_USER_AGENT

Then run shorter commands, for example:

export MWCLI_HOST=host.docker.internal
export MWCLI_SCHEME=http
export MWCLI_PATH=/w/
python -m mwcli site search --arg "space" --kw what=text --max-items 5

Metadata

Release files for mwclient-cli 0.1.5

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

Source distribution (sdist)

Source distribution for mwclient-cli 0.1.5
File Size Uploaded
mwclient_cli-0.1.5.tar.gz 24.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mwclient-cli 0.1.5
File Interpreter ABI Platform
mwclient_cli-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 32.5 kB

Release files / mwclient_cli-0.1.5.tar.gz

Download URL mwclient_cli-0.1.5.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4a81dd47e0d9a03d745722cf2b50f6ca39200f0cf6acd0aaaf72c60f283c9322
BLAKE2b-256 checksum
How to use checksums
d6e3b726fb2840d7441b395693bfbb4a84f02fc861499fa12ec4df81b761e128
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / mwclient_cli-0.1.5-py3-none-any.whl

Download URL mwclient_cli-0.1.5-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
055e23203305f1d41f42dac21ba7322ca0f154a3a05973d6dd433777a5c0b14e
BLAKE2b-256 checksum
How to use checksums
144b4d2746ef69e8550c065ff13666610792a0f11b57b730a1d2956c615254d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

1 release file

0.1.3

2 release files

0.1.2

1 release file

0.1.0

2 release files

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