argparse-from-jsonschema


Nameargparse-from-jsonschema JSON
Version 0.0.6 PyPI version JSON
download
home_pagehttps://github.com/LeConTesteur/argparse-from-jsonschema
SummaryParse Argument with JSON Schema
upload_time2023-09-21 18:47:22
maintainer
docs_urlNone
authorLeConTesteur
requires_python
license
keywords argparse jsonschema argument schema data validation json validation command line parser parsing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # argparse-from-jsonschema 

Parse Argument with JSON Schema.

## Installation

Need Python 3.6+.

```bash
pip install argparse-from-jsonschema
```

## Usage

[Schema](./tests/argument_config.json):

```json
{
  "$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:

```python
# demo.py
import argparse_from_jsonschema

print(argparse_from_jsonschema.parse(schema='./tests/argument_config.json'))
```

Run with arguments:

```bash
python3 demo.py /path/to/config.py
#> {'config': '/path/to/config.py', 'resume': False, 'foo': False 'scale': 1.0, 'mode': 'happy'}
```

CLI:

```bash
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
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/LeConTesteur/argparse-from-jsonschema",
    "name": "argparse-from-jsonschema",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "Argparse,jsonschema,Argument Schema,data validation,json,validation,command,line,parser,parsing",
    "author": "LeConTesteur",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/aa/c5/c2de90986b2db6f235727d03c94cb3e5ca88db879654702fd8d5fb96d522/argparse-from-jsonschema-0.0.6.tar.gz",
    "platform": null,
    "description": "# argparse-from-jsonschema \n\nParse Argument with JSON Schema.\n\n## Installation\n\nNeed Python 3.6+.\n\n```bash\npip install argparse-from-jsonschema\n```\n\n## Usage\n\n[Schema](./tests/argument_config.json):\n\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"title\": \"argument_config\",\n  \"description\": \"Arg-parse Schema UnitTest\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"config\": {\n      \"type\": \"string\",\n      \"positional\": true,\n      \"description\": \"path of config file\"\n    },\n    \"resume\": {\n      \"type\": \"boolean\",\n      \"description\": \"resume from checkpoint or not\"\n    },\n    \"foo\": {\n      \"type\": \"boolean\",\n      \"description\": \"--with-foo for true or --no-foo for false\",\n      \"false-prefix\": \"no\",\n      \"true-prefix\": \"with\"\n    },\n    \"scale\": {\n      \"type\": \"number\",\n      \"default\": 1.0,\n      \"description\": \"scale of image\"\n    },\n    \"mode\": {\n      \"enum\": [\n        \"happy\",\n        \"high\",\n        \"heaven\"\n      ],\n      \"default\": \"happy\",\n      \"description\": \"speed mode\"\n    },\n    \"composition\": [\n      {\"type\": \"string\", \"description\": \"Only first element is use\"},\n      {\"type\": \"null\"}\n    ]\n  },\n  \"required\": [\n    \"config\"\n  ]\n}\n```\n\nPython Code:\n\n```python\n# demo.py\nimport argparse_from_jsonschema\n\nprint(argparse_from_jsonschema.parse(schema='./tests/argument_config.json'))\n```\n\nRun with arguments:\n\n```bash\npython3 demo.py /path/to/config.py\n#> {'config': '/path/to/config.py', 'resume': False, 'foo': False 'scale': 1.0, 'mode': 'happy'}\n```\n\nCLI:\n\n```bash\nargparse-from-jsonschema tests/argument_config.json\n#> Show help for schema file [tests/argument_config.json]:\n#> usage: YOUR-COMMAND [-h] [--resume] [--with-foo] [--scale SCALE]\n#>                     [--mode {happy,high,heaven}]\n#>                     config\n#>\n#> Arg-parse Schema UnitTest\n#>\n#> positional arguments:\n#>   config                path of config file\n#>\n#> optional arguments:\n#>   -h, --help            show this help message and exit\n#>   --resume              resume from checkpoint or not\n#>   --with-foo, --no-foo  --with-foo for true or --no-foo for false\n#>   --scale SCALE         scale of image, [1.0] in default\n#>   --mode {happy,high,heaven}\n#>                         speed mode, [happy] in default\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Parse Argument with JSON Schema",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/LeConTesteur/argparse-from-jsonschema"
    },
    "split_keywords": [
        "argparse",
        "jsonschema",
        "argument schema",
        "data validation",
        "json",
        "validation",
        "command",
        "line",
        "parser",
        "parsing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5f79d5e8dc06e607089610fe592e07f6b7549f3d3ee6ca09ddbde574b65a91f4",
                "md5": "373a21aa35dbb38c9915315f112e18e5",
                "sha256": "7b7c554a460c52432928ce8116dcb17375bae04a0401fda8954196618b282fe7"
            },
            "downloads": -1,
            "filename": "argparse_from_jsonschema-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "373a21aa35dbb38c9915315f112e18e5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5524,
            "upload_time": "2023-09-21T18:47:20",
            "upload_time_iso_8601": "2023-09-21T18:47:20.766647Z",
            "url": "https://files.pythonhosted.org/packages/5f/79/d5e8dc06e607089610fe592e07f6b7549f3d3ee6ca09ddbde574b65a91f4/argparse_from_jsonschema-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aac5c2de90986b2db6f235727d03c94cb3e5ca88db879654702fd8d5fb96d522",
                "md5": "87e1ed3b3eb980e09793b66491b8f66c",
                "sha256": "d8a351ce593a9f748abf6fb851090b5b851e3a99bc2f0b9f8c2ac6509fa1351c"
            },
            "downloads": -1,
            "filename": "argparse-from-jsonschema-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "87e1ed3b3eb980e09793b66491b8f66c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5353,
            "upload_time": "2023-09-21T18:47:22",
            "upload_time_iso_8601": "2023-09-21T18:47:22.211578Z",
            "url": "https://files.pythonhosted.org/packages/aa/c5/c2de90986b2db6f235727d03c94cb3e5ca88db879654702fd8d5fb96d522/argparse-from-jsonschema-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-21 18:47:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "LeConTesteur",
    "github_project": "argparse-from-jsonschema",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "argparse-from-jsonschema"
}
        
Elapsed time: 0.11456s