Skip to main content

argparsh - python argparse for the shell

Ever wanted to parse arguments in bash but felt frustrated by giant case blocks and unfriendly syntax? Ever tried getopts but ended up curled on the floor sobbing? Have you ever spent sleepless nights hoping that bash argument parsing could be as simple as python's argparse? Maybe argparsh is for you.

argparsh aims to provide an easy way to construct an argument parsing program from any shell.

Usage

# Create a parser that accepts a string and an optional int value
parser=$({
    # Initialize the parser with the name of the script and a description
    argparsh new $0 -d "Example parser"

    # Add a positional argument - note that args after -- are options to add_arg
    # and not aliases for the argument
    argparsh add_arg strarg -- --help "My string argument"

    # Add a keyword argument that can either be -i <value> or --intarg <value>
    argparsh add_arg -i --intarg -- \
        --help "My int argument" \
        --type int \
        --default 10
})

# Parse the input arguments with the parser above
eval $(argparsh parse $parser -- "$@")

# Access parsed arguments by name
echo "String argument was" $strarg
echo "Integer argument was" $intarg

See example.sh for a more complete example, and examples of alternate output formats (e.g. parsing CLI arguments into an associative array)

Installation

No dependencies besides python/pip.

pip install argparsh

Or, to build from source:

git clone https://github.com/aneeshdurg/argparsh.git
cd argparsh
pip install .

Similar Works

argparsh differs from previous attempts at improving shell argument parsing by being shell agnostic (although only bash is tested, it is relatively easy to add support for more shells, contributions are welcome), supporting subcommands/subparsers, and allowing detailed + customizable help text to be configured.

  • getopts
    • the OG argument handling utility. A bit clunky to use.
  • argparse.sh
    • similar approach, but not completely shell agnostic, and lacking in more advanced features, like subcommands.
  • fish argparse
    • Fish specific, but a nice utility. Not easy to use outside of fish and no subcommand support.

Metadata

Release files for argparsh 0.0.4

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

Source distribution (sdist)

Source distribution for argparsh 0.0.4
File Size Uploaded Provenance
argparsh-0.0.4.tar.gz 9.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 18.3 kB

Release files / argparsh-0.0.4.tar.gz

Download URL argparsh-0.0.4.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
13f571eaa9522d1e2425e7d596a51be038f26cb393f7360faaae206a3e0d8b5f
BLAKE2b-256 checksum
How to use checksums
488171e78fd2aa05391474286bc579663925e99d104b8e6ec73aca99882f1151
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.2

Release files / argparsh-0.0.4-py3-none-any.whl

Download URL argparsh-0.0.4-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e938f413e6de50490b435e3cd91b3e2662c0277a5faab58e4b1402e0ad12506
BLAKE2b-256 checksum
How to use checksums
e79c986d190c78af4882c41a484cf9131624155dd875b7bda6b99b4ae2795a69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.2

Security for argparsh 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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