jsonargparse

4.48.0 · active · verified Fri Apr 10

jsonargparse is a Python library that extends `argparse` to simplify the creation of Command-Line Interfaces (CLIs) and make Python applications easily configurable. It allows parsing configuration options from command line arguments, config files (JSON, YAML, Jsonnet, TOML), and environment variables, leveraging type hints for validation. It is a well-maintained project with frequent releases, adhering to high standards of development, including semantic versioning, deprecation periods, changelog, automated testing, and full test coverage.

Warnings

Install

Imports

Quickstart

The simplest way to create a CLI is by using the `CLI()` function with a type-hinted Python function. `jsonargparse` automatically generates arguments, validates types, and uses docstrings for help messages.

from jsonargparse import CLI

def main(name: str, greeting: str = 'Hello') -> None:
    """
    A simple command-line interface function.

    Args:
        name: The name of the person to greet.
        greeting: The greeting message to use.
    """
    print(f'{greeting}, {name}!')

if __name__ == '__main__':
    # Run this from the command line:
    # python your_script.py --name World
    # python your_script.py --name Alice --greeting Hi
    CLI(main)

view raw JSON →