Skip to main content

cmdliner

Cmdliner is a python command line parsing library focus on extending scripts/applications with command line parsing features while requiring miminal code for the setup.

Minimal Use Case

The minimal use case provides --version and -v(vv) for verbosity:

from cmdliner import cli, verbose

# You just need to decorate your "main" function with cli(version)
# version is a required argument, it will be used to provide --version
@cli("1.0")
def main():
    print("hello")
    verbose(1, "You see this with -v")


# Instead of calling your main function directly you call cli(), it will handle
# the argument parsing and invoke the previously decorated function
if __name__ == "__main__":
    cli()

Testing:

$ python test.py
hello
$ python test.py --version
test.py 1.0
$ python test.py -v
hello
You see this with -v

Using command line arguments

from cmdliner import cli


@cli("1.0")
def main(name, age):
    print(f"{name} is {age} years old")


if __name__ == "__main__":
    cli()

Result:

$ python test.py
Missing required command line parameter 'name' !
Usage:
  test.py <name> <age>
$ python test.py Joe 12
Joe is 12 years old

How to install

pip install cmdliner

Metadata

Release files for cmdliner 0.0.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 cmdliner 0.0.2
File Size Uploaded
cmdliner-0.0.2.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cmdliner 0.0.2
File Interpreter ABI Platform
cmdliner-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 33.2 kB

Release files / cmdliner-0.0.2.tar.gz

Download URL cmdliner-0.0.2.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d64299d39e9f03960ef6074ec846fcea0e95aec7832802bebd0a90fe0b8e4bac
BLAKE2b-256 checksum
How to use checksums
0b22ab1de45c114b935141fbe864f00724555a3edd1b892aab95aef992f1930d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.4

Release files / cmdliner-0.0.2-py3-none-any.whl

Download URL cmdliner-0.0.2-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f66ce5d8f1daf6dbb4a3931cdd06419502c5ca9919533cafa0ff56b00d6d1f3
BLAKE2b-256 checksum
How to use checksums
67de62758975984ee6ae41f4432c02660eccbab5024864fa8512d9c089fb2569
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.4

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

0.0.0

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