Skip to main content

A high-level shorthand argument parser for Python 3 or above

Project description

argpy

A high-level shorthand argument parser for Python 3 or above


Overview

The objective of argpy is simply to strengthen one's propensity to utilize argparsing in Python scripts by making the definition of command line arguments slightly less tedious.


Installation

Run pip3 install argpy


Arguments

var name type default
options Options list n / a

Examples

Importing the Module

from argpy import argpy

Defining and Retrieving Options

Options are passed into argpy in the form of a list of dictionaries. Here each item or element within the list represents one option. In the example below, option one is defined as name with a short form flag of -n and a long form flag of --name. The "dest" key defines how the passed in option will be accessed from within the program while the "help" key defines any additional help text that will be accessible by the user passing in the option via the command line. The second option demonstrates how to pass in a boolean argument, which defaults to False.

# Define options
options = [
      {"flags": ("-n", "--name"), "dest": "name", "help": "The object's name"},
      {
          "flags": ("-a", "--activate"),
          "dest": "activate",
          "bool": True,
          "help": "Whether to activate the object",
      },
  ]

The above options can be implemented and retrieved by continuing the script as follows:

# Get arguments
arguments = argpy(options)

# Get name, activate
name = arguments.name
activate = arguments.activate

In case you're wondering what this would look like from that command line, see below.

python3 my_script.py --name OptimusPrime --activate

or

python3 my_script.py -n OptimusPrime -a

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

argpy-0.0.2.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

argpy-0.0.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file argpy-0.0.2.tar.gz.

File metadata

  • Download URL: argpy-0.0.2.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/45.1.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for argpy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ca34a029f66fa74ec96f137290fedb803a39629606a315e6249a846a7b0b475c
MD5 f661ff0487585f9314d37972af866944
BLAKE2b-256 7843f11b5a5129709e7ad27ed94caef46fec1987e44b626e26d22cc5117d2a7b

See more details on using hashes here.

File details

Details for the file argpy-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: argpy-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/45.1.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for argpy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bc18d7340064d08d8aecaf2224d620b2efc0af0ccda69b3e72747bee96f68472
MD5 0212c924815eef8b9942d6bd8f51d49a
BLAKE2b-256 a875f61ef49a52b932055e9f01a41978b53a1c17fc3a62b13f31703298844a87

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