# Wind Parser
 [](https://github.com/anthonyraf/wind-parser/actions/workflows/python-package.yml) [](https://deepsource.io/gh/anthonyraf/wind-parser/?ref=repository-badge)
*Python wind parser is a parser used to retrieve arguments for command line interfaces and turn them into python dictionary.*
- Wind parser has a very simple and easy use
- Wind parser supports keyword arguments, flags and keyword arguments that accept lists
> This parser was created for the [speed](https://github.com/anthonyraf/speed-cli) framework.
## Installation
Installation with **pip** :
$ pip install wind-parser
## Usage
After installing wind-parser you can just instantiate the Parser class with `sys.argv` as argument (`sys.argv` isn't required but it's better for the code clarity)
Here is an example of how the parser is used:
```python
# command.py
import sys
from wind_parser import Parser
parser = Parser(sys.argv) # This variable stores the arguments with their values in a python dictionary
if __name__ == '__main__':
print(parser) # Print the dictionary
```
> **Note**
> : You can also use `p.args` for printing the dictionary
Then you can run in your terminal:
$ python command.py --name=John --age=32 --hobbies Football,Basketball,Cinema --verbose
Output:
{'name':'John', 'age':'32', 'hobbies': ['Football', 'Basketball', 'Cinema'], 'verbose':True}
To access the value of an argument, you can choose between:
- Use dictionary key access:
```python
print(p['name'])
# or
print(p.args['name'])
```
- Use class attribute access:
```python
print(p.name)
```
> **Note**
> : With this method, you will not be able to retrieve arguments with a `-` in its name.
## Specifications
The different types of arguments supported:
- Keyword argument : `-a 1`, `--a=1`, `-a item1,item2,item3`
- Flag : `--verbose`, `-v`, `--help`
Here are the types of the different possible values depending on the type of argument:
| Arguments | Python type|
|-----------|-----|
|`--name=John` or `--age 16`| str |
|`--verbose` or `-v` | bool (always True) |
|`--files main.py,m.cfg,test.txt` | list[str]
Raw data
{
"_id": null,
"home_page": "https://github.com/anthonyraf/wind-parser",
"name": "wind-parser",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "cli,parser",
"author": "Anthony Rafidison",
"author_email": "benjaraf006@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ed/2c/3ad475d0bf6b0fc9ef744569a278cba419f358321bf4579d152e0822c8cf/wind_parser-0.1.3.tar.gz",
"platform": null,
"description": "# Wind Parser \n [](https://github.com/anthonyraf/wind-parser/actions/workflows/python-package.yml) [](https://deepsource.io/gh/anthonyraf/wind-parser/?ref=repository-badge)\n\n*Python wind parser is a parser used to retrieve arguments for command line interfaces and turn them into python dictionary.*\n\n- Wind parser has a very simple and easy use\n- Wind parser supports keyword arguments, flags and keyword arguments that accept lists\n> This parser was created for the [speed](https://github.com/anthonyraf/speed-cli) framework.\n## Installation\n\nInstallation with **pip** : \n\n $ pip install wind-parser\n \n## Usage\n\nAfter installing wind-parser you can just instantiate the Parser class with `sys.argv` as argument (`sys.argv` isn't required but it's better for the code clarity)\n\nHere is an example of how the parser is used:\n```python\n# command.py\n\nimport sys\nfrom wind_parser import Parser\n\nparser = Parser(sys.argv) # This variable stores the arguments with their values in a python dictionary\n \nif __name__ == '__main__':\n print(parser) # Print the dictionary\n```\n> **Note**\n> : You can also use `p.args` for printing the dictionary\n\n\nThen you can run in your terminal:\n \n $ python command.py --name=John --age=32 --hobbies Football,Basketball,Cinema --verbose\nOutput:\n\n {'name':'John', 'age':'32', 'hobbies': ['Football', 'Basketball', 'Cinema'], 'verbose':True}\nTo access the value of an argument, you can choose between:\n\n- Use dictionary key access: \n```python\nprint(p['name'])\n# or\nprint(p.args['name'])\n```\n- Use class attribute access:\n```python\nprint(p.name)\n```\n> **Note**\n> : With this method, you will not be able to retrieve arguments with a `-` in its name.\n\n## Specifications\nThe different types of arguments supported:\n\n- Keyword argument : `-a 1`, `--a=1`, `-a item1,item2,item3`\n- Flag : `--verbose`, `-v`, `--help`\n\n\nHere are the types of the different possible values depending on the type of argument:\n\n| Arguments | Python type|\n|-----------|-----|\n|`--name=John` or `--age 16`| str |\n|`--verbose` or `-v` | bool (always True) |\n|`--files main.py,m.cfg,test.txt` | list[str]\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Python wind parser is a parser used to retrieve arguments for command line interfaces and turn them into python dictionary",
"version": "0.1.3",
"split_keywords": [
"cli",
"parser"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4a5d385cc0dbd0f61d147ac628451cc91953deed4c4d4f70ee995f9304c2de5d",
"md5": "24736d842ddcb7aa5dca3925be705bb7",
"sha256": "2f60283dfbfc0284c413a2f0edd7865a0972faa4784e7ae5c07f9eade41a8600"
},
"downloads": -1,
"filename": "wind_parser-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "24736d842ddcb7aa5dca3925be705bb7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8917,
"upload_time": "2023-01-28T19:08:52",
"upload_time_iso_8601": "2023-01-28T19:08:52.512525Z",
"url": "https://files.pythonhosted.org/packages/4a/5d/385cc0dbd0f61d147ac628451cc91953deed4c4d4f70ee995f9304c2de5d/wind_parser-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ed2c3ad475d0bf6b0fc9ef744569a278cba419f358321bf4579d152e0822c8cf",
"md5": "0eb394b8956c18ad2c9cc1a867d3a672",
"sha256": "1f4adec1ef3596872b59f36138cfac29a56432bc4d2caea01bf9f10eea77b864"
},
"downloads": -1,
"filename": "wind_parser-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "0eb394b8956c18ad2c9cc1a867d3a672",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8130,
"upload_time": "2023-01-28T19:08:54",
"upload_time_iso_8601": "2023-01-28T19:08:54.056899Z",
"url": "https://files.pythonhosted.org/packages/ed/2c/3ad475d0bf6b0fc9ef744569a278cba419f358321bf4579d152e0822c8cf/wind_parser-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-28 19:08:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "anthonyraf",
"github_project": "wind-parser",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "wind-parser"
}