argclz


Nameargclz JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryCreate commandline interface via dataclass-like class
upload_time2025-07-10 15:36:44
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseBSD 3-Clause License Copyright (c) 2025, Yu-Ting Wei Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords commandline
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # argclz

[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/argclz)](https://pypi.org/project/argclz/)
[![PyPI version](https://badge.fury.io/py/argclz.svg)](https://badge.fury.io/py/argclz)

[![Documentation Status](https://readthedocs.org/projects/argp/badge/?version=latest)](https://argp.readthedocs.io/en/latest/)
[![codecov](https://codecov.io/gh/ytsimon2004/argclz/branch/main/graph/badge.svg?token=HfO5frntJe)](https://codecov.io/gh/ytsimon2004/argclz)

Class-based command-line argument parsing for Python that combines the power of `argparse` with class definitions and
type annotations.

## Features

- **Type-safe arguments** - Automatically infer type conversion from Python type annotations
- **Clean syntax** - Define arguments as class attributes with straightforward decorators
- **Composable** - Easily reuse and extend argument definitions through inheritance
- **Validation** - Built-in validation system with chainable API
- **Subcommands** - Support for command hierarchies with minimal boilerplate
- **Organized help** - Group arguments into logical sections for better documentation

## Installation

```bash
pip install argclz
```

## [See Documentation](https://argp.readthedocs.io/en/latest/)

## Quick Start

```python
from argclz import *


class MyArgs(AbstractParser):
    verbose: bool = argument('--verbose', help='Enable verbose output')
    name: str = argument('-n', '--name', required=True, help='Name of the user')
    count: int = argument('--count', default=1, help='Number of times to greet')

    def run(self):
        for _ in range(self.count):
            if self.verbose:
                print(f"Greeting with enthusiasm: Hello, {self.name}!")
            else:
                print(f"Hello, {self.name}!")


if __name__ == '__main__':
    MyArgs().main()
```

Show help:

```bash
python my_script.py -h
```

Expected output:

```text
usage: my_script.py [-h] [--verbose] -n NAME [--count COUNT]

options:
  -h, --help            show this help message and exit
  --verbose             Enable verbose output
  -n NAME, --name NAME  Name of the user
  --count COUNT         Number of times to greet
```

Run with:

```bash
python my_script.py --name Alice --count 3 --verbose
```

## Core Features

### Argument Types

```python
# Regular argument
name: str = argument('-n', '--name', help='Name of the user')

# Boolean flag
verbose: bool = argument('--verbose', help='Enable verbose output')

# Positional argument
filename: str = pos_argument('FILENAME', help='Input file to process')

# Variable-length argument
items: list[str] = var_argument('ITEMS', help='Items to process')
```

### Type Parsers

```python
# Comma-separated values to a tuple of floats
coords: tuple[float, ...] = argument('--coords', type=float_tuple_type)

# Value range (min:max)
ranging: tuple[int, int] = argument('--range', type=int_tuple_type)
```

### Argument Organization

```python
# Grouped arguments
verbose: bool = argument('--verbose', group='general')
output_dir: str = argument('--output', group='output')

# Mutually exclusive arguments
output_json: bool = argument('--json', ex_group='output')
output_yaml: bool = argument('--yaml', ex_group='output')
```

### Validators

```python
# Range validator
age: int = argument('--age', validator.int.in_range(18, 99))

# Path validator
path: Path = argument('--path', validator.path.is_dir().is_exists())
```

### Subcommands

```python
class InitCmd(AbstractParser):
    name: str = argument('--name', required=True)

    def run(self):
        print(f"Initializing project: {self.name}")


class BuildCmd(AbstractParser):
    release: bool = argument('--release')

    def run(self):
        print("Building in release mode" if self.release else "Building in debug mode")


# Entry point
from argclz.commands import parse_command_args

if __name__ == '__main__':
    parse_command_args({
        'init': InitCmd,
        'build': BuildCmd
    })
```

### Reusable Option Classes

```python
class IOOptions:
    input_path: str = argument('--input', help='Input file')
    output_path: str = argument('--output', help='Output file')


class LoggingOptions:
    verbose: bool = argument('--verbose', help='Enable verbose logging')


class MyOptions(IOOptions, LoggingOptions):
    # Override an inherited argument
    input_path = as_argument(IOOptions.input_path).with_options(required=True)
```

## License

[BSD 3-Clause License](LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "argclz",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "commandline",
    "author": null,
    "author_email": "Yu-Ting Wei <ytsimon2004@gmail.com>, Ta-Shun Su <antoniost29@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f8/b0/60d6706ed4168c444bcb1c50c60a44c083f6f600c541417ee1c7916855ea/argclz-1.0.1.tar.gz",
    "platform": null,
    "description": "# argclz\n\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/argclz)](https://pypi.org/project/argclz/)\n[![PyPI version](https://badge.fury.io/py/argclz.svg)](https://badge.fury.io/py/argclz)\n\n[![Documentation Status](https://readthedocs.org/projects/argp/badge/?version=latest)](https://argp.readthedocs.io/en/latest/)\n[![codecov](https://codecov.io/gh/ytsimon2004/argclz/branch/main/graph/badge.svg?token=HfO5frntJe)](https://codecov.io/gh/ytsimon2004/argclz)\n\nClass-based command-line argument parsing for Python that combines the power of `argparse` with class definitions and\ntype annotations.\n\n## Features\n\n- **Type-safe arguments** - Automatically infer type conversion from Python type annotations\n- **Clean syntax** - Define arguments as class attributes with straightforward decorators\n- **Composable** - Easily reuse and extend argument definitions through inheritance\n- **Validation** - Built-in validation system with chainable API\n- **Subcommands** - Support for command hierarchies with minimal boilerplate\n- **Organized help** - Group arguments into logical sections for better documentation\n\n## Installation\n\n```bash\npip install argclz\n```\n\n## [See Documentation](https://argp.readthedocs.io/en/latest/)\n\n## Quick Start\n\n```python\nfrom argclz import *\n\n\nclass MyArgs(AbstractParser):\n    verbose: bool = argument('--verbose', help='Enable verbose output')\n    name: str = argument('-n', '--name', required=True, help='Name of the user')\n    count: int = argument('--count', default=1, help='Number of times to greet')\n\n    def run(self):\n        for _ in range(self.count):\n            if self.verbose:\n                print(f\"Greeting with enthusiasm: Hello, {self.name}!\")\n            else:\n                print(f\"Hello, {self.name}!\")\n\n\nif __name__ == '__main__':\n    MyArgs().main()\n```\n\nShow help:\n\n```bash\npython my_script.py -h\n```\n\nExpected output:\n\n```text\nusage: my_script.py [-h] [--verbose] -n NAME [--count COUNT]\n\noptions:\n  -h, --help            show this help message and exit\n  --verbose             Enable verbose output\n  -n NAME, --name NAME  Name of the user\n  --count COUNT         Number of times to greet\n```\n\nRun with:\n\n```bash\npython my_script.py --name Alice --count 3 --verbose\n```\n\n## Core Features\n\n### Argument Types\n\n```python\n# Regular argument\nname: str = argument('-n', '--name', help='Name of the user')\n\n# Boolean flag\nverbose: bool = argument('--verbose', help='Enable verbose output')\n\n# Positional argument\nfilename: str = pos_argument('FILENAME', help='Input file to process')\n\n# Variable-length argument\nitems: list[str] = var_argument('ITEMS', help='Items to process')\n```\n\n### Type Parsers\n\n```python\n# Comma-separated values to a tuple of floats\ncoords: tuple[float, ...] = argument('--coords', type=float_tuple_type)\n\n# Value range (min:max)\nranging: tuple[int, int] = argument('--range', type=int_tuple_type)\n```\n\n### Argument Organization\n\n```python\n# Grouped arguments\nverbose: bool = argument('--verbose', group='general')\noutput_dir: str = argument('--output', group='output')\n\n# Mutually exclusive arguments\noutput_json: bool = argument('--json', ex_group='output')\noutput_yaml: bool = argument('--yaml', ex_group='output')\n```\n\n### Validators\n\n```python\n# Range validator\nage: int = argument('--age', validator.int.in_range(18, 99))\n\n# Path validator\npath: Path = argument('--path', validator.path.is_dir().is_exists())\n```\n\n### Subcommands\n\n```python\nclass InitCmd(AbstractParser):\n    name: str = argument('--name', required=True)\n\n    def run(self):\n        print(f\"Initializing project: {self.name}\")\n\n\nclass BuildCmd(AbstractParser):\n    release: bool = argument('--release')\n\n    def run(self):\n        print(\"Building in release mode\" if self.release else \"Building in debug mode\")\n\n\n# Entry point\nfrom argclz.commands import parse_command_args\n\nif __name__ == '__main__':\n    parse_command_args({\n        'init': InitCmd,\n        'build': BuildCmd\n    })\n```\n\n### Reusable Option Classes\n\n```python\nclass IOOptions:\n    input_path: str = argument('--input', help='Input file')\n    output_path: str = argument('--output', help='Output file')\n\n\nclass LoggingOptions:\n    verbose: bool = argument('--verbose', help='Enable verbose logging')\n\n\nclass MyOptions(IOOptions, LoggingOptions):\n    # Override an inherited argument\n    input_path = as_argument(IOOptions.input_path).with_options(required=True)\n```\n\n## License\n\n[BSD 3-Clause License](LICENSE)\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License\n        \n        Copyright (c) 2025, Yu-Ting Wei\n        \n        Redistribution and use in source and binary forms, with or without\n        modification, are permitted provided that the following conditions are met:\n        \n        1. Redistributions of source code must retain the above copyright notice, this\n           list of conditions and the following disclaimer.\n        \n        2. Redistributions in binary form must reproduce the above copyright notice,\n           this list of conditions and the following disclaimer in the documentation\n           and/or other materials provided with the distribution.\n        \n        3. Neither the name of the copyright holder nor the names of its\n           contributors may be used to endorse or promote products derived from\n           this software without specific prior written permission.\n        \n        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n        ",
    "summary": "Create commandline interface via dataclass-like class",
    "version": "1.0.1",
    "project_urls": {
        "Documentation": "https://argclz.readthedocs.io/en/latest/",
        "Homepage": "https://github.com/ytsimon2004/argclz",
        "Issues": "https://github.com/ytsimon2004/argclz/issues",
        "Repository": "https://github.com/ytsimon2004/argclz"
    },
    "split_keywords": [
        "commandline"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e471322856d80b7c92f3e9e56ddba164d34ff96f6c62250e696a20773ddd2067",
                "md5": "dda7377805ceb71c1c103df71cde55e8",
                "sha256": "ba3c39fd9999bedd19d51e7ef5c00e780612f72da2d24502cca710d092b2758a"
            },
            "downloads": -1,
            "filename": "argclz-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dda7377805ceb71c1c103df71cde55e8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 29833,
            "upload_time": "2025-07-10T15:36:43",
            "upload_time_iso_8601": "2025-07-10T15:36:43.302066Z",
            "url": "https://files.pythonhosted.org/packages/e4/71/322856d80b7c92f3e9e56ddba164d34ff96f6c62250e696a20773ddd2067/argclz-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f8b060d6706ed4168c444bcb1c50c60a44c083f6f600c541417ee1c7916855ea",
                "md5": "bf5dbe74da2e2598905ca63bc4c74d6f",
                "sha256": "69fc0ae1bbdca56aaaa13a1e3892225cbb05fc50c89b03456ce3aee1506d9ddc"
            },
            "downloads": -1,
            "filename": "argclz-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "bf5dbe74da2e2598905ca63bc4c74d6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 27806,
            "upload_time": "2025-07-10T15:36:44",
            "upload_time_iso_8601": "2025-07-10T15:36:44.506884Z",
            "url": "https://files.pythonhosted.org/packages/f8/b0/60d6706ed4168c444bcb1c50c60a44c083f6f600c541417ee1c7916855ea/argclz-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-10 15:36:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ytsimon2004",
    "github_project": "argclz",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "argclz"
}
        
Elapsed time: 0.45928s