https://github.com/nathan-fiscaletti/parameterparser-py
✔️An advanced parameter parser for Python
https://github.com/nathan-fiscaletti/parameterparser-py
cli command-line-parser parameter parameter-parser parameters python python3
Last synced: about 1 month ago
JSON representation
✔️An advanced parameter parser for Python
- Host: GitHub
- URL: https://github.com/nathan-fiscaletti/parameterparser-py
- Owner: nathan-fiscaletti
- License: mit
- Created: 2019-07-13T20:24:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-05T21:50:16.000Z (about 6 years ago)
- Last Synced: 2025-02-19T09:38:06.724Z (12 months ago)
- Topics: cli, command-line-parser, parameter, parameter-parser, parameters, python, python3
- Language: Python
- Size: 44.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Parameter Parser (Python)
> **Parameter Parser** is a simple library used to parse intricate parameters from an array of strings.
> **Hint:** This package is available through `Python PIP`.
> `pip install parameterparser`
#### Supports Python 2.7+
[](https://badge.fury.io/py/parameterparser)
[](./tests/latest.stylelog)
[](https://pepy.tech/project/parameterparser)
[](https://github.com/nathan-fiscaletti/parameterparser-py/issues)

[Documentation](./docs/) - [Advanced Code Examples](./examples/readme.md) - [Looking for the PHP version?](https://github.com/nathan-fiscaletti/parameterparser)
### Features
* Parse command line parameters.
* Assign aliases to parameters.
* Custom closures for each command line parameter.
* Variadic closure support for arguments taking more than one value.
* Customize the way the command line is parsed.
### Example Usage
```python
import sys
from parameterparser import Parameter, Cluster, Parser
# Initialize a new Cluster
parameters = Cluster()
# Add a Parameter to the Cluster
parameter = Parameter("-", "name", lambda name: name)
parameter.set_required(True)\
.set_description("Your name.")
parameters.add(parameter)
# Create a new Parser using the Cluster
parser = Parser(sys.argv, parameters)
# Parse the parameters using the Parser.
results = parser.parse()
# Verify that the parameters were valid after parsing.
if not parser.is_valid():
# Since it was not valid, output usage.
parameters.print_full_usage(
"Parameter Parser",
"An advanced parameter parser for Python",
"v1.0.0"
)
else:
# Retrieve the name from the results
name = results['name']
# Output the name
print("Your name is " + name + os.linesep)
```
### Output
```
~/ python test.py -name 'Nathan Fiscaletti'
Your name is Nathan Fiscaletti
```
### Development
Before commiting anything, please create a pre-commit hook with the following content.
This will ensure that the pycodestyle badge is properly updated.
```bash
#!/bin/bash
python3 tests/style.py
```