{"id":16841675,"url":"https://github.com/redtachyon/typarse","last_synced_at":"2026-01-27T19:44:33.097Z","repository":{"id":130379081,"uuid":"330152376","full_name":"RedTachyon/typarse","owner":"RedTachyon","description":"Simple type-based argument parsing","archived":false,"fork":false,"pushed_at":"2024-10-21T11:20:00.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T05:51:55.340Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RedTachyon.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-01-16T11:59:21.000Z","updated_at":"2024-10-21T11:20:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"42f8322d-d620-4088-9826-7b7117380c91","html_url":"https://github.com/RedTachyon/typarse","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedTachyon%2Ftyparse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedTachyon%2Ftyparse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedTachyon%2Ftyparse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedTachyon%2Ftyparse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RedTachyon","download_url":"https://codeload.github.com/RedTachyon/typarse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351410,"owners_count":21089271,"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":[],"created_at":"2024-10-13T12:42:42.315Z","updated_at":"2026-01-27T19:44:33.032Z","avatar_url":"https://github.com/RedTachyon.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typarse\n\nThis is a small project born out of my frustration with simple argument parsing in Python.\n\nNot only do I have to instantiate some object whose name I can never remember, then I get way too many \nfunction parameters to get them right... It's a mess. And I don't even need half the features.\n\nSo this is an attempt at streamlining this process while simultaneously promoting some better type safety, by using the\nmagic of Python type hints! \n\nReally all the magic here is happening in the BaseParser class. You just need to subclass it, add a few typed parameters,\nperhaps with some extra information in dictionaries... and you're done! For examples, just look at, well, examples.\n\n## Supported types\n\nFirst of all, all the basic types supported by argparse are also supported here. Things like: `str`, `int`, `float`. `bool`s are automatically interpreted as flags, False by default. Each type can be wrapped in a `List` to support reading them like `--list 1 2 3 4`. Each type can also be made `Optional` which makes it, well, optinal.\n\n\n## Simple illustrative example\n\n```python\nfrom typarse import BaseParser\nfrom typing import List\n\n\nclass Parser(BaseParser):\n    nums: List[int]\n    square: bool\n    default: int = 0\n\n    _abbrev = {\n        \"nums\": \"n\",\n        \"square\": \"s\",\n        \"default\": \"d\"\n    }\n\n    _help = {\n        \"nums\": \"List of numbers to sum\",\n        \"square\": \"Whether the result should be squared\",\n        \"default\": \"Initial value, added to the sum\"\n    }\n\n\n\nargs = Parser()\n\nprint(args.default + sum(args.nums) ** (1+args.square))\n```\n\n# Functionality 2: Config\n\nIn the spirit of the library, I added a config management component. \nSimilarly to parsing, you can define a config using type annotations on a class -- also in a nested manner.\n\nExample:\n```python\nfrom typarse import BaseConfig\nfrom typing import List \n\nclass Config(BaseConfig):\n    rate: float = 0.1\n    amount: float = 0.01\n    limit: float = 1.\n    class PolicyConfig(BaseConfig):\n        layers: List[int] = [32, 32, 32]\n        activation: str = \"relu\"\n\nconfig = {\n    \"rate\": 0.5,\n    \"PolicyConfig\": {\n        \"layers\": [64, 64]\n    }\n}\n\n```\n\n# Installation\n\nIt's on PyPi so install it with `pip install typarse`, `poetry add typarse` or whatever you want. If you want to install it from the source, it's pure Python so I'm sure you can figure it out.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredtachyon%2Ftyparse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredtachyon%2Ftyparse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredtachyon%2Ftyparse/lists"}