Skip to main content

Create argparser automatically from functions

Project description

Overview

A wrapper around argparser to help build CLIs from functions. Uses type-hints extensively :snake:.

PyPi Version Python Version PyPI License

Setup

:gear: Installation

Install it directly into an activated virtual environment:

$ pip install arger

or add it to your Poetry project:

$ poetry add arger

:books: Usage

  • create a python file called test.py
from arger import Arger

def main(param1: int, param2: str, kw1=None, kw2=False):
    """Example function with types documented in the docstring.

    :param param1: The first parameter.
    :param param2: The second parameter.
    """
    print(locals())

if __name__ == '__main__':
    Arger(main).run()
  • run this normally with
python test.py 100 param2
  • Checkout examples folder and documentation to see more of arger in action.

Features

  • Uses docstring to parse help comment for arguments. Supports
  • Flags will be generated from parameter-name. If needed you could declare it inside docstring like :param arg1: -a --arg this is the document. Also one can use def main(arg1:int=Option('-a', '--arg')): ...
  • The decorated functions can be composed to form nested sub-commands of any level.
  • No external lib dependency
  • Standard types supported. Please see examples for more supported types with examples.
  • All argument to ArgumentParser.add_argument is supported. It can be updated with arger.Argument or arger.Option classes.
  • *args supported but no **kwargs support yet.
  • all optional arguments that start with underscore is not passed to Parser. They are considered private to the function implementation. One can use _namespace_ to get the output from the ArgumentParser.parse_args()

Similar Projects

argh

  • has similar goals as to ease up using argparser.
  • doesn't support type hints.
  • No recent releases.

typer

  • if you are using click , I highly recommend you to check this library.
  • it is neat and many features are drawn from it.
  • doesn't support loading help text for arguments from docstrings.

invoke

  • doesn't support type hints.

cliche

  • has similar goals.
  • doesn't cover much use cases as arger .

cliar

  • no docstring support for help argument.

Recommended Alternatives

Projects that I didn't know while creating this project. I highly recommend you to checkout them.
  1. clize
  2. nuclear
  3. defopt

This project was generated with cookiecutter using jacebrowning/template-python.

Argparser enhancements

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

arger-1.0.5.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

arger-1.0.5-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file arger-1.0.5.tar.gz.

File metadata

  • Download URL: arger-1.0.5.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.4.0-1031-azure

File hashes

Hashes for arger-1.0.5.tar.gz
Algorithm Hash digest
SHA256 28751e2d2eb76c8e638344acfe81b493b8cec8014c4b2684e00831891bca6feb
MD5 f92147a16aae37ef1fe87572805fed30
BLAKE2b-256 f07a0aa49bf0fb3e21ec628cc95bae9662f935e9fba402177f28070594affb0b

See more details on using hashes here.

File details

Details for the file arger-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: arger-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Linux/5.4.0-1031-azure

File hashes

Hashes for arger-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dc98ffa930171f5810096027adcc9db913a1755620ee8ba4610abc58fc0fd838
MD5 5f8071b22e5c761845596c6cc4e245b4
BLAKE2b-256 08afa0cab7a3624ffb853035d33c7c7ebd72d04def6465f5720e0bbace146110

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