Skip to main content

pargv

Parse command line arguments into a list of args and a dict of kwargs.

Installation

pip install pargv

Usage

By default, pargv.parse_args() uses sys.argv as command line arguments. It can be used in the following way.

from pargv import parse_args

args, kwargs = parse_args()

The arguments to be parsed can also be specified manually:

from pargv import parse_args

args, kwargs = parse_args(argv=['pargv.py', '--name=pargv'])

Specification

parse_args parses arguments in the following way, assuming the following command line arguments (sys.argv): ['/pargv/pargv.py', 'command', 'positional', '--flag', '--optional=value', 'test', '--output-file', 'filename', '-ab=one', 'two']

By calling args, kwargs = parse_args(), this would return the following list and dict:

args = ['/pargv/pargv.py', 'command', 'positional']
kwargs = {
        'flag': True,
        'optional': ['value', 'test'],
        'output_file': 'filename',
        'a': True,
        'b': ['one', 'two'],
    }

Basic behaviour

  • All arguments before the first option (starting with a hyphen) are considered positional arguments (args)
  • All other arguments are considered optional keyword arguments (kwargs)
  • Optional arguments without leading hyphens are considered as values to preceding keyword arguments
  • One value of an option is stored as a string, multiple values are stored as a list
  • Flags are stored with the value True in the dict
  • Up to 2 leading hyphens are stripped from options, all other hyphens are converted into underscores (---test-this- would become the key _test_this_ in the dict)
  • For multiple short options such as -vao=file.ext or -vao file.ext, the last option (o) is set to the specified value, while other options (v and a) are set to True.

Metadata

Release files for pargv 0.2.0

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

Source distribution (sdist)

Source distribution for pargv 0.2.0
File Size Uploaded Provenance Actions
pargv-0.2.0.tar.gz 2.2 kB Without provenance Details for pargv-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 4.5 kB

Release files / pargv-0.2.0.tar.gz

Download URL pargv-0.2.0.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
01237a76913cb6978b91f418110407b4e778746ceb37546a20e987b9b6759e14
BLAKE2b-256 checksum
How to use checksums
fdecb3bb89c27aea49f21e0e7ec38100385311b50cf3a7b413e660f50a73a787
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.6 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.1 rfc3986/1.5.0 tqdm/4.64.0 urllib3/1.26.5 CPython/3.10.12

Release files / pargv-0.2.0-py3-none-any.whl

Download URL pargv-0.2.0-py3-none-any.whl
Size 2.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
320c51026a22dd9b5a88bafb782a425bb5702277d04b1f4242df73ca15013dc4
BLAKE2b-256 checksum
How to use checksums
ca0a57450159ab42a7ed9fc3b6b9e8756dcd54b214510bd2eff35ef5f7431fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.6 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.1 rfc3986/1.5.0 tqdm/4.64.0 urllib3/1.26.5 CPython/3.10.12

Security for pargv 0.2.0

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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