Skip to main content
https://readthedocs.org/projects/jsonargparse/badge/?version=stable https://github.com/mauvilsa/jsonargparse/actions/workflows/tests.yaml/badge.svg https://codecov.io/gh/mauvilsa/jsonargparse/branch/main/graph/badge.svg https://sonarcloud.io/api/project_badges/measure?project=mauvilsa_jsonargparse&metric=alert_status&token=74f3ff0af709f6caa0544dfbcf823c49fb68cb46 https://badge.fury.io/py/jsonargparse.svg

jsonargparse

Docs: https://jsonargparse.readthedocs.io/ | Source: https://github.com/mauvilsa/jsonargparse/

jsonargparse is a library for creating command-line interfaces (CLIs) and making Python apps easily configurable. It is a well-maintained project with frequent releases, adhering to high standards of development: semantic versioning, deprecation periods, changelog, automated testing, and full test coverage.

Although jsonargparse might not be widely recognized yet, it already boasts a substantial user base. Most notably, it serves as the framework behind pytorch-lightning’s LightningCLI.

The documentation is a reference that describes each feature in isolation, which is not always the best way to learn. If you would rather see the why behind the features and complete use cases built end to end, have a look at the talks and articles page, which collects presentations, blog posts and example projects.

Teaser examples

CLI with minimal boilerplate:

from jsonargparse import auto_cli

def main_function(...):  # your main parameters with type hints here
    ...  # your main code here

if __name__ == "__main__":
    auto_cli(main_function)  # parses arguments and runs main_function

Minimal boilerplate but manually parsing:

from jsonargparse import auto_parser

parser = auto_parser(main_function)
cfg = parser.parse_args()
...

Powerful argparse-like low level parsers:

from jsonargparse import ArgumentParser

parser = ArgumentParser()
parser.add_argument("--config", action="config")  # support config files
parser.add_argument("--opt", type=int | Literal["off"])  # complex arguments via type hints
parser.add_function_arguments(main_function, "function")  # add function parameters
parser.add_class_arguments(SomeClass, "class")  # add class parameters
...
cfg = parser.parse_args()
init = parser.instantiate(cfg)
...

Features

jsonargparse is user-friendly and encourages the development of clean, high-quality code. It encompasses numerous powerful features, some unique to jsonargparse, while also combining advantages found in similar packages:

Other notable features include:

  • Extensive type hint support: nested types (union, optional), containers (list, dict, etc.), protocols, user-defined generics, restricted types (regex, numbers), paths, URLs, types from stubs (*.pyi), future annotations (PEP 563), and backports (PEP 604).

  • Keyword arguments introspection: resolving of parameters used via **kwargs.

  • Dependency injection: support types that expect a class instance and callables that return a class instance.

  • Structured configs: parse config files with more understandable non-flat hierarchies.

  • Config file formats: json, yaml, toml, jsonnet and extensible to more formats.

  • Relative paths: within config files and parsing of config paths referenced inside other configs.

  • Argument linking: directing parsed values to multiple parameters, preventing unnecessary interpolation in configs.

  • Variable interpolation: powered by OmegaConf.

  • Tab completion: powered by shtab or argcomplete.

Design principles

  • Non-intrusive/decoupled:

    There is no requirement for unrelated modifications throughout a codebase, maintaining the separation of concerns principle. In simpler terms, changes should make sense even without the CLI. No need to inherit from a special class, add decorators, or use CLI-specific type hints.

  • Minimal boilerplate:

    A recommended practice is to write code with function/class parameters having meaningful names, accurate type hints, and descriptive docstrings. Reuse these wherever they appear to automatically generate the CLI, following the don’t repeat yourself principle. A notable advantage is that when parameters are added or types changed, the CLI will remain synchronized, avoiding the need to update the CLI’s implementation.

  • Dependency injection:

    Using as type hint a class or a callable that instantiates a class, a practice known as dependency injection, is a sound design pattern for developing loosely coupled and highly configurable software. Such type hints should be supported with minimal restrictions.

Installation

You can install using pip as:

pip install jsonargparse

By default, the only dependency installed with jsonargparse is PyYAML. However, several optional features can be enabled by specifying one or more of the following extras (optional dependencies): signatures, jsonschema, jsonnet, urls, fsspec, toml, ruamel, omegaconf, shtab, and argcomplete. Additionally, the all extras can be used to enable all optional features (excluding tab completion ones). To install jsonargparse with extras, use the following syntax:

pip install "jsonargparse[signatures,urls]"  # Enable signatures and URLs features
pip install "jsonargparse[all]"              # Enable all optional features

To install the latest development version, use the following command:

pip install "jsonargparse[signatures] @ https://github.com/mauvilsa/jsonargparse/zipball/main"

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonargparse-4.52.0.tar.gz (164.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsonargparse-4.52.0-py3-none-any.whl (174.8 kB view details)

Uploaded Python 3

File details

Details for the file jsonargparse-4.52.0.tar.gz.

File metadata

  • Download URL: jsonargparse-4.52.0.tar.gz
  • Upload date:
  • Size: 164.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for jsonargparse-4.52.0.tar.gz
Algorithm Hash digest
SHA256 103168510fab9d45a980fe7560dcbf20d1cce38320a43904583d23869af3bee1
MD5 b398c0fd3328269f39e911d730328202
BLAKE2b-256 f11b86ab3c48f74609de566e6c6fea5493a7bea4c7de485e5a56fa1239c698b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonargparse-4.52.0.tar.gz:

Publisher: tests.yaml on mauvilsa/jsonargparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jsonargparse-4.52.0-py3-none-any.whl.

File metadata

  • Download URL: jsonargparse-4.52.0-py3-none-any.whl
  • Upload date:
  • Size: 174.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for jsonargparse-4.52.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1878b16b6be90c3e838aac569784a110fe1eb1806c28e56175cdc7f2e563d78c
MD5 f816975549bf27364c9b7b42036732f9
BLAKE2b-256 5270e9114d52e9e72daaaeec30ecafe1018a4fbe6288ec35e16822529676b671

See more details on using hashes here.

Provenance

The following attestation bundles were made for jsonargparse-4.52.0-py3-none-any.whl:

Publisher: tests.yaml on mauvilsa/jsonargparse

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

4.52.0 This release

2 files

4.51.0

2 files

4.50.0

2 files

4.49.0

2 files

4.48.0

2 files

4.47.0

2 files

4.46.0

2 files

4.45.0

2 files

4.44.0

2 files

4.43.0

2 files

4.42.0

2 files

4.41.0

2 files

4.40.2

2 files

4.40.1

2 files

4.40.0

2 files

4.39.0

2 files

4.38.0

2 files

4.37.0

2 files

4.36.0

2 files

4.35.0

2 files

4.34.1

2 files

4.34.0

2 files

4.33.2

2 files

4.33.1

2 files

4.32.1

2 files

4.32.0

2 files

4.31.0

2 files

4.30.0

2 files

4.29.0

2 files

4.28.0

2 files

4.27.7

2 files

4.27.6

2 files

4.27.5

2 files

4.27.4

2 files

4.27.3

2 files

4.27.2

2 files

4.27.1

2 files

4.27.0

2 files

4.26.2

2 files

4.26.1

2 files

4.26.0

2 files

4.25.0

2 files

4.24.1

2 files

4.24.0

2 files

4.23.1

2 files

4.23.0

2 files

4.22.1

2 files

4.22.0

2 files

4.21.2

2 files

4.21.1

2 files

4.21.0

2 files

4.20.1

2 files

4.20.0

2 files

4.19.0

2 files

4.18.0

2 files

4.17.0

2 files

4.16.0

2 files

4.15.2

2 files

4.15.1

2 files

4.15.0

2 files

4.14.1

2 files

4.14.0

2 files

4.13.3

2 files

4.13.2

2 files

4.13.1

2 files

4.13.0

2 files

4.12.0

2 files

4.11.0

2 files

4.10.2

2 files

4.10.1

2 files

4.10.0

2 files

4.9.0

2 files

4.8.0

2 files

4.7.3

2 files

4.7.2

2 files

4.7.1

2 files

4.7.0

2 files

4.6.0

2 files

4.5.0

2 files

4.4.0

2 files

4.3.1

2 files

4.3.0

2 files

4.2.0

2 files

4.1.4

2 files

4.1.3

2 files

4.1.2

2 files

4.1.1

2 files

4.1.0

2 files

4.0.4

2 files

4.0.3

2 files

4.0.2

2 files

4.0.1

2 files

4.0.0

2 files

3.19.4

2 files

3.19.3

2 files

3.19.2

2 files

3.19.1

2 files

3.19.0

2 files

3.18.0

2 files

3.17.0

2 files

3.16.1

2 files

3.16.0

2 files

3.15.0

2 files

3.14.0

2 files

3.13.1

2 files

3.13.0

2 files

3.12.1

2 files

3.12.0

2 files

3.11.2

2 files

3.11.1

2 files

3.11.0

2 files

3.10.1

2 files

3.10.0

2 files

3.9.0

2 files

3.8.1

2 files

3.8.0

2 files

3.7.0

2 files

3.6.0

2 files

3.5.1

2 files

3.5.0

2 files

3.4.1

2 files

3.4.0

2 files

3.3.2

2 files

3.3.1

2 files

3.3.0

2 files

3.2.1

2 files

3.1.0

2 files

3.0.1

2 files

3.0.0

2 files

2.32.2

2 files

2.32.1

1 file

2.32.0

1 file

2.31.2

1 file

2.31.1

1 file

2.31.0

1 file

2.30.2

1 file

2.30.0

1 file

2.29.0

1 file

2.28.0

1 file

2.27.0

1 file

2.26.1

1 file

2.26.0

1 file

2.25.4

1 file

2.25.3

1 file

2.25.2

1 file

2.25.1

1 file

2.25.0

1 file

2.24.1

1 file

2.24.0

1 file

2.23.5

1 file

2.23.4

1 file

2.23.3

1 file

2.23.2

1 file

2.23.1

1 file

2.23.0

1 file

2.22.2

1 file

2.22.1

1 file

2.22.0

1 file

2.21.0

1 file

2.20.0

1 file

2.19.0

1 file

2.18.0

1 file

2.17.0

1 file

2.16.0

1 file

2.15.0

1 file

2.14.3

1 file

2.14.2

1 file

2.14.1

1 file

2.14.0

1 file

2.13.1

1 file

2.13.0

1 file

2.12.0

1 file

2.11.0

1 file

2.10.1

1 file

2.9.0

1 file

2.8.0

1 file

2.7.0

1 file

2.6.1

1 file

2.6.0

1 file

2.5.0

1 file

2.4.1

1 file

2.4.0

1 file

2.3.0

1 file

2.2.1

1 file

2.1.1

1 file

2.1.0

1 file

2.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page