jsonargparse

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

https://github.com/omni-us/jsonargparse

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 29 committers (3.4%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.0%) to scientific vocabulary

Keywords

argparse argparse-alternative argument-parser cli configuration-files dataclasses environment-variables json jsonnet omegaconf python python3 toml type-hints yaml

Keywords from Contributors

profiles brain-computer-interfaces gravitational-lensing energy-system transformers energy-system-model pypi llm-inference tensors llms
Last synced: 4 months ago · JSON representation ·

Repository

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

Basic Info
Statistics
  • Stars: 387
  • Watchers: 4
  • Forks: 57
  • Open Issues: 31
  • Releases: 0
Topics
argparse argparse-alternative argument-parser cli configuration-files dataclasses environment-variables json jsonnet omegaconf python python3 toml type-hints yaml
Created over 6 years ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing Funding License Code of conduct Citation Security

README.rst

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


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
`__.

Teaser examples
---------------

CLI with minimal boilerplate:

.. code-block:: python

    from jsonargparse import auto_cli

    def main_function(...):  # your main parameters and logic here
        ...

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

Minimal boilerplate but manually parsing:

.. code-block:: python

    from jsonargparse import auto_parser

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

Powerful argparse-like low level parsers:

.. code-block:: python

    from jsonargparse import ArgumentParser

    parser = ArgumentParser()
    parser.add_argument("--config", action="config")  # support config files
    parser.add_argument("--opt", type=Union[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_classes(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:

- **Automatic** creation of CLIs, like `Fire
  `__, `Typer
  `__, `Clize
  `__ and `Tyro
  `__.

- Use **type hints** for argument validation, like `Typer
  `__, `Tap
  `__ and `Tyro
  `__.

- Use of **docstrings** for automatic generation of help, like `Tap
  `__, `Tyro
  `__ and `SimpleParsing
  `__.

- Parse from **configuration files** and **environment variables**, like
  `OmegaConf `__, `dynaconf
  `__, `confuse
  `__ and `configargparse
  `__.

- **Dataclasses** support, like `SimpleParsing
  `__ and `Tyro
  `__.


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:

Installation
============

You can install using `pip `__ as:

.. code-block:: bash

    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:

.. code-block:: bash

    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:

.. code-block:: bash

    pip install "jsonargparse[signatures] @ git+https://github.com/omni-us/jsonargparse.git@main"

Owner

  • Name: omni:us Engineering
  • Login: omni-us
  • Kind: organization
  • Email: github@omnius.com
  • Location: Berlin, Germany

Open source contributions from the Omnius Engineering Team

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you want to cite this software, please do as follows."
title: jsonargparse
license: MIT
repository-code: https://github.com/omni-us/jsonargparse
authors:
  - family-names: Villegas
    given-names: Mauricio
    orcid: https://orcid.org/0000-0001-7450-6707
  - name: contributors
version: 4
date-released: 2021-11-16

GitHub Events

Total
  • Issues event: 100
  • Watch event: 56
  • Delete event: 93
  • Issue comment event: 458
  • Push event: 227
  • Pull request review event: 56
  • Pull request review comment event: 51
  • Pull request event: 191
  • Fork event: 14
  • Create event: 103
Last Year
  • Issues event: 100
  • Watch event: 56
  • Delete event: 93
  • Issue comment event: 458
  • Push event: 227
  • Pull request review event: 56
  • Pull request review comment event: 51
  • Pull request event: 191
  • Fork event: 14
  • Create event: 103

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 1,122
  • Total Committers: 29
  • Avg Commits per committer: 38.69
  • Development Distribution Score (DDS): 0.045
Past Year
  • Commits: 168
  • Committers: 10
  • Avg Commits per committer: 16.8
  • Development Distribution Score (DDS): 0.071
Top Committers
Name Email Commits
Mauricio Villegas m****e@y****m 1,072
Jirka Borovec 6****a 7
Santiago Castro s****0@h****m 5
Andrew Gardner a****0@g****m 3
pre-commit-ci[bot] 6****] 3
Daniel Dale d****e@g****m 3
Kian-Meng Ang k****g@c****g 2
Miguel Monteiro m****r@g****m 2
Jon Crall e****c@g****m 2
Ioannis Gatopoulos j****p@g****m 2
Dennis Torres d****s@p****m 2
Carlos Mocholí c****i@g****m 2
Andrew Balinski a****i@g****m 1
Basha Mougamadou b****u@c****m 1
Cody Martin 6****0 1
Dian Li d****i@t****e 1
wangtianshu w****g@t****e 1
qunhong zneg 8****9@q****m 1
diede d****e@o****m 1
Solvik Blum s****m@d****m 1
Rustam Khadipash 1****h 1
Quillot Mathias m****t@a****r 1
PierreGtch 2****h 1
Pablo LION 3****N 1
Natarajan Krishnaswami n****n@k****g 1
LGTM Migrator l****r 1
Hubert Palo d****p@g****m 1
Ethan Marx 6****x 1
Eggry Ran e****y@l****n 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 203
  • Total pull requests: 534
  • Average time to close issues: 3 months
  • Average time to close pull requests: 3 days
  • Total issue authors: 106
  • Total pull request authors: 27
  • Average comments per issue: 2.71
  • Average comments per pull request: 1.95
  • Merged pull requests: 462
  • Bot issues: 0
  • Bot pull requests: 22
Past Year
  • Issues: 61
  • Pull requests: 236
  • Average time to close issues: 13 days
  • Average time to close pull requests: 3 days
  • Issue authors: 40
  • Pull request authors: 16
  • Average comments per issue: 1.85
  • Average comments per pull request: 1.86
  • Merged pull requests: 191
  • Bot issues: 0
  • Bot pull requests: 7
Top Authors
Issue Authors
  • rusmux (12)
  • carmocca (10)
  • MiguelMonteiro (8)
  • function2-llx (7)
  • indigoviolet (6)
  • EthanMarx (6)
  • maticus (6)
  • samvanstroud (4)
  • hadipash (4)
  • Erotemic (4)
  • mauvilsa (4)
  • bilelomrani1 (4)
  • a-gardner1 (4)
  • AlejandroBaron (3)
  • florianblume (3)
Pull Request Authors
  • mauvilsa (453)
  • pre-commit-ci[bot] (21)
  • MiguelMonteiro (7)
  • a-gardner1 (6)
  • Borda (6)
  • Erotemic (5)
  • mauvilsa-omnius (4)
  • mquillot (4)
  • nkrishnaswami (2)
  • eggry (2)
  • PierreGtch (2)
  • HubertPalo (2)
  • EthanMarx (2)
  • euxhenh (2)
  • DianLiI (2)
Top Labels
Issue Labels
bug (96) enhancement (71) question (21) pending author response (8) refactor (6) duplicate (6) documentation (5) wontfix (3)
Pull Request Labels
bug (213) refactor (171) enhancement (95) documentation (10) wontfix (1)

Packages

  • Total packages: 4
  • Total downloads:
    • pypi 2,238,782 last-month
  • Total docker downloads: 1,433,692
  • Total dependent packages: 30
    (may contain duplicates)
  • Total dependent repositories: 473
    (may contain duplicates)
  • Total versions: 273
  • Total maintainers: 2
pypi.org: jsonargparse

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

  • Versions: 193
  • Dependent Packages: 27
  • Dependent Repositories: 466
  • Downloads: 2,233,168 Last month
  • Docker Downloads: 1,433,692
Rankings
Downloads: 0.4%
Average: 0.6%
Dependent repos count: 0.7%
Dependent packages count: 0.7%
Docker downloads count: 0.8%
Maintainers (1)
Last synced: 4 months ago
pypi.org: yamlargparse

Parsing of command line options, yaml config files and/or environment variables based on argparse.

  • Versions: 33
  • Dependent Packages: 0
  • Dependent Repositories: 5
  • Downloads: 5,614 Last month
Rankings
Stargazers count: 4.5%
Dependent repos count: 6.6%
Forks count: 6.6%
Average: 7.9%
Dependent packages count: 10.1%
Downloads: 11.9%
Maintainers (1)
Last synced: 4 months ago
spack.io: py-jsonargparse

An extension to python's argparse which simplifies parsing of configuration options from command line arguments, json configuration files (yaml or jsonnet supersets), environment variables and hard-coded defaults.

  • Versions: 6
  • Dependent Packages: 2
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Stargazers count: 16.0%
Forks count: 20.8%
Average: 23.5%
Dependent packages count: 57.3%
Maintainers (1)
Last synced: 4 months ago
conda-forge.org: jsonargparse
  • Versions: 41
  • Dependent Packages: 1
  • Dependent Repositories: 2
Rankings
Dependent repos count: 20.3%
Average: 27.9%
Stargazers count: 28.1%
Dependent packages count: 29.0%
Forks count: 34.2%
Last synced: 4 months ago

Dependencies

.github/workflows/code-checks.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/codeql.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite
.github/workflows/tests.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite