Skip to main content

Actions and other utility functions for use with argparse

Project description

argparse-utilities

Actions and other utility functions for use with argparse

Quickstart

Install from pip:

pip install argparse-utilities

Usage

import argparse
from argparse_utilities import StoreMaxOneAction

parser = argparse.ArgumentParser(
    prog='Foo',
    description='foo foo foo',
)

parser.add_argument(
    '-f', '--foo',
    action=StoreMaxOneAction,
    type=int,
    required=True,
)

x = parser.parse_args(['--foo', '1'])
# x will be argparse.Namespace(foo=1)

parser.parse_args(['--foo', '1', '--foo', '2'])
# will throw ValueError('--foo supplied more than once')

Development

For those developing or maintaining the argparse-utilities package itself, be sure to install it with the [dev] option to pull in packages used when developing.

pip install --editable .[dev]

When developing, this package uses pre-commit. After the initial clone of the repository, you will need to set up pre-commit with:

# in the top level of the checked-out repository:
pre-commit install

Changelog

0.0.2 released 2023-11-09

  • Initial Version

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

argparse-utilities-0.0.2.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

argparse_utilities-0.0.2-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

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