Skip to content
WM KeyboardWM Keyboard
Accessibility

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.

Terminal window
wmpy new my-tool # a plugin folder to start from
cd my-tool
wmpy check # what the keyboard would refuse
wmpy test # run the tests
wmpy pack # build my-tool's .wmplugin file

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

Terminal window
brew tap wasi-master/wmpy https://github.com/wasi-master/wmpy
brew install wmpy

Or, without Homebrew:

Terminal window
curl -fsSL https://raw.githubusercontent.com/wasi-master/wmpy/main/install.sh | sh

Check it works with wmpy --version. It prints its own version, the interpreter’s, and the plugin API level it runs.

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.

OptionDoes
-C DIRRuns as if wmpy had been started in DIR, as git -C does: wmpy -C plugins/weather pack. wmpy pip also takes --dir.
--color WHENauto (the default), always or never. Auto colours a terminal and GitHub Actions logs, and follows NO_COLOR, CLICOLOR_FORCE and FORCE_COLOR.
-q, --quietPrints 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.

Terminal window
wmpy upgrade
wmpy upgrade --check

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

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.

wmpy.toml
[check]
strict = true # wmpy check fails on warnings too
ignore = ["unused_local"] # codes never reported for this plugin
[run] # test, run, preview, render, budget, profile, repl
locale = "bn"
theme = "dark"
surface = "panel"
mock = "mocks/dev.json" # run, preview, render, budget, profile, repl
settings = { units = "imperial" } # run, preview, render
[test]
jobs = 4
fail-fast = true
[pack]
output = "dist" # a folder, or a file ending in .wmplugin
shake-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.

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.

Terminal window
wmpy preview --locale bn --theme dark
wmpy test --locale ar
Terminal window
wmpy new my-tool
wmpy 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.

OptionDoes
--templateWhat 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.
--nameThe plugin’s name, shown in the keyboard.
--idThe plugin’s id. By default my. and the name, such as my.weather.
--authorShown on the install screen.
--forceWrite into a folder that already has files in it.
--ci githubAlso write .github/workflows/plugin.yml, which checks, tests and packs the plugin on every push. See In CI.
--listPrint the templates, with what each one shows, and make nothing.
--jsonPrint 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.

Terminal window
wmpy check
wmpy check my-tool --strict

Finds 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, previews and syntax. 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/ and locales/, and the size limits.
  • Every .py file the plugin ships, with the checks the editors run: misspelt names, a module used without its permission, an address not in hosts, a provider or action plugin.json does 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.

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.

Terminal window
wmpy explain name_typo
wmpy explain

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

Terminal window
wmpy check --fix
wmpy 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.

Terminal window
wmpy fmt
wmpy fmt --check
wmpy fmt main.py --diff

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

OptionDoes
--checkChanges nothing. Lists the files that need formatting and exits with 1 if there are any.
--diffChanges nothing. Prints the changes as a unified diff and exits with 1 if there are any.
--allFormats the tests too.
--jsonPrints {"ok", "checked", "changed", "files"}.
Terminal window
wmpy permissions
wmpy permissions --strict

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

Terminal window
wmpy i18n extract --lang bn
wmpy i18n check
wmpy i18n stats

Reads the text your code passes to _(), gettext() and ngettext(), and the @name, @description, @action, @setting and @option keys of plugin.json.

  • extract adds each missing key to every locales/<tag>.json, empty. The keyboard shows the English for an empty translation, so a half-done file is safe to ship. --lang picks 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 as one, few and many for Russian.
  • check exits 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.
  • stats prints how much of each language is done.

See Translations.

Terminal window
wmpy test
wmpy test -k rot13
wmpy test --junit results.xml
wmpy test --watch

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

test.py
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.

OptionDoes
-k TEXTRuns only the tests whose file::name contains the text, such as -k rot13 or -k tests/test_api.py.
--jsonPrints {"ok", "passed", "failed", "durationMs", "tests"}, each test with its output and its error.
--junit FILEAlso writes the results as JUnit XML, which most CI services show as a table.
--watchRuns again each time a file in the folder changes. Stop it with Ctrl-C.
-j NRuns 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-fastStops at the first failing test.
--locale, --theme, --surfaceWhat 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.

Terminal window
wmpy mock record --out tests/mock.json
wmpy mock record --out tests/mock.json --tests --redact session_id

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

Terminal window
wmpy budget
wmpy budget --tests --device-speed 0.3
wmpy profile --top 10

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

Terminal window
wmpy render my-tool --mock mock.json
wmpy render --set units=imperial --locale bn --pretty

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

Terminal window
wmpy pack
wmpy pack -o dist/weather.wmplugin
wmpy pack --entry-json

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

OptionDoes
-o FILEWhere to write it.
--no-checkPacks without checking first.
--no-shake, --shake-symbolsTree shaking of packages from wmpy pip: off, or also inside modules. See Python packages.
--jsonPrints {"path", "size", "sha256", "entry", "shake"}.
--entry-jsonPrints only the entry for an addon repository’s wmkeyboard-repo.json, with the sha256 and sizeBytes filled in. See Publishing.
Terminal window
wmpy stubs

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

Terminal window
wmpy repl
wmpy repl my-tool --mock mock.json

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

CommandDoes
:renderDraws the plugin’s panel as text, loading it the first time.
:event JSONSends the panel an event and draws it again. A widget id alone is a click: :event button:Add.
:storageWhat the prompt and the panel saved.
:callsThe host calls the prompt and the panel made.
:load FILERuns a file at the prompt, as if you typed it.
:resetA fresh interpreter, and the panel loaded again.
:help, :quitThis 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.

Terminal window
wmpy device
wmpy push
wmpy dev
wmpy logs --since 10m

These four work with a phone over adb, once Plugin developer mode is on in the keyboard. See Test on your phone.

  • wmpy device lists 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. --json prints the same as JSON.
  • wmpy push checks 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. -s picks a phone when more than one is connected.
  • wmpy dev pushes 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 logs follows what a plugin prints on the phone, with errors in red. Give it a folder or a plugin id; --since 10m starts earlier. When the system log has nothing yet, it shows the plugin’s saved log. --json prints 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 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 sends the plugin to the community repository, or to an addon repository of your own. See Publishing.

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.

Terminal window
wmpy new my-tool --ci github

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

.github/workflows/plugin.yml
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.wmplugin

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

Terminal window
wmpy completions zsh > ~/.zfunc/_wmpy

Prints tab completion for bash, zsh, fish, elvish or powershell.