{"id":13532948,"url":"https://github.com/lebrice/SimpleParsing","last_synced_at":"2025-04-01T21:31:30.164Z","repository":{"id":37759275,"uuid":"213200949","full_name":"lebrice/SimpleParsing","owner":"lebrice","description":"Simple, Elegant, Typed Argument Parsing with argparse","archived":false,"fork":false,"pushed_at":"2025-02-03T14:55:31.000Z","size":1440,"stargazers_count":460,"open_issues_count":64,"forks_count":56,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-28T21:37:25.668Z","etag":null,"topics":["argparse","argparse-alternative","argument-parsing","dataclasses","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lebrice.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"docs/Roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-06T16:15:54.000Z","updated_at":"2025-03-28T18:05:29.000Z","dependencies_parsed_at":"2023-02-19T13:31:19.037Z","dependency_job_id":"32168e65-7e4c-411d-9d99-8c12eda1242f","html_url":"https://github.com/lebrice/SimpleParsing","commit_stats":{"total_commits":336,"total_committers":29,"mean_commits":"11.586206896551724","dds":"0.13690476190476186","last_synced_commit":"4388893b768495090dcd8dc7e399372d8e5829be"},"previous_names":[],"tags_count":76,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebrice%2FSimpleParsing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebrice%2FSimpleParsing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebrice%2FSimpleParsing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lebrice%2FSimpleParsing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lebrice","download_url":"https://codeload.github.com/lebrice/SimpleParsing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246713111,"owners_count":20821840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["argparse","argparse-alternative","argument-parsing","dataclasses","python"],"created_at":"2024-08-01T07:01:15.268Z","updated_at":"2025-04-01T21:31:26.688Z","avatar_url":"https://github.com/lebrice.png","language":"Python","readme":"![Build Status](https://github.com/lebrice/SimpleParsing/actions/workflows/build.yml/badge.svg) [![PyPI version](https://badge.fury.io/py/simple-parsing.svg)](https://badge.fury.io/py/simple-parsing)\n\n# Simple, Elegant, Typed Argument Parsing \u003c!-- omit in toc --\u003e\n\n`simple-parsing` allows you to transform your ugly `argparse` scripts into beautifully structured, strongly typed little works of art. This isn't a fancy, complicated new command-line tool either, ***this simply adds new features to plain-old argparse!***\nUsing [dataclasses](https://docs.python.org/3.7/library/dataclasses.html), `simple-parsing` makes it easier to share and reuse command-line arguments - ***no more copy pasting!***\n\nSupports inheritance, **nesting**, easy serialization to json/yaml, automatic help strings from comments, and much more!\n\n```python\n# examples/demo.py\nfrom dataclasses import dataclass\nfrom simple_parsing import ArgumentParser\n\nparser = ArgumentParser()\nparser.add_argument(\"--foo\", type=int, default=123, help=\"foo help\")\n\n@dataclass\nclass Options:\n    \"\"\" Help string for this group of command-line arguments \"\"\"\n    log_dir: str                # Help string for a required str argument\n    learning_rate: float = 1e-4 # Help string for a float argument\n\nparser.add_arguments(Options, dest=\"options\")\n\nargs = parser.parse_args()\nprint(\"foo:\", args.foo)\nprint(\"options:\", args.options)\n```\n\n```console\n$ python examples/demo.py --log_dir logs --foo 123\nfoo: 123\noptions: Options(log_dir='logs', learning_rate=0.0001)\n```\n\n```console\n$ python examples/demo.py --help\nusage: demo.py [-h] [--foo int] --log_dir str [--learning_rate float]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --foo int             foo help (default: 123)\n\nOptions ['options']:\n   Help string for this group of command-line arguments\n\n  --log_dir str         Help string for a required str argument (default:\n                        None)\n  --learning_rate float\n                        Help string for a float argument (default: 0.0001)\n```\n\n### (*new*) Simplified API:\n\nFor a simple use-case, where you only want to parse a single dataclass, you can use the `simple_parsing.parse` or `simple_parsing.parse_known_args` functions:\n\n```python\noptions: Options = simple_parsing.parse(Options)\n# or:\noptions, leftover_args = simple_parsing.parse_known_args(Options)\n```\n\n## installation\n\n`pip install simple-parsing`\n\n## [Examples](https://github.com/lebrice/SimpleParsing/tree/master/examples/README.md)\n\n## [API Documentation](https://github.com/lebrice/SimpleParsing/tree/master/docs/README.md) (Under construction)\n\n## Features\n\n- ### [Automatic \"--help\" strings](https://github.com/lebrice/SimpleParsing/tree/master/examples/docstrings/README.md)\n\n  As developers, we want to make it easy for people coming into our projects to understand how to run them. However, a user-friendly `--help` message is often hard to write and to maintain, especially as the number of arguments increases.\n\n  With `simple-parsing`, your arguments and their descriptions are defined in the same place, making your code easier to read, write, and maintain.\n\n- ### Modular, Reusable, Cleanly Grouped Arguments\n\n  *(no more copy-pasting)*\n\n  When you need to add a new group of command-line arguments similar to an existing one, instead of copy-pasting a block of `argparse` code and renaming variables, you can reuse your argument class, and let the `ArgumentParser` take care of adding relevant prefixes to the arguments for you:\n\n  ```python\n  parser.add_arguments(Options, dest=\"train\")\n  parser.add_arguments(Options, dest=\"valid\")\n  args = parser.parse_args()\n  train_options: Options = args.train\n  valid_options: Options = args.valid\n  print(train_options)\n  print(valid_options)\n  ```\n\n  ```console\n  $ python examples/demo.py \\\n      --train.log_dir \"training\" \\\n      --valid.log_dir \"validation\"\n  Options(log_dir='training', learning_rate=0.0001)\n  Options(log_dir='validation', learning_rate=0.0001)\n  ```\n\n  These prefixes can also be set explicitly, or not be used at all. For more info, take a look at the [Prefixing Guide](https://github.com/lebrice/SimpleParsing/tree/master/examples/prefixing/README.md)\n\n- ### [Argument subgroups](https://github.com/lebrice/SimpleParsing/tree/master/examples/subgroups/README.md)\n\n  It's easy to choose between different argument groups of arguments, with the `subgroups`\n  function!\n\n- ### [Setting defaults from Configuration files](https://github.com/lebrice/SimpleParsing/tree/master/examples/config_files/README.md)\n\n  Default values for command-line arguments can easily be read from many different formats, including json/yaml!\n\n- ### [**Easy serialization**](https://github.com/lebrice/SimpleParsing/tree/master/examples/serialization/README.md):\n\n  Easily save/load configs to `json` or `yaml`!.\n\n- ### [**Inheritance**!](https://github.com/lebrice/SimpleParsing/tree/master/examples/inheritance/README.md)\n\n  You can easily customize an existing argument class by extending it and adding your own attributes, which helps promote code reuse across projects. For more info, take a look at the [inheritance example](https://github.com/lebrice/SimpleParsing/tree/master/examples/inheritance/inheritance_example.py)\n\n- ### [**Nesting**!](https://github.com/lebrice/SimpleParsing/tree/master/examples/nesting/README.md):\n\n  Dataclasses can be nested within dataclasses, as deep as you need!\n\n- ### [Easier parsing of lists and tuples](https://github.com/lebrice/SimpleParsing/tree/master/examples/container_types/README.md) :\n\n  This is sometimes tricky to do with regular `argparse`, but `simple-parsing` makes it a lot easier by using the python's builtin type annotations to automatically convert the values to the right type for you.\n  As an added feature, by using these type annotations, `simple-parsing` allows you to parse nested lists or tuples, as can be seen in [this example](https://github.com/lebrice/SimpleParsing/tree/master/examples/merging/README.md)\n\n- ### [Enums support](https://github.com/lebrice/SimpleParsing/tree/master/examples/enums/README.md)\n\n- (More to come!)\n\n## Examples:\n\nAdditional examples for all the features mentioned above can be found in the [examples folder](https://github.com/lebrice/SimpleParsing/tree/master/examples/README.md)\n","funding_links":[],"categories":["[Python](https://www.python.org/)","Python"],"sub_categories":["Useful awesome list for Go cli"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flebrice%2FSimpleParsing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flebrice%2FSimpleParsing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flebrice%2FSimpleParsing/lists"}