mwcli
CLI wrapper around mwclient. Built for Agents.
Exposes mwclient methods from 3 targets:
site->mwclient.Sitepage->mwclient.page.Pageimage->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:
--hostrequired (orMWCLI_HOST)--schemedefaulthttps--pathdefault/w/--extdefault.php--username,--passwordoptional auth
Method args:
--arg VALUEpositional arg, JSON-parsed when possible--kw KEY=VALUEkeyword arg, value JSON-parsed when possible--max-items Ncap iterator/list output--streamprint list/tuple one JSON per line--markdownconvert 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,allusersapi,ask,blocks,checkuserlog,chunk_upload,clientlogindeletedrevisions,email,expandtemplates,exturlusageget,get_token,handle_api_result,logevents,loginparse,patrol,post,random,raw_api,raw_call,raw_indexrecentchanges,require,revisions,search,site_initupload,usercontributions,users,version_tuple_from_generator,watchlist
page methods:
append,backlinks,can,categories,delete,edit,embeddedinextlinks,get_token,handle_edit_error,images,iwlinks,langlinks,linksmove,normalize_title,prepend,purge,redirects_to,resolve_redirectrevisions,save,strip_namespace,templates,text,touch
image methods:
- all
pagemethods, 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
Search
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 textsite 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_HOSTMWCLI_PATH(default/w/)MWCLI_EXT(default.php)MWCLI_SCHEME(defaulthttps)MWCLI_USERNAMEMWCLI_PASSWORDMWCLI_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)
| File | Size | Uploaded | |
|---|---|---|---|
| mwclient_cli-0.1.5.tar.gz | 24.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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}
|