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.

    1. e.g. def main(param: ...) -> -p, --param
    2. If needed you could declare it inside docstring like :param arg1: -a --arg this is the document.
  • one can use Argument class to pass any values to the parser.add_argument function

  • The decorated functions can be composed to form nested sub-commands of any level.

  • Most of the Standard types supported. Please see examples for more supported types with examples.

NOTE

  • *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

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

Uploaded Source

Built Distribution

arger-1.3.7-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: arger-1.3.7.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.8.8 Linux/5.4.0-1043-azure

File hashes

Hashes for arger-1.3.7.tar.gz
Algorithm Hash digest
SHA256 b940050e78ef4831b8d37e91a70c832e1585ed09ddb42dc5c4e3881c65c01785
MD5 efc22dfcb70dd6afcd1829fabd0a1e0c
BLAKE2b-256 f7645568949b4bc0b09ba8ca33aa0d8757bc7516e57578f64a6fa193d8e7cc26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: arger-1.3.7-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.5 CPython/3.8.8 Linux/5.4.0-1043-azure

File hashes

Hashes for arger-1.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0b925c28b46940b2a2a3c78efc62814670eb3561dce2cf76d052732fb6fad11f
MD5 ea2eca84ea66ebe2e62458fbfa688550
BLAKE2b-256 e3303e05f1448c4fd7428d27518185ff9483707e575c1153d3593b2a2088266a

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