
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
argparse-from-jsonschema
Advanced tools
Parse Argument with JSON Schema.
Need Python 3.6+.
pip install argparse-from-jsonschema
{
"$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
FAQs
Parse Argument with JSON Schema
We found that argparse-from-jsonschema demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.