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()
  • Here Arger is just a subclass of ArgumentParser. It will not conceal you from using other argparse libraries.

  • run this normally with

python test.py 100 param2
  • Checkout examples folder and documentation to see more of arger in action. It supports any level of sub-commands.

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=Argument(flags=('-a', '--arg'), ...): ...
  • The decorated functions can be composed to form nested sub-commands of any level.
  • No external lib dependency
  • Most of the 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 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. Some parameter names with special meaning
    • _namespace_ -> to get the output from the ArgumentParser.parse_args()
    • _arger_ -> to get the parser instance

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.2.8.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

arger-1.2.8-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: arger-1.2.8.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Linux/5.10.2-2-MANJARO

File hashes

Hashes for arger-1.2.8.tar.gz
Algorithm Hash digest
SHA256 230e7d980614a6654f3af27ccf073393f283e36710621295b0460deba5ffb2ac
MD5 e23e7b55d3448b94200ff09deb4fdc9d
BLAKE2b-256 4a2e64278de0f786444c11d9d3b0c4b7fdbe8c8f89bb8d24b7ad203524b81e7d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arger-1.2.8-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.1 Linux/5.10.2-2-MANJARO

File hashes

Hashes for arger-1.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 f54b8a011b09e4aa4ca0c8e7880c6314d5142b3ba283a612d3ad19e6741c5536
MD5 6126eaa78b2445722c8bf3a481d692b7
BLAKE2b-256 a7b99e7c83489d1a9d9c16a922f1ec3d099817c6f6ab53d09a903f54d2775d90

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