{"id":19028650,"url":"https://github.com/jayanthkoushik/corgy","last_synced_at":"2025-04-23T15:43:59.161Z","repository":{"id":56798671,"uuid":"372658348","full_name":"jayanthkoushik/corgy","owner":"jayanthkoushik","description":"Feature rich Python data classes.","archived":false,"fork":false,"pushed_at":"2024-03-08T16:54:04.000Z","size":1697,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T22:40:25.945Z","etag":null,"topics":["argparse","argument-parsing","cli","command-line-parsing","python"],"latest_commit_sha":null,"homepage":"https://jkoushik.me/corgy/","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/jayanthkoushik.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-06-01T00:21:54.000Z","updated_at":"2024-07-09T02:08:53.000Z","dependencies_parsed_at":"2024-03-07T06:28:31.668Z","dependency_job_id":"12fe6b6c-e43c-46e9-afca-20741cae8619","html_url":"https://github.com/jayanthkoushik/corgy","commit_stats":{"total_commits":336,"total_committers":2,"mean_commits":168.0,"dds":"0.16666666666666663","last_synced_commit":"b2b5e83027674e06d4c5a1591d1ffa2a3673bb5a"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayanthkoushik%2Fcorgy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayanthkoushik%2Fcorgy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayanthkoushik%2Fcorgy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jayanthkoushik%2Fcorgy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jayanthkoushik","download_url":"https://codeload.github.com/jayanthkoushik/corgy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250462969,"owners_count":21434696,"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","argument-parsing","cli","command-line-parsing","python"],"created_at":"2024-11-08T21:11:53.756Z","updated_at":"2025-04-23T15:43:59.134Z","avatar_url":"https://github.com/jayanthkoushik.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# corgy\n\nCorgy is a Python library that allows you to create feature rich data\nclasses using intuitive type annotations.\n\n```pycon\n\u003e\u003e\u003e from typing import List\n\u003e\u003e\u003e from typing_extensions import Literal\n\u003e\u003e\u003e from corgy import Corgy\n\u003e\u003e\u003e from corgy.types import KeyValuePairs\n\n\u003e\u003e\u003e class G(Corgy):\n...     x: int\n...     y: Literal[\"y1\", \"y2\", \"y3\"]\n\n\u003e\u003e\u003e class C(Corgy):\n...     x: List[float] = [1.0, 2.0]\n...     y: KeyValuePairs[str, int]\n...     g: G\n\n```\n\n## Features\n\n* **Type checking**: `Corgy` instances are type-checked, and support a\n  number of type modifiers.\n\n```pycon\n\u003e\u003e\u003e from typing import Tuple\n\n\u003e\u003e\u003e class C(Corgy):\n...     x: int\n...     y: Tuple[int, int]\n\n\u003e\u003e\u003e C(x=\"1\")\nTraceback (most recent call last):\n    ...\nValueError: error setting `x`: invalid value for type '\u003cclass 'int'\u003e': '1'\n\n\u003e\u003e\u003e C(y=(1, 2, 3))\nTraceback (most recent call last):\n    ...\nValueError: error setting `y`: invalid value for type 'typing.Tuple[int, int]': (1, 2, 3): expected exactly '2' elements\n\n```\n\n* **Dictionary interface**: `Corgy` instances can be converted to/from\n  dictionaries.\n\n```pycon\n\u003e\u003e\u003e class G(Corgy):\n...     x: int\n\n\u003e\u003e\u003e class C(Corgy):\n...     x: int\n...     g: G\n\n\u003e\u003e\u003e g = G.from_dict({\"x\": 1})\n\u003e\u003e\u003e g\nG(x=1)\n\n\u003e\u003e\u003e c = C(x=2, g=g)\n\u003e\u003e\u003e c.as_dict()\n{'x': 2, 'g': {'x': 1}}\n\n```\n\n* **Command-line parsing**: `Corgy` class attributes can be added to an\n  `ArgumentParser` instance, and parsed from the command-line. Help\n  messages can be added to attributes with `Annotated`, and will be\n  passed to the command line parser.\n\n```pycon\n\u003e\u003e\u003e from argparse import ArgumentParser\n\u003e\u003e\u003e from typing import Optional\n\u003e\u003e\u003e from typing_extensions import Annotated\n\n\u003e\u003e\u003e class ArgGroup(Corgy):\n...     arg1: Annotated[Optional[int], \"optional number\"]\n...     arg2: Annotated[bool, \"a boolean\"]\n\n\u003e\u003e\u003e class MyArgs(Corgy):\n...     arg1: Annotated[int, \"a number\"] = 1\n...     arg2: Annotated[Tuple[float, ...], \"at least one float\"]\n...     grp1: Annotated[ArgGroup, \"group 1\"]\n\n\u003e\u003e\u003e parser = ArgumentParser(usage=\"\")\n\u003e\u003e\u003e MyArgs.add_args_to_parser(parser)\n\u003e\u003e\u003e parser.print_help()  # doctest: +SKIP\nusage:\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --arg1 ARG1           a number\n  --arg2 ARG2 [ARG2 ...]\n                        at least one float\n\ngrp1:\n  group 1\n\n  --grp1:arg1 [GRP1:ARG1]\n                        optional number\n  --grp1:arg2, --no-grp1:arg2\n                        a boolean\n\n```\n\n* **Enhanced argparse formatting**: The `corgy` package provides\n  `CorgyHelpFormatter`, a formatter class for `argparse`, with support\n  for colorized output. It can also be used independent of `Corgy`\n  classes.\n\n```pycon\n\u003e\u003e\u003e from corgy import CorgyHelpFormatter\n\n\u003e\u003e\u003e # `ArgGroup` and `MyArgs` as defined above\n\u003e\u003e\u003e parser = ArgumentParser(usage=\"\", formatter_class=CorgyHelpFormatter)\n\u003e\u003e\u003e MyArgs.add_args_to_parser(parser)\n\u003e\u003e\u003e parser.print_help()  # doctest: +SKIP\n```\n\n  ![Sample argparse output with `CorgyHelpFormatter`](https://raw.githubusercontent.com/jayanthkoushik/corgy/44d0d2bdc225456e1d1d0ac78cfde26065f9b86f/example.svg)\n\n* **Convenience types**: `corgy.types` provides a number of types for\n  converting strings into objects like paths, dictionaries, classes,\n  etc. These can be used standalone, but are especially useful for\n  parsing from command line arguments. Refer to the docs for details on\n  all available types. A small example is shown below.\n\n```pycon\n\u003e\u003e\u003e T = KeyValuePairs[str, int]\n\u003e\u003e\u003e m = T(\"x=1,y=2\")\n\u003e\u003e\u003e print(m)\n{'x': 1, 'y': 2}\n\n```\n\n## Install\n`corgy` is available on PyPI, and can be installed with pip:\n\n```bash\npip install corgy\n```\n\nSupport for colorized output requires the `crayons` package, also\navailable on PyPI. You can pull it as a dependency for `corgy` by\ninstalling with the `colors` extra:\n\n```bash\npip install corgy[colors]\n```\n\nParsing `Corgy` objects from `toml` files requires the `tomli` package\non Python versions below 3.11. This can be installed automatically with\nthe `toml` extra:\n\n```bash\npip install corgy[toml]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjayanthkoushik%2Fcorgy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjayanthkoushik%2Fcorgy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjayanthkoushik%2Fcorgy/lists"}