Esrapgra
The opposite of argparse. Converts function arguments to command-line arguments.
Installation
pip install esrapgra
From source
pip install git+https://github.com/audy/esrapgra
Overview
So you want to call wget from Python, mapping Python variables to
command-line arguments:
wget \
http://example.com/file.zip \
--directory-prefix=/path/to/directory \
--retry-connrefused \
--waitretry=5 \
--tries=3
This often gets messy if you need to interpolate values into the arguments or map Python logic into command logic:
args = [
"http://example.com/file.zip",
"--directory-prefix",
directory_prefix,
f"--tries={tries}"
]
if retry_connrefused:
args.append("--retry-connrefused")
subprocess.check_output(["wget"] + args)
With Esrapgra (if you can remember how to spell it), this becomes a nice function invocation:
es = Esrapgra(kwargs_last=True)
args = es.lex_arguments(
"http://example.com/file.zip",
directory_prefix="/path/to/directory",
retry_connrefused=True,
waitretry=5,
tries=3
)
subprocess.check_output(["wget"] + args)
The following things are happening:
- String arguments are automatically escaped and quote to protect against shell-escape attacks
- Boolean arguments are automatically turned into boolean flags (e.g.,
retry_connrefused=Trueturns into--retry-connrefusedandretry_connrefused=Falseturns into nothing) - Numeric flags are automatically converted into strings
Examples
Basic Initialization
You can initialize the Esrapgra object with default parameters:
esrap = Esrapgra()
Custom Separator
Customize the separator between words in keyword arguments:
# Using underscores as separators
esrap = Esrapgra(separator="_")
# Example usage
esrap.lex_arguments(test_argument="test") # Output: ['--test_argument="test"']
Custom Prefix
Define a custom prefix for the keyword arguments:
# Using a single hyphen as a prefix
esrap = Esrapgra(prefix="-")
# Example usage
esrap.lex_arguments(test_argument="test") # Output: ['-test_argument="test"']
Keyword Arguments Position
Control the position of keyword arguments relative to positional arguments:
# Putting keyword arguments before positional arguments
esrap = Esrapgra(kwargs_last=False)
# Example usage
esrap.lex_arguments(
"first_arg",
test_argument="test"
)
# Output: ['-test_argument="test"', 'first_arg']
Quoting Strings
You can enable or disable the quoting of strings as per your needs:
# Disabling quoting of strings
esrap = Esrapgra(quote_strings=False)
# Example usage
# Adjust the expected output based on the implementation of `lex_arguments`
esrap.lex_arguments(test_argument="test")
Metadata
Release files for esrapgra 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| esrapgra-0.1.1.tar.gz | 4.2 kB | Without provenance | Details for esrapgra-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| esrapgra-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for esrapgra-0.1.1-py3-none-any.whl |
Total release size: 8.4 kB
Release files / esrapgra-0.1.1.tar.gz
| Download URL | esrapgra-0.1.1.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
722edd547f93c7ae452bd60f148b533aa46fe03cbecb9c4c7928214f66ece7ab
|
|
BLAKE2b-256 checksum How to use checksums |
8b013835e57a0fa3128f67fefe287fd0049f22a26ab287511ecfefd205a0f582
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / esrapgra-0.1.1-py3-none-any.whl
| Download URL | esrapgra-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e5ab2953904e7a35dbba6f42112fc8c152aab9e3078b742344af2b7de247385
|
|
BLAKE2b-256 checksum How to use checksums |
b10bd7bcb4010093a8831e03c207eaa9335557686b589ead338aa09605a5ec1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for esrapgra 0.1.1
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.