Skip to main content

Python wind parser is a parser used to retrieve arguments for command line interfaces and turn them into python dictionary

Project description

Wind Parser

Python versions badge Python package DeepSource

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 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:

# 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:
print(p['name'])
# or
print(p.args['name'])
  • Use class attribute access:
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]

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

wind_parser-0.1.3.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wind_parser-0.1.3-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file wind_parser-0.1.3.tar.gz.

File metadata

  • Download URL: wind_parser-0.1.3.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.4 Linux/5.4.0-1100-azure

File hashes

Hashes for wind_parser-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1f4adec1ef3596872b59f36138cfac29a56432bc4d2caea01bf9f10eea77b864
MD5 0eb394b8956c18ad2c9cc1a867d3a672
BLAKE2b-256 ed2c3ad475d0bf6b0fc9ef744569a278cba419f358321bf4579d152e0822c8cf

See more details on using hashes here.

File details

Details for the file wind_parser-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: wind_parser-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.4 Linux/5.4.0-1100-azure

File hashes

Hashes for wind_parser-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2f60283dfbfc0284c413a2f0edd7865a0972faa4784e7ae5c07f9eade41a8600
MD5 24736d842ddcb7aa5dca3925be705bb7
BLAKE2b-256 4a5d385cc0dbd0f61d147ac628451cc91953deed4c4d4f70ee995f9304c2de5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page