{"id":13501945,"url":"https://github.com/anntzer/defopt","last_synced_at":"2025-04-04T13:05:27.685Z","repository":{"id":37501916,"uuid":"51206172","full_name":"anntzer/defopt","owner":"anntzer","description":"Effortless argument parser","archived":false,"fork":false,"pushed_at":"2024-03-24T19:25:40.000Z","size":512,"stargazers_count":208,"open_issues_count":8,"forks_count":12,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-03-29T17:32:32.517Z","etag":null,"topics":["cli"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/defopt/","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/anntzer.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-06T14:44:50.000Z","updated_at":"2024-06-18T17:10:44.898Z","dependencies_parsed_at":"2023-01-30T03:30:36.156Z","dependency_job_id":"d6637436-e6fc-4829-9caf-892ee5f75c35","html_url":"https://github.com/anntzer/defopt","commit_stats":{"total_commits":282,"total_committers":7,"mean_commits":"40.285714285714285","dds":0.375886524822695,"last_synced_commit":"d4bbf716ebd7d5980c5d33d07289101f232c5545"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anntzer%2Fdefopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anntzer%2Fdefopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anntzer%2Fdefopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anntzer%2Fdefopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anntzer","download_url":"https://codeload.github.com/anntzer/defopt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247176524,"owners_count":20896487,"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":["cli"],"created_at":"2024-07-31T22:01:56.134Z","updated_at":"2025-04-04T13:05:27.659Z","avatar_url":"https://github.com/anntzer.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"defopt\n======\n\n| |GitHub| |PyPI| |conda-forge|\n| |Read the Docs| |Build|\n\n.. |GitHub|\n   image:: https://img.shields.io/badge/github-anntzer%2Fdefopt-brightgreen\n   :target: `GitHub repository`_\n.. |PyPI|\n   image:: https://img.shields.io/pypi/v/defopt.svg?color=brightgreen\n   :target: https://pypi.org/project/defopt\n.. |conda-forge|\n   image:: https://img.shields.io/conda/v/conda-forge/defopt.svg?label=conda-forge\u0026color=brightgreen\n   :target: https://anaconda.org/conda-forge/defopt\n.. |Read the Docs|\n   image:: https://img.shields.io/readthedocs/defopt\n   :target: `Read the Docs`_\n.. |Build|\n   image:: https://img.shields.io/github/actions/workflow/status/anntzer/defopt/build.yml?branch=main\n   :target: https://github.com/anntzer/defopt/actions\n\ndefopt is a lightweight, no-effort argument parser.\n\ndefopt will:\n\n- Allow functions to be run from code and the command line without modification.\n- Reward you for documenting your functions.\n- Save you from writing, testing and maintaining argument parsing code.\n\ndefopt will not:\n\n- Modify your functions in any way.\n- Allow you to build highly complex or customized command line tools.\n\nIf you want total control over how your command line looks or behaves, try\ndocopt_, click_ or argh_. If you just want to write Python code and leave the\ncommand line interface up to someone else, defopt is for you.\n\nUsage\n-----\n\nOnce you have written and documented_ your function, simply pass it to\n`defopt.run()` and you're done.\n\n.. code-block:: python\n\n    import defopt\n\n    # Use type hints:\n    def main(greeting: str, *, count: int = 1):\n        \"\"\"\n        Display a friendly greeting.\n\n        :param greeting: Greeting to display\n        :param count: Number of times to display the greeting\n        \"\"\"\n        for _ in range(count):\n            print(greeting)\n\n    # ... or document parameter types in the docstring:\n    def main(greeting, *, count=1):\n        \"\"\"\n        Display a friendly greeting.\n\n        :param str greeting: Greeting to display\n        :param int count: Number of times to display the greeting\n        \"\"\"\n        for _ in range(count):\n            print(greeting)\n\n    if __name__ == '__main__':\n        defopt.run(main)\n\nDescriptions of the parameters and the function itself are used to build an\ninformative help message.\n\n::\n\n    $ python test.py -h\n    usage: test.py [-h] [-c COUNT] greeting\n\n    Display a friendly greeting.\n\n    positional arguments:\n      greeting              Greeting to display\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -c COUNT, --count COUNT\n                            Number of times to display the greeting\n                            (default: 1)\n\nYour function can now be called identically from Python and the command line.\n\n::\n\n    \u003e\u003e\u003e from test import main\n    \u003e\u003e\u003e main('hello!', count=2)\n    hello!\n    hello!\n\n::\n\n    $ python test.py hello! --count 2\n    hello!\n    hello!\n\nPhilosopy\n---------\n\ndefopt was developed with the following guiding principles in mind:\n\n#. **The interface can be fully understood in seconds.** If it took any longer,\n   your time would be better spent learning a more flexible tool.\n\n#. **Anything you learn applies to the existing ecosystem.** The exact same\n   docstrings used by defopt are also used by Sphinx's autodoc_ extension to\n   generate documentation, and by your IDE to do type checking. Chances are you\n   already know everything you need to know to use defopt.\n\n#. **Everything is handled for you.** If you're using defopt, it's because you\n   don't want to write any argument parsing code *at all*. You can trust it to\n   build a logically consistent command line interface to your functions\n   with no configuration required.\n\n#. **Your Python functions are never modified.** Type conversions are only ever\n   applied to data originating from the command line. When used in code,\n   duck-typing still works exactly as you expect with no surprises.\n\nDevelopment\n-----------\n\nFor source code, examples, questions, feature requests and bug reports, visit\nthe `GitHub repository`_.\n\nDocumentation\n-------------\n\nDocumentation is hosted on `Read the Docs`_.\n\n.. _GitHub repository: https://github.com/anntzer/defopt\n.. _Read the Docs: https://defopt.readthedocs.io/en/latest/\n.. _autodoc: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html\n.. _docopt: http://docopt.org/\n.. _click: https://click.palletsprojects.com/\n.. _argh: https://argh.readthedocs.io/en/latest/\n.. _documented: https://defopt.readthedocs.io/en/latest/examples.html#docstring-styles\n\n.. This document is included in docs/index.rst; table of contents appears here.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanntzer%2Fdefopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanntzer%2Fdefopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanntzer%2Fdefopt/lists"}