Skip to main content

CLI wrapper around mwclient

Project description

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 -r requirements.txt
pip install -e .

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

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 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mwclient_cli-0.1.0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mwclient_cli-0.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file mwclient_cli-0.1.0.tar.gz.

File metadata

  • Download URL: mwclient_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for mwclient_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3e0521e3144e8a3f237b2016eeed78afcc96a77aefa4f6667a07d2dd905f5a1b
MD5 4c95939d5cef41e5851314ee259da6bd
BLAKE2b-256 9b53ea53a1e00b8d8508afb4542cbd3a5e81edff167ae36a6d7b6aca5aefa026

See more details on using hashes here.

File details

Details for the file mwclient_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mwclient_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for mwclient_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4b5aed6d0df313eb17f7c30bda474c1a4b2e42915945b515e2d3cf09c470ea3
MD5 a53056927519adbf4a69408be263034b
BLAKE2b-256 11fa6b495f1b54432725347b2e511a2a941d919f055f1aa7f932605f436a2fac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page