{"id":16513233,"url":"https://github.com/moisutsu/classopt","last_synced_at":"2025-10-12T07:22:22.024Z","repository":{"id":45826500,"uuid":"382745032","full_name":"moisutsu/classopt","owner":"moisutsu","description":"Arguments parser with class for Python, inspired by StructOpt","archived":false,"fork":false,"pushed_at":"2023-09-17T07:20:21.000Z","size":87,"stargazers_count":61,"open_issues_count":4,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T16:44:58.800Z","etag":null,"topics":["argument-parser","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/classopt/","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/moisutsu.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":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-04T02:18:04.000Z","updated_at":"2024-11-27T07:01:26.000Z","dependencies_parsed_at":"2024-06-21T14:07:01.594Z","dependency_job_id":null,"html_url":"https://github.com/moisutsu/classopt","commit_stats":{"total_commits":86,"total_committers":5,"mean_commits":17.2,"dds":0.2441860465116279,"last_synced_commit":"6d0781164696bc021b856768a56eaef22a2c0cd5"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisutsu%2Fclassopt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisutsu%2Fclassopt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisutsu%2Fclassopt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moisutsu%2Fclassopt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moisutsu","download_url":"https://codeload.github.com/moisutsu/classopt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826780,"owners_count":20354220,"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":["argument-parser","python"],"created_at":"2024-10-11T16:08:12.852Z","updated_at":"2025-10-12T07:22:17.007Z","avatar_url":"https://github.com/moisutsu.png","language":"Python","readme":"\u003ch1 align=\"center\"\u003eWelcome to ClassOpt 👋\u003c/h1\u003e\n\u003cp\u003e\n  \u003cimg alt=\"Version\" src=\"https://img.shields.io/pypi/v/classopt\" /\u003e\n  \u003ca href=\"https://github.com/moisutsu/classopt/blob/main/LICENSE\" target=\"_blank\"\u003e\n    \u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://twitter.com/moisutsu\" target=\"_blank\"\u003e\n    \u003cimg alt=\"Twitter: moisutsu\" src=\"https://img.shields.io/twitter/follow/moisutsu.svg?style=social\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003e Arguments parser with class for Python, inspired by [StructOpt](https://github.com/TeXitoi/structopt)\n\n## Install\n\n```sh\npip install classopt\n```\n\n## Usage\n\n\nImport `classopt` and define the Opt class with decorator.\n\n```python\nfrom classopt import classopt\n\n@classopt(default_long=True)\nclass Opt:\n    file: str\n    count: int = 3\n    numbers: list[int]\n    flag: bool\n\nif __name__ == \"__main__\":\n    opt = Opt.from_args()\n    print(opt)\n    print(opt.file)\n```\n\nRun with command line arguments.\n\n```bash\n$ python example.py --file example.txt --numbers 1 2 3 --flag\nOpt(file='example.txt', count=3, numbers=[1, 2, 3], flag=True)\nexample.txt\n```\nYou can specify most of the arguments to [argparse.ArgumentParser.add_argument](https://docs.python.org/ja/3/library/argparse.html#argparse.ArgumentParser.add_argument) in `config` (except name_or_flags).\n\n\n```python\nfrom classopt import classopt, config\n\n@classopt\nclass Opt:\n    file: str\n    count: int = config(long=True)\n    numbers: list = config(long=True, short=True, nargs=\"+\", type=int)\n    flag: bool = config(long=True, action=\"store_false\")\n\nif __name__ == \"__main__\":\n    opt = Opt.from_args()\n    print(opt)\n```\n\n```bash\n$ python example.py example.txt --count 5 -n 1 2 3 --flag\nOpt(file='example.txt', count=5, numbers=[1, 2, 3], flag=False)\n```\n\nSome details\n```python\n# `default_long=True` is equivalent to `config(long=True)' for all members\n# Similarly, you can do `default_short=True`\n@classopt(default_long=True)\nclass Opt:\n    # `long=False` overrides `default_long=True`\n    file: str = config(long=False)\n\n    # equivalent to `numbers: list = config(nargs=\"*\", type=int)`\n    # and `numbers: typing.List[int]`\n    numbers: list[int]\n\n    # equivalent to `flag: bool = config(action=\"store_true\")`\n    flag: bool\n```\n\n### Other Way\n\nYou can also define an argument parser by inheriting from `ClassOpt`.\n\n```python\nfrom classopt import ClassOpt, config\n\nclass Opt(ClassOpt):\n    file: str\n    count: int = config(long=True)\n    numbers: list[int] = config(long=True, short=\"-c\")\n    flag: bool = config(long=True)\n\nif __name__ == \"__main__\":\n    opt = Opt.from_args()\n    print(opt)\n    print(opt.file)\n```\n\nRun with command line arguments.\n\n```bash\n$ python example.py example.txt --count 5 -c 1 2 3 --flag\nOpt(file='example.txt', count=5, numbers=[1, 2, 3], flag=True)\nexample.txt\n```\n\nThe inherited method does not support some features and may disappear in the future.\nSo we recommend the decorator method.\n\n## Run tests\n\n```sh\npoetry run pytest\n```\n\n## Author\n\n👤 **moisutsu**\n\n* Twitter: [@moisutsu](https://twitter.com/moisutsu)\n* Github: [@moisutsu](https://github.com/moisutsu)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n\n## 📝 License\n\nCopyright © 2021 [moisutsu](https://github.com/moisutsu).\u003cbr /\u003e\nThis project is [MIT](https://github.com/moisutsu/classopt/blob/main/LICENSE) licensed.\n\n***\n_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoisutsu%2Fclassopt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoisutsu%2Fclassopt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoisutsu%2Fclassopt/lists"}