Parse Argument with JSON Schema
Project description
argparse-from-jsonschema
Parse Argument with JSON Schema.
Installation
Need Python 3.6+.
pip install argparse-from-jsonschema
Usage
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "argument_config",
"description": "Arg-parse Schema UnitTest",
"type": "object",
"properties": {
"config": {
"type": "string",
"positional": true,
"description": "path of config file"
},
"resume": {
"type": "boolean",
"description": "resume from checkpoint or not"
},
"foo": {
"type": "boolean",
"description": "--with-foo for true or --no-foo for false",
"false-prefix": "no",
"true-prefix": "with"
},
"scale": {
"type": "number",
"default": 1.0,
"description": "scale of image"
},
"mode": {
"enum": [
"happy",
"high",
"heaven"
],
"default": "happy",
"description": "speed mode"
},
"composition": [
{"type": "string", "description": "Only first element is use"},
{"type": "null"}
]
},
"required": [
"config"
]
}
Python Code:
# demo.py
import argparse_from_jsonschema
print(argparse_from_jsonschema.parse(schema='./tests/argument_config.json'))
Run with arguments:
python3 demo.py /path/to/config.py
#> {'config': '/path/to/config.py', 'resume': False, 'foo': False 'scale': 1.0, 'mode': 'happy'}
CLI:
argparse-from-jsonschema tests/argument_config.json
#> Show help for schema file [tests/argument_config.json]:
#> usage: YOUR-COMMAND [-h] [--resume] [--with-foo] [--scale SCALE]
#> [--mode {happy,high,heaven}]
#> config
#>
#> Arg-parse Schema UnitTest
#>
#> positional arguments:
#> config path of config file
#>
#> optional arguments:
#> -h, --help show this help message and exit
#> --resume resume from checkpoint or not
#> --with-foo, --no-foo --with-foo for true or --no-foo for false
#> --scale SCALE scale of image, [1.0] in default
#> --mode {happy,high,heaven}
#> speed mode, [happy] in default
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
File details
Details for the file argparse-from-jsonschema-0.0.6.tar.gz
.
File metadata
- Download URL: argparse-from-jsonschema-0.0.6.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8a351ce593a9f748abf6fb851090b5b851e3a99bc2f0b9f8c2ac6509fa1351c |
|
MD5 | 87e1ed3b3eb980e09793b66491b8f66c |
|
BLAKE2b-256 | aac5c2de90986b2db6f235727d03c94cb3e5ca88db879654702fd8d5fb96d522 |
File details
Details for the file argparse_from_jsonschema-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: argparse_from_jsonschema-0.0.6-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b7c554a460c52432928ce8116dcb17375bae04a0401fda8954196618b282fe7 |
|
MD5 | 373a21aa35dbb38c9915315f112e18e5 |
|
BLAKE2b-256 | 5f79d5e8dc06e607089610fe592e07f6b7549f3d3ee6ca09ddbde574b65a91f4 |