cpms, the LeanCPMS command line¶
cpms manages your organization in LeanCPMS Cloud from your own computer:
live state, sessions, the monthly settlements, members and keys, and the
declared state (price list, sites) as YAML documents you export, edit and
apply. The same commands work for people and for AI agents.
It talks to LeanCPMS Cloud unless you tell it otherwise. Running your own
instance? Log in once with cpms login --url https://…
(Running your own instance).
This directory builds leancpms-cli, the command without the server. It
depends on httpx, pydantic and PyYAML only.
Install¶
With uv, from PyPI. uv also fetches
Python 3.14, which cpms needs, if your computer lacks it:
curl -LsSf https://astral.sh/uv/install.sh | sh # if you do not have uv yet
uv tool install leancpms-cli
cpms --help
- Upgrade:
uv tool upgrade leancpms-cli. To pin a version:uv tool install leancpms-cli==0.1.7. - pipx works too, if Python 3.14 is already installed:
pipx install leancpms-cli. - Do not install it where the LeanCPMS server is installed: the server
already contains
cpms.
The examples assume a Unix shell (Linux or macOS).
Log in¶
Log in with the same e-mail address you use for the portal:
cpms login
It prints a code and opens the portal's page for it in your browser (or
prints the address only: --no-browser, or no display). Log in there if
you are not, check that the page shows the same code, choose your
organization and whether the key may act (write) or only look (read),
and approve. Your role as a member decides which you may choose: members
are read unless the operator, or a colleague with a write key, made
them write. cpms login waits for that and then saves a personal
key, yours and that organization's, in ~/.config/cpms/config.toml,
readable only by you.
cpms whoami # which key is in use, whose, for which organization
cpms --version # which cpms this is
cpms logout # revokes the key on the server and forgets it
The key stops working when you are removed as a member, and so does
every key you issued with it. Approve a code only if you just ran
cpms login yourself: whoever started it gets the key.
Users and access explains members, roles
and keys, with several computers, a lost computer, and common tasks.
Everyday commands¶
cpms # live state: sites, fuse groups, outlets, current per phase
cpms sessions --since 2026-11-01 --status ended
cpms sessions --since 2026-11-01 --csv > november.csv
cpms session SIM-0001/42 # one session: <charge point>/<transaction>
cpms session SIM-0001/42 stop # acts at once, no confirmation
cpms session SIM-0001/42 quarters # its energy per UTC quarter-hour
cpms quarters --since 2026-11-01 --until 2026-12-01 --csv > november-quarters.csv
cpms report settlements --month 2026-10 # the month's settlements per site, with bookkeeping proposals
cpms quarters gives one row per session and UTC clock quarter-hour
(:00, :15, :30, :45): the Wh delivered in it, to set against quarter-hour
spot prices. --site narrows, --json gives the same rows as JSON. The
first and last quarter of a session are usually shorter than 15 minutes
(seconds); estimated marks a quarter computed across a gap in the meter
samples, and final is False (the table says open) for the quarter a
running session is in, which will still grow. phases is how many phases
carried charging current in the quarter (the most at once, at least 1 A,
as the box measured it; empty when the box reported no currents in it). A session's quarters sum to
exactly its wh. Energy only: there are no prices in it.
Who is a member, and with which role
cpms members list
cpms members add ben@example.com --org acme # read
cpms members add carla@example.com --org acme --role write
cpms members set-role ben@example.com --org acme --role write
cpms members remove ben@example.com --org acme
--org acme is needed even though your key is already for acme.
Keys
cpms keys list # every key of the organization, revoked ones too
cpms keys issue --name dashboard --scope read # prints the secret once
cpms keys revoke 7b2d90aa
Every command takes --json for machine-readable output.
cpms --help and cpms <command> --help list the rest.
Managing your documents¶
Your organization's price list and each of its sites are YAML documents on the server. You change one by exporting it, editing the file, and applying it. No git repository is needed:
-
Export the document into a file:
cpms manifest export acme --site main-street > site.yaml--pricelistexports the price list instead,--organizationthe organization document, and with none of them you get every document in one file. -
Edit the file in any text editor.
-
Check it, see what would change, and apply it:
cpms manifest validate site.yaml # offline: the schema; needs no key cpms manifest plan site.yaml # the server: the diff, references, live warnings cpms manifest apply site.yaml -m "Fused up to 50 A"applyshows the plan again and asks before it applies.-m, the reason, is required and stored with the version.
The server keeps every version. Each apply is stored with its message, who applied it and when, so you can always see what changed and get an older version back:
cpms manifest history acme --site main-street # every version, with its message
cpms manifest export acme --site main-street --version 3 > v3.yaml
cpms manifest diff acme --site main-street v3 # from version 3 to the current one
Some things to know:
planandapplyneed awritekey; exporting and history need onlyread.- Someone else may apply the same document while you edit. Your
planthen shows that your file would undo their change: export again and redo your edit.applyapplies exactly the plan it showed you, and refuses if the document changed on the server before you confirmed; run it again and read the new plan. - Removing anything (a charge point, an outlet, a tariff) needs
--pruneonplanandapply. - The organization document is changed by the operator. An organization's key applies the price list and the site documents, so export them one at a time when you mean to apply them.
- An outlet's
public_idis the id in its QR code (/c/<public_id>). Leave it out and the server makes one up on first apply and keeps it. Once the codes are printed, write the ids into the site file (- {connector: 1, key: s1-1, public_id: h7k2m9pq}): a declared id applies, also on a new server, andplanwarns before an outlet's id changes.
Keeping the files in a repository¶
For a team, keeping the files in a git repository of your own is a good habit: you review each other's changes before they are applied, and CI can check every change. It is not required; the server's history is the record either way. One file per document works well:
organization.yaml
pricelist.yaml
sites/main-street.yaml
sites/harbour.yaml
Edit a file, run validate and plan, commit, then run apply with the
commit's reason as -m. The server holds the truth and the files are a
way to say things: if someone else applied a change, plan shows that
applying your file would undo it, and export brings the file up to date.
validate needs no key, so CI can run it on every pull request; plan
needs one.
In your editor: the JSON Schema¶
The documents have a JSON Schema, so an editor can complete field names and flag mistakes as you type. That works in editors that use yaml-language-server: VS Code with Red Hat's YAML extension, Neovim, Helix, Zed. Add this line at the top of each file:
# yaml-language-server: $schema=https://raw.githubusercontent.com/forsslund/leancpms/main/schema/manifest.cpms-v1.schema.json
That URL works once the repository is public; replace main with a tag
to pin a version. Until then, use a local copy, written by the command
itself and kept next to your files:
cpms manifest schema > cpms-v1.schema.json
# yaml-language-server: $schema=cpms-v1.schema.json
The path is relative to the YAML file (../cpms-v1.schema.json from
sites/). export does not write the line, so add it again after an
export.
The schema checks types, required and unknown fields, allowed values,
key spelling, and that amounts are quoted ("4.70", not 4.70). It does
not check anything that spans several fields: a budget above the fuse,
duplicate keys, ocpp ids or public ids, a plan naming a missing tariff, or
an unknown time zone. validate and plan check those. Only plan
knows whether another outlet on the server already has a public id.
Scripts, CI and agents¶
A pipeline, a dashboard or an agent of its own gets a key for an
integration, which records who issued it: cpms keys issue --name ci
--scope read with your personal write key. It is shown only once. A key
you issue lives only as long as your membership: when you leave, it is
revoked with your own. An integration that must outlive you gets its key
from the operator.
Give the script the key in the environment variable CPMS_API_KEY, never
on the command line, where it ends up in shell history and process lists.
That is all LeanCPMS Cloud needs; against another instance, set CPMS_URL
too. Without --profile, the environment wins over your own login. A
command that finds no key exits 2 and says what to set. cpms logout
with a key from CPMS_API_KEY revokes it but cannot remove it from the
environment; unset it.
--jsonworks on every command, before or after the subcommand.- Exit codes: 0 ok, 1 the action failed (the server said no, the server could not be reached, a plan has errors), 2 usage or configuration.
cpms manifest applynever prompts without a TTY. It prints the plan and exits 2 unless you pass--yes. Show the plan to a person first, then apply with--yes -m "why".session … stop|closeacts at once, with no confirmation step.- Pass the key in the environment or the config file, never on the command line or in a transcript.
Releasing (maintainers)¶
Raise version in both cli/pyproject.toml and the root pyproject.toml
(a test keeps them equal), then tag and push:
git tag cli-v0.1.7 && git push origin cli-v0.1.7
.github/workflows/release-cli.yml builds the wheel and sdist, smoke-tests
the wheel, and attaches both to a GitHub release. It also publishes to PyPI
when the repository variable PYPI_PUBLISH is true. That needs, once:
a PyPI account with two-factor authentication; a pending trusted
publisher on PyPI for the project leancpms-cli (owner forsslund,
repository leancpms, workflow release-cli.yml, environment pypi);
and an environment pypi in the GitHub repository's settings. A pending
publisher does not reserve the name: if someone else registers
leancpms-cli first, it becomes invalid. The first release creates the
project and so reserves the name. Trusted publishing uses GitHub's OIDC
token, so no PyPI token is stored anywhere. A file published to PyPI cannot be replaced,
only yanked: a wrong release is fixed with a new version.