Skip to main content

Reversed argparse: generate string of command-line args from Python objects.

Project description

Reversed argparse: generate string of command-line args from Python objects.

package version from PyPI build status from GitHub test coverage from Codecov grade from Codacy license

The argunparse is intended to perform an approximate reverse of what argparse does. In short: generating string (or a list of strings) of command-line arguments from a dict and/or a list.

How to use

Simple example of how argunparse works:

import argunparse

options = {
    'v': True,
    'long-flag': True,
    'ignored': False,
    'also-ignored': None,
    'o': 'out_file.txt',
    'log': 'log_file.txt'
    }
args = {
    'in_file.txt'
    }

unparser = argunparse.ArgumentUnparser()
print(unparser.unparse(*args, **options))
# -v --long-flag -o=out_file.txt --log=log_file.txt in_file.txt

print(unparser.unparse_to_list(*args, **options))
# ['-v', '--long-flag', '-o=out_file.txt', '--log=log_file.txt', 'in_file.txt']

Special option values are:

  • True – option will be treated as a flag;

  • False and None – option will be ignored.

All other values will be converted to strings using str().

For more examples see examples.ipynb notebook.

Requirements

Python version 3.8 or later.

Python libraries as specified in requirements.txt.

Building and running tests additionally requires packages listed in requirements_test.txt.

Tested on Linux, macOS and Windows.

Installation

For simplest installation use pip:

pip3 install argunparse

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

argunparse-0.1.4.tar.gz (10.7 kB view hashes)

Uploaded Source

Built Distribution

argunparse-0.1.4-py3-none-any.whl (9.4 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