The wmpy command line
Install wmpy, then make, check, test and pack WM Keyboard plugins on your computer, with the same interpreter and checks the keyboard uses.
wmpy is a command-line tool for plugins. It runs on your computer, in a
folder of plain files you edit in any editor, and it uses the same
interpreter and the same checks as the keyboard and the plugin editors.
wmpy new my-tool # a plugin folder to start fromcd my-toolwmpy check # what the keyboard would refusewmpy test # run the testswmpy pack # build my-tool's .wmplugin fileYou do not need it to write a plugin. The plugin editor in the browser and the one on the phone do everything here except the command line. wmpy is for people who prefer their own editor, keep plugins in Git, or test them in CI.
Install
Section titled “Install”brew tap wasi-master/wmpy https://github.com/wasi-master/wmpybrew install wmpyOr, without Homebrew:
curl -fsSL https://raw.githubusercontent.com/wasi-master/wmpy/main/install.sh | shscoop bucket add wmpy https://github.com/wasi-master/wmpyscoop install wmpyOr, without Scoop, in PowerShell:
irm https://raw.githubusercontent.com/wasi-master/wmpy/main/install.ps1 | iexpipx install wmpy# oruv tool install wmpyWith Node.js, run it without installing:
npx wmpy --helpInstall Rust, then:
cargo install --git https://github.com/wasi-master/wmkeyboard wmpyCheck it works with wmpy --version. It prints its own version, the
interpreter’s, and the plugin API level it runs.
How commands work
Section titled “How commands work”Every command takes the plugin folder as its first argument, and uses the
folder you are in when you leave it out. A command exits with 0 when all
went well, 1 when the plugin failed (a check, a test), and 2 when wmpy could
not do the work, such as a folder that does not exist. wmpy --help lists
the commands in groups, with these codes and a few examples at the end.
Options every command takes
Section titled “Options every command takes”| Option | Does |
|---|---|
-C DIR | Runs as if wmpy had been started in DIR, as git -C does: wmpy -C plugins/weather pack. wmpy pip also takes --dir. |
--color WHEN | auto (the default), always or never. Auto colours a terminal and GitHub Actions logs, and follows NO_COLOR, CLICOLOR_FORCE and FORCE_COLOR. |
-q, --quiet | Prints only problems and results: no progress lines, hints or summaries of success. wmpy -q pack prints the archive’s path and nothing else. |
They go before or after the command: wmpy -q test and wmpy test -q are
the same.
Keep wmpy up to date
Section titled “Keep wmpy up to date”wmpy upgradewmpy upgrade --checkwmpy upgrade installs the newest release the way this wmpy was installed:
brew upgrade, scoop update, npm install -g, pipx upgrade,
uv tool upgrade or cargo install. A wmpy from the install scripts, or one
you copied by hand, downloads the release archive for your computer, checks
it against its SHA-256 and replaces itself. --check only says whether a
newer one is out, and --version 0.2.0 picks one.
Once a day at most, a command run in a terminal asks GitHub which release is
newest, in the background while it runs, and the next run after a newer one
appears ends with a line saying so. It never asks in CI (when CI is set),
with --quiet, from the language server or the MCP server, or when output is
meant for scripts. The request carries no more than wmpy/<version>. Set
WMPY_NO_UPDATE_CHECK=1 to turn it off.
wmpy.toml
Section titled “wmpy.toml”A plugin can keep its own settings for wmpy in a wmpy.toml beside
plugin.json, or in the [tool.wmpy] table of a pyproject.toml. Options
on the command line win over both, and neither file goes into the
.wmplugin.
[check]strict = true # wmpy check fails on warnings tooignore = ["unused_local"] # codes never reported for this plugin
[run] # test, run, preview, render, budget, profile, repllocale = "bn"theme = "dark"surface = "panel"mock = "mocks/dev.json" # run, preview, render, budget, profile, replsettings = { units = "imperial" } # run, preview, render
[test]jobs = 4fail-fast = true
[pack]output = "dist" # a folder, or a file ending in .wmpluginshake-symbols = true
[device]serial = "192.168.1.20:5555"Paths are read from the plugin folder. A key wmpy does not know is a warning, so a typo does not go unseen, and a value of the wrong kind stops the command with exit code 2.
Locale, theme and surface
Section titled “Locale, theme and surface”wmpy test, run, preview, render, repl, budget, profile and
mock record take --locale, --theme and --surface, which are what the
plugin reads as plugin.locale, plugin.theme (and plugin.dark) and
plugin.surface. An API 5 plugin is translated with the locales/<tag>.json
the keyboard would pick for that locale: the whole tag, then the language,
so --locale pt-BR uses pt-BR.json, or else pt.json. A locale no file
fits shows the English, and wmpy says so. wmpy preview draws the panel
right to left for Arabic, Persian, Hebrew, Urdu and the other right-to-left
languages.
wmpy preview --locale bn --theme darkwmpy test --locale arwmpy new
Section titled “wmpy new”wmpy new my-toolwmpy new weather --template weather --name "Weather" --author "Your Name"Makes a folder with a working plugin in it. Run in a terminal with no options, it asks for the name, the template and the author. In a script it takes the defaults: a blank plugin named after the folder.
| Option | Does |
|---|---|
--template | What to start from: blank, text-tools, cipher, todo, kitchen-sink, text-generator, weather or text-actions. The same plugins the editors offer under Start from. |
--name | The plugin’s name, shown in the keyboard. |
--id | The plugin’s id. By default my. and the name, such as my.weather. |
--author | Shown on the install screen. |
--force | Write into a folder that already has files in it. |
--ci github | Also write .github/workflows/plugin.yml, which checks, tests and packs the plugin on every push. See In CI. |
--list | Print the templates, with what each one shows, and make nothing. |
--json | Print what it made as JSON. |
The folder it makes:
my-tool/├── plugin.json├── main.py├── test.py├── .gitignore leaves out .wmpy/ and built .wmplugin files├── pyrightconfig.json points Pylance and pyright at the stubs├── .vscode/extensions.json suggests the wmpy extension in VS Code└── .wmpy/stubs/ the wm package, for editors (see wmpy stubs)Every template but cipher is written for API 5, from wm import. The
cipher is the plugin the API 4 guide builds,
with the older wm and ui globals, and keeps "apiVersion": 4.
wmpy check
Section titled “wmpy check”wmpy checkwmpy check my-tool --strictFinds what the keyboard would refuse or trip over, without running the plugin:
plugin.json, by the rules the app uses when it installs a plugin: the id, name and version,apiVersion, every permission,hosts,tool,settings,providers,actions,previewsandsyntax. Each problem points at its line in the file, and an error the install screen would show says so in the app’s own words.- The archive the folder becomes: the entry script, other modules, files in
assets/andlocales/, and the size limits. - Every
.pyfile the plugin ships, with the checks the editors run: misspelt names, a module used without its permission, an address not inhosts, a provider or actionplugin.jsondoes not declare, and Python plugins cannot run. Test files are checked for syntax only.
A problem that fails for certain when its line runs is an error: a name that
is not defined (a NameError), a call that needs a permission plugin.json
does not ask for, and an address on a host it does not list. A name looked up
inside a try that catches NameError, or in a module that makes names at
run time (with globals(), exec, setattr or a module __getattr__), is a
warning instead.
error[unknown_permission]: WM Keyboard does not know the permission "netwrok" --> plugin.json:8:30 |8 | "permissions": ["storage", "netwrok"], | ^^^^^^^^^ = note: the app refuses it: This version of WM Keyboard does not know the permission “netwrok”. … = help: did you mean "network"? The permissions: https://wmkeyboard.pages.dev/plugins/permissions/It ends with a line such as checked plugin.json and 3 Python files: 1 error, 0 warnings. It exits with 1 when there is an error. --strict (or
strict = true under [check] in wmpy.toml) fails on warnings
too, --watch checks again each time you save, and --json prints
{"ok", "errors", "warnings", "problems"} for other tools.
Silence a problem
Section titled “Silence a problem”When wmpy is wrong about a line, say so on the line:
value = registry[name] # wmpy: ignore[undefined_name]total = compute() # wmpy: ignore# wmpy: ignore[code, code] silences those codes on its line, and a bare
# wmpy: ignore silences every code there. # wmpy: ignore-file[code]
anywhere in a file silences the code in the whole file, and ignore under
[check] in wmpy.toml in the whole plugin. The editors and the
language server read the same comments. Python the keyboard cannot read,
such as an unclosed string, cannot be silenced: the keyboard refuses the file
whatever the comment says.
What a code means
Section titled “What a code means”wmpy explain name_typowmpy explainEach problem has a code in brackets, error[host_missing]. wmpy explain
says what one means, whether a quick fix exists, how to silence it and where
the docs say more; with no code it lists them all, from the checks of the
Python, of plugin.json and of packages from PyPI. --json prints the same.
Fix what it finds
Section titled “Fix what it finds”wmpy check --fixwmpy check --fix --dry-run--fix makes the changes the editors’ quick fixes make, then checks again
and prints what is left. It corrects a misspelt name, adds a missing import,
writes a stub for a provider that plugin.json declares, and adds what
plugin.json is missing: a permission, a provider, an action, a keyword or
a setting. Changes to plugin.json keep the file’s layout.
One fix can make another possible, so it repeats until nothing changes, at
most five times, and lists each change under its file. A risky permission
and a new host are choices your users see when they install or update, so
--fix lists them and adds them only with --fix-risky. It never replaces a
tool.keyword that is already set. --dry-run prints the changes as a
unified diff and writes nothing.
wmpy fmt
Section titled “wmpy fmt”wmpy fmtwmpy fmt --checkwmpy fmt main.py --diffFormats the plugin’s Python files the way Format does in the editors. It changes only whitespace: four spaces a level, one style for spacing and blank lines. Comments, strings and numbers stay as you wrote them.
With no paths it formats the entry script and its modules. Tests (test.py
and tests/) join with --all or when you name them. Packages that
wmpy pip added are left alone unless you name them. A file outside a
plugin folder is refused.
| Option | Does |
|---|---|
--check | Changes nothing. Lists the files that need formatting and exits with 1 if there are any. |
--diff | Changes nothing. Prints the changes as a unified diff and exits with 1 if there are any. |
--all | Formats the tests too. |
--json | Prints {"ok", "checked", "changed", "files"}. |
wmpy permissions
Section titled “wmpy permissions”wmpy permissionswmpy permissions --strictLists each permission plugin.json declares or the code needs, with the
calls that need it by file and line, then each host with the addresses that
reach it. A permission is needed, unused or missing. Missing means a call
raises PermissionError on the phone. Unused is a suggestion; a module that
is imported but never called counts as unused.
For hosts it reads the addresses the code writes out: a string, the start of
an f-string, or a name set once at the top of a file. *.example.org covers
its subdomains, and an entry a wildcard already covers is marked. When a
request builds its address at run time, a host nothing names is marked
unknown rather than unused.
It exits with 1 when something is missing. --strict also fails on unused
entries, and --json prints the report.
wmpy i18n
Section titled “wmpy i18n”wmpy i18n extract --lang bnwmpy i18n checkwmpy i18n statsReads the text your code passes to _(), gettext() and ngettext(), and
the @name, @description, @action, @setting and @option keys of
plugin.json.
extractadds each missing key to everylocales/<tag>.json, empty. The keyboard shows the English for an empty translation, so a half-done file is safe to ship.--langpicks languages and starts a file that does not exist yet. Your translations are kept. A key nothing uses any more is listed, and removed only with--prune. A plural gets the forms its language needs, such asone,fewandmanyfor Russian.checkexits with 1 when a translation is missing or empty, uses a{name}the English lacks or drops one, or lacks a plural form. Text that is not a literal, such as_(title), gets a warning: write_("Hi {name}", name=name)instead.statsprints how much of each language is done.
See Translations.
wmpy test
Section titled “wmpy test”wmpy testwmpy test -k rot13wmpy test --junit results.xmlwmpy test --watchRuns test.py and every tests/test_*.py, each in a fresh interpreter. A
file’s top level runs first. Then each top-level function whose name starts
with test_ runs on its own, and fails if it raises. A file with no test
functions is one test, as test.py always was.
import json
def test_it_loads(): s = plugin_test.session() r = s.load() assert r.ok, r.error
def test_rot13(): s = plugin_test.session() s.load() assert s.transform("Hello", "rot13").value == "Uryyb"
def test_in_bengali(): s = plugin_test.session(locale="bn") assert "খুঁজুন" in json.dumps(s.load().ui, ensure_ascii=False)A session and its results read as attributes, s.load() and r.ok, or as
keys, s["load"]() and r["ok"], which older tests use.
What the tests print goes to the terminal as they run. Each test’s result
and each failure, with the line it stopped on, go after it, and the last line
is the count: 2 passed, 0 failed in 0.05 s. When a test fails on a result
whose call failed, as assert r.ok, r.error does, the report leads with the
plugin’s own error, at its line in the plugin’s file with its traceback, and
names the line of the test that stopped as a note.
| Option | Does |
|---|---|
-k TEXT | Runs only the tests whose file::name contains the text, such as -k rot13 or -k tests/test_api.py. |
--json | Prints {"ok", "passed", "failed", "durationMs", "tests"}, each test with its output and its error. |
--junit FILE | Also writes the results as JUnit XML, which most CI services show as a table. |
--watch | Runs again each time a file in the folder changes. Stop it with Ctrl-C. |
-j N | Runs N test files at once, each in its own interpreter; -j 0 is one per processor. Their prints then come with each result. |
-x, --fail-fast | Stops at the first failing test. |
--locale, --theme, --surface | What the plugin is told, for every session the tests make that does not name its own. See Locale, theme and surface. |
Testing and debugging explains
plugin_test: sessions, mock answers for host calls, events, previews and
the rest.
wmpy mock record
Section titled “wmpy mock record”wmpy mock record --out tests/mock.jsonwmpy mock record --out tests/mock.json --tests --redact session_idRuns the plugin with real https to the hosts in its plugin.json, and
writes every call it made to the keyboard, with the reply, to a mock file
that plugin_test.session(mock=...), wmpy render --mock and
wmpy budget --mock read. Record once against the real service, then test
against the file, offline and the same every time.
It runs a scenario (--scenario events.json), the plugin’s tests
(--tests, whose own mocks are set aside), or by default a click on each
button of the first draw. Each address becomes a route, and the address is
cut to a * where a key or token starts, so the route still fits when the
test uses another key.
Secrets are replaced with <redacted>: the Authorization, Cookie and
API-key headers, query values and JSON fields named key, token,
api_key, apikey, access_token, secret, password or sig, the
plugin’s own secrets and whatever secrets.get answered. --redact NAME
adds a name. Read the file before you commit it all the same.
wmpy budget and wmpy profile
Section titled “wmpy budget and wmpy profile”wmpy budgetwmpy budget --tests --device-speed 0.3wmpy profile --top 10The keyboard stops a plugin that takes too long: 9 million steps or 3
seconds to load, 6 million or 2 seconds for an event, 1.2 million or half a
second for a draw. wmpy budget runs the plugin and shows how close each
kind of call came, as a share of each limit, with the worst call. Over 50%
is a warning, over 80% is in danger, and it exits with 1 when anything went
over, so a CI job can fail on it.
Time is the plugin’s own: time spent waiting for the internet or the AI is
left out, as the keyboard leaves it out. A phone is slower than a computer,
so give --device-speed (0.3 for a phone three times slower). On a slow
phone the time, not the steps, is what stops a plugin.
wmpy profile runs the same way with every def timed, and lists the
functions that took the most time, with their calls and average. A
function’s time includes the functions it calls.
Both run a scenario (--scenario events.json), the tests (--tests, or
-k TEXT, which runs the tests it matches), or by default a click on each
button of the first draw and each timer once. They take --locale,
--theme and --surface too. --mock FILE answers host calls before the real ones are made,
and --json prints the report. Storage, settings and secrets are copied
first, so a measured run leaves your plugin’s saved state alone.
wmpy render
Section titled “wmpy render”wmpy render my-tool --mock mock.jsonwmpy render --set units=imperial --locale bn --prettyLoads the plugin as a panel and prints its first draw as JSON, with host
calls answered from the mock file. It is the quickest way to see what a
change does to the widget tree. --set KEY=VALUE gives a setting a value
for the draw, --locale, --theme and --surface say what the plugin is
told, and --pretty indents the JSON. It exits with 1 when the draw failed.
wmpy pack
Section titled “wmpy pack”wmpy packwmpy pack -o dist/weather.wmpluginwmpy pack --entry-jsonBuilds the .wmplugin file the keyboard installs. It checks the plugin first
and refuses to pack one with an error. The file goes in the plugin folder as
<Name>-<version>.wmplugin, the name the editors give it, or where output
under [pack] in wmpy.toml says. The command prints the path on
its own line, then its size and SHA-256 (left out with -q).
What goes in: plugin.json, the entry script, and for API 5 the other .py
files, assets/ and locales/. The licenses/ folder goes in too, with the
licence of each package wmpy pip added. The keyboard does not keep those
files when it installs the plugin, but they stay in the file you share.
Tests, tests/, dotfiles, __pycache__, pyrightconfig.json, wmpy.lock,
wmpy.toml, pyproject.toml and other .wmplugin files stay out. The
archive is the same byte for byte each time you pack the same files, so its
SHA-256 only changes when the plugin does.
| Option | Does |
|---|---|
-o FILE | Where to write it. |
--no-check | Packs without checking first. |
--no-shake, --shake-symbols | Tree shaking of packages from wmpy pip: off, or also inside modules. See Python packages. |
--json | Prints {"path", "size", "sha256", "entry", "shake"}. |
--entry-json | Prints only the entry for an addon repository’s wmkeyboard-repo.json, with the sha256 and sizeBytes filled in. See Publishing. |
wmpy stubs
Section titled “wmpy stubs”wmpy stubsWrites type stubs of the wm package to .wmpy/stubs/, so Pylance,
pyright, mypy and PyCharm know from wm import plugin, ui: every function
and its arguments, with the reference’s text as its help. They also cover
plugin_test in test files, and the wm and ui globals of an API 4
plugin. wmpy new writes them for you; run this again after updating wmpy.
--json prints the folder and the files written.
The pyrightconfig.json from wmpy new has "stubPath": ".wmpy/stubs".
For mypy, set MYPYPATH=.wmpy/stubs. In PyCharm, mark .wmpy/stubs as a
sources root.
The stubs give names, arguments and help. Whether a call is allowed, such as
a module used without its permission, is what wmpy check and the
language server tell you.
wmpy run and wmpy preview
Section titled “wmpy run and wmpy preview”wmpy run runs the plugin in the terminal: its panel, its buttons and its
log. wmpy preview opens it in the browser and draws it again each time you
save. Both take --locale, --theme and --surface, and read the mock and
the settings under [run] in wmpy.toml. See
Terminal and browser preview.
wmpy repl
Section titled “wmpy repl”wmpy replwmpy repl my-tool --mock mock.jsonA Python prompt on the keyboard’s own interpreter, with the wm package.
Inside a plugin folder it has the plugin’s permissions and its modules
(import helpers, and import main for the entry script). Outside one,
every permission is on and any https address can be reached. Host calls go
where wmpy run sends them: real https, a pretend text box and clipboard,
and pretend answers for what only a phone has, with --mock answering
first.
It reads input as CPython’s prompt does: a line ending in : opens a block
that a blank line ends, and open brackets or strings carry on to the next
line. An expression’s value is printed and kept as _. Ctrl-C stops a
runaway loop and keeps everything else.
| Command | Does |
|---|---|
:render | Draws the plugin’s panel as text, loading it the first time. |
:event JSON | Sends the panel an event and draws it again. A widget id alone is a click: :event button:Add. |
:storage | What the prompt and the panel saved. |
:calls | The host calls the prompt and the panel made. |
:load FILE | Runs a file at the prompt, as if you typed it. |
:reset | A fresh interpreter, and the panel loaded again. |
:help, :quit | This list, and leave (Ctrl-D works too). |
The history is kept between runs unless you add --no-history. Piped
input runs as a script, printing only the results.
wmpy device, push, dev and logs
Section titled “wmpy device, push, dev and logs”wmpy devicewmpy pushwmpy devwmpy logs --since 10mThese four work with a phone over adb, once Plugin developer mode is on in the keyboard. See Test on your phone.
wmpy devicelists the phones adb sees, whether WM Keyboard is installed on each, and whether developer mode is on. When it is off, it says where the switch is.--jsonprints the same as JSON.wmpy pushchecks the plugin, packs it and installs it on the phone without the install screen. Risky permissions stay off until you turn them on, and the reply names them.-spicks a phone when more than one is connected.wmpy devpushes the plugin, then pushes it again each time you save a file in its folder. An open panel loads the new version, and the plugin’s log prints in the same terminal until you press Ctrl-C.wmpy logsfollows what a plugin prints on the phone, with errors in red. Give it a folder or a plugin id;--since 10mstarts earlier. When the system log has nothing yet, it shows the plugin’s saved log.--jsonprints each line as{"time", "level", "plugin", "text"}on a line of its own.
serial under [device] in wmpy.toml names the phone when
more than one is connected, as -s does.
wmpy pip
Section titled “wmpy pip”wmpy pip install copies a pure-Python package from PyPI into the plugin, after
checking that it can run in the keyboard. wmpy pack then leaves out the
parts the plugin never imports. wmpy.lock keeps what you asked for, so
wmpy pip update stays inside "python-dateutil>=2.8,<3"; wmpy pip verify
checks the vendored files against the SHA-256 the lock keeps of each, and
wmpy pip sync puts back what is missing or changed. -r requirements.txt
installs a list. See Python packages,
and Which packages work for the
results of checking the most used ones.
requests and httpx are built into the keyboard, so wmpy pip install requests says so, exits with 0 and downloads nothing. A package that depends
on one of them installs without it, and wmpy.lock does not list it. See
requests, httpx and urllib.
wmpy publish
Section titled “wmpy publish”wmpy publish sends the plugin to the community repository, or to an addon
repository of your own. See Publishing.
wmpy lsp, wmpy mcp and wmpy editor
Section titled “wmpy lsp, wmpy mcp and wmpy editor”wmpy lsp is the language server editors talk to, with the same suggestions,
checks and fixes as the plugin editor. See Language server.
wmpy mcp gives an AI coding agent the same tools. See AI agents.
wmpy editor installs the wmpy extension for VS Code, Zed or a JetBrains
IDE. See Editors.
wmpy new my-tool --ci githubwrites a GitHub Actions workflow that installs wmpy with its action, then
runs wmpy check --strict, wmpy test --junit test-results.xml and
wmpy pack, and keeps the .wmplugin and the test results as an artifact:
steps: - uses: actions/checkout@v7 - uses: wasi-master/wmpy@v0 - run: wmpy check --strict - run: wmpy test --junit test-results.xml - run: wmpy pack -o plugin.wmpluginwasi-master/wmpy@v0 installs the newest wmpy 0.x release on Linux, macOS
or Windows runners and puts it on the PATH; with: version: 0.1.0 pins
one. In other CI services, use the install script. Colour is on
in GitHub Actions logs; elsewhere, pass --color always.
wmpy completions
Section titled “wmpy completions”wmpy completions zsh > ~/.zfunc/_wmpyPrints tab completion for bash, zsh, fish, elvish or powershell.
