A simple package for parsing function arguments from the command line
Project description
ParseArgs
A simple, intuitive way to parse command line arguments. Simply make a function, and call parseargs on it.
- parses data types through annoations (annotations not required for string arguments)
- parses positional arguments into positional cli arguments with the same name
- parses optional keyword arguments by adding them as optional cli arguments
- parses annotated arguments and uses the native cli specification for types
- adds a description of the command by using the signature of the method.
Example
in fun.py:
from parseargs import parseargs
def fun(firstname, lastname:str, number:int = 5):
print(f"Hello {firstname} {lastname}")
print(f"Your number is {number}")
number *= 2
print(f"Twice your number is {number}")
parseargs(fun)
Now on the command line, you can do:
$ python fun.py ricky bobby --number 5
Notice how it will print out 10. If you remove the annotation declaring the number an int, it will instead print out 55, because it will interpret it as a string.
We can get the method signature with:
$ python fun.py -h
usage: fun.py [-h] [-n NUMBER] firstname lastname
signature = (firstname, lastname: str, number: int = 5)
positional arguments:
firstname
lastname
optional arguments:
-h, --help show this help message and exit
-n NUMBER, --number NUMBER
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file parseargs-0.0.5.tar.gz.
File metadata
- Download URL: parseargs-0.0.5.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2b21f09b1fa766dc84ac62496ab4478857322b6d3019148ff9b9ae7f776c950
|
|
| MD5 |
1ac1e9e27e8488da096981d3fe1b09c7
|
|
| BLAKE2b-256 |
7207d21305d873fdea9fb7ba31747c80953af488f5c5ffa1b48cb754fe65ae29
|
File details
Details for the file parseargs-0.0.5-py3-none-any.whl.
File metadata
- Download URL: parseargs-0.0.5-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1a307f0ebf394450643357691a61dc59989dffb5917d5147d97fa50d5cf2104
|
|
| MD5 |
a113b5a881922463428116f064e1b48b
|
|
| BLAKE2b-256 |
278a7a83762ac41d4032feb6165355378495ae89b03ccc09e14c13882b2ce649
|