Skip to main content

Rust Clap inspired command line argument parser.

Project description

clap-python

Command Line Argument Parser for Python

License PyPi

Licensed under Apache 2.0.

About

A full-featured, fast Command Line Argument Parser for Python

For more details, see:

Quick Start

pip install clap_python
from clap_python import App, Arg

app = (
    App()
    .version("0.1.0")  # Version of the app.
    .arg_required_else_help(True)  # If no args passed show help message.
    .arg(Arg("--name", "-n").help("Name of the person to greet").required(True))
    .arg(
        Arg("--count", "-c")
        .help("Number of times to greet")
        .default(1)
        .value_parser(int)  # tell the parser to cast arg to int.
    )
)

if __name__ == "__main__":
    args = app.parse_args()
    for _ in range(args["count"]):
        print(f"Hello {args['name']}!")

Positionals

from clap_python import App, Arg

if __name__ == "__main__":
    args = App().arg(Arg("names").multiple_values(True)).parse_args()
    print(f"names: {args['names']}")

Autocomplete

from clap_python import App, Arg
from clap_python.complete import autocomplete

app = App().arg(Arg("-c")).arg(Arg("--files").multiple_values(True))
autocomplete(app) # Enable autocompletion
args = app.parse_args() # Parse arguments
print(args)

You can read more at docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clap_python-0.2.2.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

clap_python-0.2.2-py3-none-any.whl (24.0 kB view details)

Uploaded Python 3

File details

Details for the file clap_python-0.2.2.tar.gz.

File metadata

  • Download URL: clap_python-0.2.2.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for clap_python-0.2.2.tar.gz
Algorithm Hash digest
SHA256 feed03666ddd43245746559752c9967861c5b474eb649c9e9d70575ba36a2131
MD5 b9cee4873f90abe9a42614e15e577d65
BLAKE2b-256 9d0c6c9f05e0638a52319958b0aa17983de40884ea694aaeffd1ba654ccad341

See more details on using hashes here.

File details

Details for the file clap_python-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: clap_python-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 24.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for clap_python-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2acd3ad455b8a51755881801b9787e9e2b13459d432902709421b6452c138156
MD5 76f213f4f82bc595e09c992037ddb609
BLAKE2b-256 16675685281c3ef2decc4f4b67799a6e7827c802deb4dab87be07ba69dabd109

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page