Skip to main content

Implement minimal boilerplate CLIs derived from type hints and parse from command line, config files and environment variables.

Project description

https://readthedocs.org/projects/jsonargparse/badge/?version=stable https://github.com/omni-us/jsonargparse/actions/workflows/tests.yaml/badge.svg https://codecov.io/gh/omni-us/jsonargparse/branch/main/graph/badge.svg https://sonarcloud.io/api/project_badges/measure?project=omni-us_jsonargparse&metric=alert_status https://badge.fury.io/py/jsonargparse.svg

jsonargparse

Docs: https://jsonargparse.readthedocs.io/ | Source: https://github.com/omni-us/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.

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.), user-defined generics, restricted types (regex, numbers), paths, URLs, types from stubs (*.pyi), future annotations (PEP 563), and backports (PEPs 604/585).

  • 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 extendable 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.

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 that jsonargparse installs is PyYAML. However, several optional features can be enabled by specifying any of the following extras requires: signatures, jsonschema, jsonnet, urls, fsspec, toml, ruyaml, omegaconf, shtab and argcomplete. There is also the all extras require to enable all optional features (excluding tab completion ones). Installing jsonargparse with extras require is as follows:

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

Project details


Release history Release notifications | RSS feed

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.38.0.tar.gz (198.3 kB view details)

Uploaded Source

Built Distribution

jsonargparse-4.38.0-py3-none-any.whl (219.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsonargparse-4.38.0.tar.gz
Algorithm Hash digest
SHA256 a73f2388f894fb2705eb06ec5fb424efe284330e35be5ad8356ac707810d4880
MD5 0252b526f9ac9d634907f9561ead3952
BLAKE2b-256 51f5f7974f85789c9538232dfc079291374cf15fa28fd457541eece1c7da7738

See more details on using hashes here.

Provenance

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

Publisher: tests.yaml on omni-us/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.38.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jsonargparse-4.38.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e0567f40db3dd71621d74909613f3fc29d3d8732db7785a83bb70123f994501
MD5 51089e1f286ab214c31f1cdc3f0dceab
BLAKE2b-256 f524d3b1f6c22407c17a66e37d97cef61900d36595108c234aa18f5ac6a5828e

See more details on using hashes here.

Provenance

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

Publisher: tests.yaml on omni-us/jsonargparse

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

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page