Skip to main content

argsy

Tiny wrapper for Python's argparse package with YAML-based cli configuration.

Overview

The argsy package aims to make CLI argument configuration and parsing declarative and simple, while still leveraging Python's argparse package to handle the parsing details and user help messaging.

Configuration supports declarative configuration of:

  1. top-level position args, options / flags
  2. a single tier of subcommands
  3. position args, options / flags for each subcommand
  4. support for setting default values for options / flags
  5. partial nvars support for capturing multiple input values
  6. support for the action directive (for things like toggling booleans)

Getting Started

Install argsy

pip install argsy>=1.0.0

Define your program structure

CLI arguments are define as either:

  1. a YAML file or string, or
  2. a Python dict object

YAML file

#
# my_cli_args.yml
# 
program:
  name: my_program
  descripton: "About what my_program does."
  args:
    option1:
      cmd_type: option
      flags: '-o|--option1'
      help: "Short text about the option."
      required: true
#
# my_program.py
# 
from argsy import Argsy

argsy_parser = Argsy(config_file_name="my_cli_args.yml")
parsed_args = argsy_parser.parse_args(sys.argv[1:])

# User runs: 
#     my_program -o USER_PROVIDED_OPTION_VALUE
# 
# Resulting 'parsed_args':
# {
#   'cmd': None, 
#   'args': {
#     'option1': USER_PROVIDED_OPTION_VALUE
#   }
# }

YAML String

#
# my_program.py
# 
from argsy import Argsy

CLI_ARGS = """
program:
  name: my_program
  descripton: "About what my_program does."
  args:
    option1:
      cmd_type: option
      flags: '-o|--option1'
      help: "Short text about the option."
      required: true
"""

argsy_parser = Argsy(config_str=CLI_ARGS)
parsed_args = argsy_parser.parse_args(sys.argv[1:])

# User runs: 
#     my_program -o USER_PROVIDED_OPTION_VALUE
# 
# Resulting 'parsed_args':
# {
#   'cmd': None, 
#   'args': {
#     'option1': USER_PROVIDED_OPTION_VALUE
#   }
# }

Python Dictionary

#
# my_program.py
# 
from argsy import Argsy

CLI_ARGS = dict(
    program=dict(
        name='my_program',
        description='About what my_program does.',
        args=dict(
            option1=dict(
                cmd_type='option',
                flags='-o|--option1',
                help='Short text about the option.',
                required=True
            )
        )
    )
)

argsy_parser = Argsy(config_dict=CLI_ARGS)
parsed_args = argsy_parser.parse_args(sys.argv[1:])

# User runs: 
#     my_program -o USER_PROVIDED_OPTION_VALUE
# 
# Resulting 'parsed_args':
# {
#   'cmd': None, 
#   'args': {
#     'option1': USER_PROVIDED_OPTION_VALUE
#   }
# }

Metadata

Release files for argsy 1.0.3

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

Built distribution (wheel)

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

Release files / argsy-1.0.3-py3-none-any.whl

Download URL argsy-1.0.3-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f836857d791ad974517a170ea7e6c7c5ff7b294aaee787d8dd5aa7d8820ec38e
BLAKE2b-256 checksum
How to use checksums
11dd6761d1fb2ced7a594c7ef8aec3d34cd75d366310820da25ba405cc6c84f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for argsy 1.0.3

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.

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 release file No provenance

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