The Leanpub CLI
leanpub lets you work with your Leanpub books from the command line: preview and publish, upload finished files, manage coupons, and check sales. It's a single small program with nothing else to install.
It uses the Leanpub API, which is included with a Pro Author membership or above. It needs an API key.
Install with Homebrew
On macOS or Linux with Homebrew:
brew install leanpub/tap/leanpub
Homebrew keeps it up to date: brew upgrade leanpub.
Or download it
| Computer | Download |
|---|---|
| Mac with Apple silicon (M1 and later) | leanpub-aarch64-apple-darwin.tar.gz |
| Mac with an Intel processor | leanpub-x86_64-apple-darwin.tar.gz |
| Linux, x86-64 | leanpub-x86_64-unknown-linux-musl.tar.gz |
| Linux, ARM64 | leanpub-aarch64-unknown-linux-musl.tar.gz |
| Windows, x86-64 | leanpub-x86_64-pc-windows-gnu.zip |
The macOS builds are signed and notarized by Apple. The Linux builds are static, so they run on any distribution, Alpine included.
macOS and Linux
Unpack the file and move leanpub somewhere on your PATH. For example, on a Mac with Apple silicon:
tar -xzf leanpub-aarch64-apple-darwin.tar.gz
mkdir -p ~/.local/bin
mv leanpub ~/.local/bin/
leanpub --version
If your shell says command not found, ~/.local/bin isn't on your PATH yet. Add this line to ~/.zshrc (or ~/.bashrc) and open a new terminal:
export PATH="$HOME/.local/bin:$PATH"
Windows
Unzip the file and move leanpub.exe to a folder on your PATH. To make one: create %USERPROFILE%\bin, then open Edit environment variables for your account from the Start menu, edit Path, and add that folder. Open a new terminal and run leanpub --version.
The Windows build isn't code-signed yet, so Windows may warn you the first time you run it. Choose More info, then Run anyway.
Checking a download
Every release lists the SHA-256 checksum of each file. To check yours, download the list next to it:
curl -fsSLO https://leanpub.com/downloads/cli/latest/sha256.sum
shasum -a 256 --check --ignore-missing sha256.sum
Staying up to date
A downloaded leanpub keeps itself up to date. At most once a day, after a command finishes in your terminal, it checks for a new version. When one has been out for at least a day, it installs it, after checking that it's signed with Leanpub's release key and matches its checksum. Bigger version jumps are announced, not installed.
- Update now:
leanpub update, orleanpub update --checkto only look. - Only announce new versions: set
LEANPUB_AUTO_UPDATE=notify. - Never check: set
LEANPUB_AUTO_UPDATE=off. It never checks in CI either.
Get started
leanpub login # opens your API Keys page: create a key, then paste it here
leanpub books
leanpub preview my-book --wait
leanpub --help
On macOS and Windows the key is stored in the system keychain; on Linux in a file only you can read. In CI, skip leanpub login and set LEANPUB_API_KEY instead.
Which API key to create
Each API key has the access you choose when you create it on your API Keys page. Use Full access for the CLI on your own computer, and Preview and publish for CI. A key in CI expires too (after 1 year unless you choose otherwise); we email you 14 days before.
| Commands | Read only | Preview and publish | Full access |
|---|---|---|---|
| login, whoami, books, job | Yes | Yes | Yes |
| books view | Yes | No: it needs Read sales | Yes |
| preview, publish, upload, courses preview, courses publish | No | Yes | Yes |
| royalties, coupons, coupons view | Yes | No | Yes |
| coupons create, coupons update | No | No | Yes |
| sales, readers emails, readers interested | No | No | Yes |
| books create (and courses, bundles, tracks), unpublish, retire, close | No | No | Yes |
A command the key's access doesn't cover stops with a message that names the access it needs. Create a key with that access, or use Custom to choose exactly what a key can do.
Every command has --help, and --json on any command prints the API's fields as JSON.