mwclient-cli 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ .venv/
2
+ .idea/
3
+ __pycache__/
4
+ *.pyc
5
+ dist/
@@ -0,0 +1,275 @@
1
+ Metadata-Version: 2.4
2
+ Name: mwclient-cli
3
+ Version: 0.1.0
4
+ Summary: CLI wrapper around mwclient
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: html2text==2025.4.15
7
+ Requires-Dist: mwclient==0.11.0
8
+ Provides-Extra: test
9
+ Requires-Dist: pytest==9.0.2; extra == 'test'
10
+ Description-Content-Type: text/markdown
11
+
12
+ # mwcli
13
+
14
+ CLI wrapper around `mwclient`. Built for Agents.
15
+
16
+ Exposes `mwclient` methods from 3 targets:
17
+ - `site` -> `mwclient.Site`
18
+ - `page` -> `mwclient.page.Page`
19
+ - `image` -> `mwclient.image.Image`
20
+
21
+ ## Install
22
+
23
+ From project dir:
24
+
25
+ ```bash
26
+ pip install -r requirements.txt
27
+ pip install -e .
28
+ ```
29
+
30
+ ## Command shape
31
+
32
+ ```bash
33
+ python -m mwcli [connection flags] <site|page|image> <target args> <method> [--arg ...] [--kw ...] [--markdown]
34
+ ```
35
+
36
+ Connection flags:
37
+ - `--host` required (or `MWCLI_HOST`)
38
+ - `--scheme` default `https`
39
+ - `--path` default `/w/`
40
+ - `--ext` default `.php`
41
+ - `--username`, `--password` optional auth
42
+
43
+ Method args:
44
+ - `--arg VALUE` positional arg, JSON-parsed when possible
45
+ - `--kw KEY=VALUE` keyword arg, value JSON-parsed when possible
46
+ - `--max-items N` cap iterator/list output
47
+ - `--stream` print list/tuple one JSON per line
48
+ - `--markdown` convert content-read output to Markdown (see below)
49
+
50
+ Tip: quote strings with spaces/pipes.
51
+
52
+ ## Discover available methods
53
+
54
+ ```bash
55
+ python -m mwcli methods all
56
+ python -m mwcli methods site
57
+ python -m mwcli methods page
58
+ python -m mwcli methods image
59
+ ```
60
+
61
+ ## All commands
62
+
63
+ Top-level commands:
64
+
65
+ - `python -m mwcli methods {all|site|page|image}`
66
+ - `python -m mwcli site <method> [--arg ...] [--kw ...]`
67
+ - `python -m mwcli page "<title>" <method> [--arg ...] [--kw ...]`
68
+ - `python -m mwcli image "<title>" <method> [--arg ...] [--kw ...]`
69
+
70
+ `site` methods (mwclient 0.11.0):
71
+
72
+ - `allcategories`, `allimages`, `alllinks`, `allpages`, `allusers`
73
+ - `api`, `ask`, `blocks`, `checkuserlog`, `chunk_upload`, `clientlogin`
74
+ - `deletedrevisions`, `email`, `expandtemplates`, `exturlusage`
75
+ - `get`, `get_token`, `handle_api_result`, `logevents`, `login`
76
+ - `parse`, `patrol`, `post`, `random`, `raw_api`, `raw_call`, `raw_index`
77
+ - `recentchanges`, `require`, `revisions`, `search`, `site_init`
78
+ - `upload`, `usercontributions`, `users`, `version_tuple_from_generator`, `watchlist`
79
+
80
+ `page` methods:
81
+
82
+ - `append`, `backlinks`, `can`, `categories`, `delete`, `edit`, `embeddedin`
83
+ - `extlinks`, `get_token`, `handle_edit_error`, `images`, `iwlinks`, `langlinks`, `links`
84
+ - `move`, `normalize_title`, `prepend`, `purge`, `redirects_to`, `resolve_redirect`
85
+ - `revisions`, `save`, `strip_namespace`, `templates`, `text`, `touch`
86
+
87
+ `image` methods:
88
+
89
+ - all `page` methods, plus:
90
+ - `download`, `duplicatefiles`, `imagehistory`, `imageusage`
91
+
92
+ To confirm runtime command surface on your installed version:
93
+
94
+ ```bash
95
+ python -m mwcli methods all
96
+ ```
97
+
98
+ ## Main usage examples
99
+
100
+ ### Get page content
101
+
102
+ ```bash
103
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
104
+ page "Main Page" text
105
+ ```
106
+
107
+ Read one section:
108
+
109
+ ```bash
110
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
111
+ page "Main Page" text --kw section=1
112
+ ```
113
+
114
+ Read as Markdown (`page text` uses `site parse` + `html2text`):
115
+
116
+ ```bash
117
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
118
+ page "Main Page" text --markdown
119
+ ```
120
+
121
+ The markdown output starts with:
122
+
123
+ ```md
124
+ # Main Page
125
+ ```
126
+
127
+ ### Search
128
+
129
+ Full text search:
130
+
131
+ ```bash
132
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
133
+ site search --arg "space" --kw what=text --max-items 10
134
+ ```
135
+
136
+ Title-only search:
137
+
138
+ ```bash
139
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
140
+ site search --arg "Main" --kw what=title --max-items 10
141
+ ```
142
+
143
+ ### Authentication + edit
144
+
145
+ ```bash
146
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
147
+ --username "Admin" --password "secret" \
148
+ page "Sandbox" edit \
149
+ --arg "Edited from mwcli ~~~~" \
150
+ --kw summary="mwcli test edit" \
151
+ --kw bot=false
152
+ ```
153
+
154
+ ### File upload
155
+
156
+ Local file upload:
157
+
158
+ ```bash
159
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
160
+ --username "Admin" --password "secret" \
161
+ site upload \
162
+ --kw file="/tmp/example.png" \
163
+ --kw filename="Example.png" \
164
+ --kw description="Uploaded by mwcli"
165
+ ```
166
+
167
+ Upload from URL:
168
+
169
+ ```bash
170
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
171
+ --username "Admin" --password "secret" \
172
+ site upload \
173
+ --kw url="https://example.com/example.png" \
174
+ --kw filename="ExampleFromURL.png"
175
+ ```
176
+
177
+ ### Semantic MediaWiki ask API
178
+
179
+ ```bash
180
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
181
+ site ask --arg '[[Category:Item]]|?Has author|?Has status' --max-items 20
182
+ ```
183
+
184
+ With an explicit title context:
185
+
186
+ ```bash
187
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
188
+ site ask --arg '[[Category:Item]]|?Has author' --kw title="Main Page" --max-items 20
189
+ ```
190
+
191
+ Fetch all SMW properties for a page (`smwbrowse`):
192
+
193
+ ```bash
194
+ python -m mwcli --indent 2 --host host.docker.internal --scheme http --path /w/ \
195
+ site raw_api --arg smwbrowse --arg GET --kw browse=subject \
196
+ --kw params='"{\"subject\":\"Main Page\",\"ns\":0}"'
197
+ ```
198
+
199
+ Note: `smwbrowse` expects `params` as a JSON string, so pass a JSON object wrapped as a quoted string (double-encoded).
200
+
201
+ ### Arbitrary API calls
202
+
203
+ Use `get` / `post` / `api` / `raw_api` directly.
204
+
205
+ Get siteinfo:
206
+
207
+ ```bash
208
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
209
+ site get --arg query --kw meta=siteinfo --kw siprop='general|namespaces'
210
+ ```
211
+
212
+ Generic `api` call with GET method:
213
+
214
+ ```bash
215
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
216
+ site api --arg query --arg GET --kw prop=info --kw titles="Main Page"
217
+ ```
218
+
219
+ Raw API (no extra wrapper logic):
220
+
221
+ ```bash
222
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
223
+ site raw_api --arg query --arg GET --kw list=search --kw srsearch=space
224
+ ```
225
+
226
+ Parse wikitext/HTML directly as Markdown:
227
+
228
+ ```bash
229
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
230
+ site parse --kw text=$'== Header ==\n\nBody' --markdown
231
+ ```
232
+
233
+ `--markdown` currently applies to:
234
+
235
+ - `page text`
236
+ - `site parse`
237
+
238
+ Implementation uses `html2text`: https://pypi.org/project/html2text/
239
+
240
+ ### Page and image list iterators
241
+
242
+ Recent changes:
243
+
244
+ ```bash
245
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
246
+ site recentchanges --kw prop='title|timestamp|user|comment' --max-items 5
247
+ ```
248
+
249
+ Image usage:
250
+
251
+ ```bash
252
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
253
+ image "Example.png" imageusage --max-items 10
254
+ ```
255
+
256
+ ## Env vars
257
+
258
+ You can use env vars instead of flags:
259
+
260
+ - `MWCLI_HOST`
261
+ - `MWCLI_PATH` (default `/w/`)
262
+ - `MWCLI_EXT` (default `.php`)
263
+ - `MWCLI_SCHEME` (default `https`)
264
+ - `MWCLI_USERNAME`
265
+ - `MWCLI_PASSWORD`
266
+ - `MWCLI_USER_AGENT`
267
+
268
+ Then run shorter commands, for example:
269
+
270
+ ```bash
271
+ export MWCLI_HOST=host.docker.internal
272
+ export MWCLI_SCHEME=http
273
+ export MWCLI_PATH=/w/
274
+ python -m mwcli site search --arg "space" --kw what=text --max-items 5
275
+ ```
@@ -0,0 +1,264 @@
1
+ # mwcli
2
+
3
+ CLI wrapper around `mwclient`. Built for Agents.
4
+
5
+ Exposes `mwclient` methods from 3 targets:
6
+ - `site` -> `mwclient.Site`
7
+ - `page` -> `mwclient.page.Page`
8
+ - `image` -> `mwclient.image.Image`
9
+
10
+ ## Install
11
+
12
+ From project dir:
13
+
14
+ ```bash
15
+ pip install -r requirements.txt
16
+ pip install -e .
17
+ ```
18
+
19
+ ## Command shape
20
+
21
+ ```bash
22
+ python -m mwcli [connection flags] <site|page|image> <target args> <method> [--arg ...] [--kw ...] [--markdown]
23
+ ```
24
+
25
+ Connection flags:
26
+ - `--host` required (or `MWCLI_HOST`)
27
+ - `--scheme` default `https`
28
+ - `--path` default `/w/`
29
+ - `--ext` default `.php`
30
+ - `--username`, `--password` optional auth
31
+
32
+ Method args:
33
+ - `--arg VALUE` positional arg, JSON-parsed when possible
34
+ - `--kw KEY=VALUE` keyword arg, value JSON-parsed when possible
35
+ - `--max-items N` cap iterator/list output
36
+ - `--stream` print list/tuple one JSON per line
37
+ - `--markdown` convert content-read output to Markdown (see below)
38
+
39
+ Tip: quote strings with spaces/pipes.
40
+
41
+ ## Discover available methods
42
+
43
+ ```bash
44
+ python -m mwcli methods all
45
+ python -m mwcli methods site
46
+ python -m mwcli methods page
47
+ python -m mwcli methods image
48
+ ```
49
+
50
+ ## All commands
51
+
52
+ Top-level commands:
53
+
54
+ - `python -m mwcli methods {all|site|page|image}`
55
+ - `python -m mwcli site <method> [--arg ...] [--kw ...]`
56
+ - `python -m mwcli page "<title>" <method> [--arg ...] [--kw ...]`
57
+ - `python -m mwcli image "<title>" <method> [--arg ...] [--kw ...]`
58
+
59
+ `site` methods (mwclient 0.11.0):
60
+
61
+ - `allcategories`, `allimages`, `alllinks`, `allpages`, `allusers`
62
+ - `api`, `ask`, `blocks`, `checkuserlog`, `chunk_upload`, `clientlogin`
63
+ - `deletedrevisions`, `email`, `expandtemplates`, `exturlusage`
64
+ - `get`, `get_token`, `handle_api_result`, `logevents`, `login`
65
+ - `parse`, `patrol`, `post`, `random`, `raw_api`, `raw_call`, `raw_index`
66
+ - `recentchanges`, `require`, `revisions`, `search`, `site_init`
67
+ - `upload`, `usercontributions`, `users`, `version_tuple_from_generator`, `watchlist`
68
+
69
+ `page` methods:
70
+
71
+ - `append`, `backlinks`, `can`, `categories`, `delete`, `edit`, `embeddedin`
72
+ - `extlinks`, `get_token`, `handle_edit_error`, `images`, `iwlinks`, `langlinks`, `links`
73
+ - `move`, `normalize_title`, `prepend`, `purge`, `redirects_to`, `resolve_redirect`
74
+ - `revisions`, `save`, `strip_namespace`, `templates`, `text`, `touch`
75
+
76
+ `image` methods:
77
+
78
+ - all `page` methods, plus:
79
+ - `download`, `duplicatefiles`, `imagehistory`, `imageusage`
80
+
81
+ To confirm runtime command surface on your installed version:
82
+
83
+ ```bash
84
+ python -m mwcli methods all
85
+ ```
86
+
87
+ ## Main usage examples
88
+
89
+ ### Get page content
90
+
91
+ ```bash
92
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
93
+ page "Main Page" text
94
+ ```
95
+
96
+ Read one section:
97
+
98
+ ```bash
99
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
100
+ page "Main Page" text --kw section=1
101
+ ```
102
+
103
+ Read as Markdown (`page text` uses `site parse` + `html2text`):
104
+
105
+ ```bash
106
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
107
+ page "Main Page" text --markdown
108
+ ```
109
+
110
+ The markdown output starts with:
111
+
112
+ ```md
113
+ # Main Page
114
+ ```
115
+
116
+ ### Search
117
+
118
+ Full text search:
119
+
120
+ ```bash
121
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
122
+ site search --arg "space" --kw what=text --max-items 10
123
+ ```
124
+
125
+ Title-only search:
126
+
127
+ ```bash
128
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
129
+ site search --arg "Main" --kw what=title --max-items 10
130
+ ```
131
+
132
+ ### Authentication + edit
133
+
134
+ ```bash
135
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
136
+ --username "Admin" --password "secret" \
137
+ page "Sandbox" edit \
138
+ --arg "Edited from mwcli ~~~~" \
139
+ --kw summary="mwcli test edit" \
140
+ --kw bot=false
141
+ ```
142
+
143
+ ### File upload
144
+
145
+ Local file upload:
146
+
147
+ ```bash
148
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
149
+ --username "Admin" --password "secret" \
150
+ site upload \
151
+ --kw file="/tmp/example.png" \
152
+ --kw filename="Example.png" \
153
+ --kw description="Uploaded by mwcli"
154
+ ```
155
+
156
+ Upload from URL:
157
+
158
+ ```bash
159
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
160
+ --username "Admin" --password "secret" \
161
+ site upload \
162
+ --kw url="https://example.com/example.png" \
163
+ --kw filename="ExampleFromURL.png"
164
+ ```
165
+
166
+ ### Semantic MediaWiki ask API
167
+
168
+ ```bash
169
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
170
+ site ask --arg '[[Category:Item]]|?Has author|?Has status' --max-items 20
171
+ ```
172
+
173
+ With an explicit title context:
174
+
175
+ ```bash
176
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
177
+ site ask --arg '[[Category:Item]]|?Has author' --kw title="Main Page" --max-items 20
178
+ ```
179
+
180
+ Fetch all SMW properties for a page (`smwbrowse`):
181
+
182
+ ```bash
183
+ python -m mwcli --indent 2 --host host.docker.internal --scheme http --path /w/ \
184
+ site raw_api --arg smwbrowse --arg GET --kw browse=subject \
185
+ --kw params='"{\"subject\":\"Main Page\",\"ns\":0}"'
186
+ ```
187
+
188
+ Note: `smwbrowse` expects `params` as a JSON string, so pass a JSON object wrapped as a quoted string (double-encoded).
189
+
190
+ ### Arbitrary API calls
191
+
192
+ Use `get` / `post` / `api` / `raw_api` directly.
193
+
194
+ Get siteinfo:
195
+
196
+ ```bash
197
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
198
+ site get --arg query --kw meta=siteinfo --kw siprop='general|namespaces'
199
+ ```
200
+
201
+ Generic `api` call with GET method:
202
+
203
+ ```bash
204
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
205
+ site api --arg query --arg GET --kw prop=info --kw titles="Main Page"
206
+ ```
207
+
208
+ Raw API (no extra wrapper logic):
209
+
210
+ ```bash
211
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
212
+ site raw_api --arg query --arg GET --kw list=search --kw srsearch=space
213
+ ```
214
+
215
+ Parse wikitext/HTML directly as Markdown:
216
+
217
+ ```bash
218
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
219
+ site parse --kw text=$'== Header ==\n\nBody' --markdown
220
+ ```
221
+
222
+ `--markdown` currently applies to:
223
+
224
+ - `page text`
225
+ - `site parse`
226
+
227
+ Implementation uses `html2text`: https://pypi.org/project/html2text/
228
+
229
+ ### Page and image list iterators
230
+
231
+ Recent changes:
232
+
233
+ ```bash
234
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
235
+ site recentchanges --kw prop='title|timestamp|user|comment' --max-items 5
236
+ ```
237
+
238
+ Image usage:
239
+
240
+ ```bash
241
+ python -m mwcli --host host.docker.internal --scheme http --path /w/ \
242
+ image "Example.png" imageusage --max-items 10
243
+ ```
244
+
245
+ ## Env vars
246
+
247
+ You can use env vars instead of flags:
248
+
249
+ - `MWCLI_HOST`
250
+ - `MWCLI_PATH` (default `/w/`)
251
+ - `MWCLI_EXT` (default `.php`)
252
+ - `MWCLI_SCHEME` (default `https`)
253
+ - `MWCLI_USERNAME`
254
+ - `MWCLI_PASSWORD`
255
+ - `MWCLI_USER_AGENT`
256
+
257
+ Then run shorter commands, for example:
258
+
259
+ ```bash
260
+ export MWCLI_HOST=host.docker.internal
261
+ export MWCLI_SCHEME=http
262
+ export MWCLI_PATH=/w/
263
+ python -m mwcli site search --arg "space" --kw what=text --max-items 5
264
+ ```
@@ -0,0 +1,5 @@
1
+ """mwclient-cli package."""
2
+
3
+ from .cli import run
4
+
5
+ __all__ = ["run"]
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ main()