zero-setup dynamic python command line argument parsing
Project description
ezargs
Lightweight, zero-setup dynamic Python command line argument parsing. ezargs is extremely simple (< 10 SLoC) and pushes as much of the parsing logic into the user's hands as possible. I wrote ezargs because I wanted an easier way to set up ephemeral, flexible, or just plain easy CLI arguments for Python scripts. I just wanted to be able to pass whatever I wanted and grab it in the code without having to declare fields beforehand.
The only strict rule pertains to the format of arguments, which is as follows:
- Arguments must be key-value pairs in the format:
key=value- eg.
python my_scripy.py duration=5 max_shift=12 name=foo secret='ab!@#3=e32'parses the arguments into:{'duration': '5', 'max_shift': '12', 'name': 'foo', 'secret': 'ab!@#3=e32'} - Subsequent
=appearances in the value are allowed.- eg.
name=fo=o->{'name': 'fo=o'}
- eg.
- Values with spaces must be wrapped in quotes. In general, strings should be sent with quotes (single or double).
- eg.
name="John Appleseed"->{'name': 'John Appleseed'}
- eg.
- eg.
Type conversions, presence checks, etc. are up to the user to handle. All values are parsed as strings.
Installation:
- Install ezargs with
pip install ezargs
Simple Code Recipe:
from ezargs import parse_args
def main(args: dict) -> None:
max_attempts = int(args.get("max-attempts", 5)) # default value with type conversion
if not (filename := args.get("filename")):
# presence check
raise Exception("missing file name!")
print(f"{filename=}, {max_attempts=}")
if __name__ == "__main__":
args: dict = parse_args()
main(args)
Project details
Release history Release notifications | RSS feed
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 ezargs-0.0.6.tar.gz.
File metadata
- Download URL: ezargs-0.0.6.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cfcf42ca98357129962b5a72ae677d39cf8ef53de762d9845d64e74708ebc33
|
|
| MD5 |
b4a0b9ee3fba752639407aded1d664cb
|
|
| BLAKE2b-256 |
cf3ce812cfdd74a6976445baa6a1b2628fe752fb0d819c65a080f91d24368806
|
File details
Details for the file ezargs-0.0.6-py3-none-any.whl.
File metadata
- Download URL: ezargs-0.0.6-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e99a5b77db6e6f38eb2a3b932cdf62d578d33d17daac9cf4c7870a757150a06
|
|
| MD5 |
ea63b088769bcd11b284f1ec3b46db9f
|
|
| BLAKE2b-256 |
bebdf3ca0127cc60756891ebdb5bf7b369b128c89c1d1bb4f274cb3c9a8aec2f
|