Skip to main content
Travis-CI badge Coveralls badge PyPI - Implementation Latest release PyPI - License PyPI - Python Version Download format

mando is a wrapper around argparse, and allows you to write complete CLI applications in seconds while maintaining all the flexibility.

Installation

$ pip install mando

The problem

While argparse is great for simple command line applications with only one, default command, when you have to add multiple commands and manage them things get really messy and long. But don’t worry, mando comes to help!

Quickstart

from mando import command, main

@command
def echo(text, capitalize=False):
    '''Echo the given text.'''
    if capitalize:
        text = text.upper()
    print(text)

if __name__ == '__main__':
    main()

Generated help:

$ python example.py -h
usage: example.py [-h] {echo} ...

positional arguments:
  {echo}
    echo      Echo the given text.

optional arguments:
  -h, --help  show this help message and exit

$ python example.py echo -h
usage: example.py echo [-h] [--capitalize] text

Echo the given text.

positional arguments:
  text

optional arguments:
  -h, --help    show this help message and exit
  --capitalize

Actual usage:

$ python example.py echo spam
spam
$ python example.py echo --capitalize spam
SPAM

A real example

Something more complex and real-world-ish. The code:

from mando import command, main


@command
def push(repository, all=False, dry_run=False, force=False, thin=False):
    '''Update remote refs along with associated objects.

    :param repository: Repository to push to.
    :param --all: Push all refs.
    :param -n, --dry-run: Dry run.
    :param -f, --force: Force updates.
    :param --thin: Use thin pack.'''

    print ('Pushing to {0}. All: {1}, dry run: {2}, force: {3}, thin: {4}'
           .format(repository, all, dry_run, force, thin))


if __name__ == '__main__':
    main()

mando understands Sphinx-style :param:’s in the docstring, so it creates short options and their help for you.

$ python git.py push -h
usage: git.py push [-h] [--all] [-n] [-f] [--thin] repository

Update remote refs along with associated objects.

positional arguments:
  repository     Repository to push to.

optional arguments:
  -h, --help     show this help message and exit
  --all          Push all refs.
  -n, --dry-run  Dry run.
  -f, --force    Force updates.
  --thin         Use thin pack.

Let’s try it!

$ python git.py push --all myrepo
Pushing to myrepo. All: True, dry run: False, force: False, thin: False
$ python git.py push --all -f myrepo
Pushing to myrepo. All: True, dry run: False, force: True, thin: False
$ python git.py push --all -fn myrepo
Pushing to myrepo. All: True, dry run: True, force: True, thin: False
$ python git.py push --thin -fn myrepo
Pushing to myrepo. All: False, dry run: True, force: True, thin: True
$ python git.py push --thin
usage: git.py push [-h] [--all] [-n] [-f] [--thin] repository
git.py push: error: too few arguments

Amazed uh? Yes, mando got the short options and the help from the docstring! You can put much more in the docstring, and if that isn’t enough, there’s an @arg decorator to customize the arguments that get passed to argparse.

Type annotations

mando understands Python 3-style type annotations and will warn the user if the arguments given to a command are of the wrong type.

from mando import command, main


@command
def duplicate(string, times: int):
    '''Duplicate text.

    :param string: The text to duplicate.
    :param times: How many times to duplicate.'''

    print(string * times)


if __name__ == '__main__':
    main()
$ python3 test.py duplicate "test " 5
test test test test test
$ python3 test.py duplicate "test " foo
usage: test.py duplicate [-h] string times
test.py duplicate: error: argument times: invalid int value: 'foo'

Mando has lots of other options. For example, it supports different docstring styles (Sphinx, Google and NumPy), supports shell autocompletion via the argcomplete package and supports custom format classes. For a complete documentation, visit https://mando.readthedocs.org/.

Metadata

Release files for mando 0.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mando 0.8.2
File Size Uploaded
mando-0.8.2.tar.gz 37.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mando 0.8.2
File Interpreter ABI Platform
mando-0.8.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 65.5 kB

Release files / mando-0.8.2.tar.gz

Download URL mando-0.8.2.tar.gz
Size 37.7 kB
Tags Source
SHA-256 checksum
How to use checksums
539659d9a2fdc6c9a188211c58f381e0dafe9597085174c5472eb1ed0224b6b5
BLAKE2b-256 checksum
How to use checksums
c4a040bfacdeb638e89b0193385caccc712a4f1aee2b6ff6b4284adf2822f9ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.7

Release files / mando-0.8.2-py2.py3-none-any.whl

Download URL mando-0.8.2-py2.py3-none-any.whl
Size 27.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bad558078031366ee3bed2f290449be6788d8beaddcd20751105d30550534319
BLAKE2b-256 checksum
How to use checksums
4cb81ab29c34824be434c78026dcf59aba743ea0653130b945790af9488f4b2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.8.2 This release

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.4

2 release files

0.5

2 release files

0.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page