Metadata-Version: 2.1
Name: typarse
Version: 3.1
Summary: A simple type-hint-based argument parsing library
Home-page: https://github.com/redtachyon/typarse
Author: RedTachyon
Author-email: ariel.j.kwiatkowski@gmail.com
License: GNU GPLv3
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3.8
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
Provides-Extra: tests
Requires-Dist: pytest ; extra == 'tests'

# Typarse

This is a small project born out of my frustration with simple argument parsing in Python.

Not only do I have to instantiate some object whose name I can never remember, then I get way too many 
function parameters to get them right... It's a mess. And I don't even need half the features.

So this is an attempt at streamlining this process while simultaneously promoting some better type safety, by using the
magic of Python type hints! 

Really all the magic here is happening in the BaseParser class. You just need to subclass it, add a few typed parameters,
perhaps with some extra information in dictionaries... and you're done! For examples, just look at, well, examples.

## Supported types

First 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.


## Simple illustrative example

```python
from typarse import BaseParser
from typing import List


class Parser(BaseParser):
    nums: List[int]
    square: bool
    default: int = 0

    _abbrev = {
        "nums": "n",
        "square": "s",
        "default": "d"
    }

    _help = {
        "nums": "List of numbers to sum",
        "square": "Whether the result should be squared",
        "default": "Initial value, added to the sum"
    }



args = Parser()

print(args.default + sum(args.nums) ** (1+args.square))
```

# Functionality 2: Config

In the spirit of the library, I added a config management component. 
Similarly to parsing, you can define a config using type annotations on a class -- also in a nested manner.

Example:
```python
from typarse import BaseConfig
from typing import List 

class Config(BaseConfig):
    rate: float = 0.1
    amount: float = 0.01
    limit: float = 1.
    class PolicyConfig(BaseConfig):
        layers: List[int] = [32, 32, 32]
        activation: str = "relu"

config = {
    "rate": 0.5,
    "PolicyConfig": {
        "layers": [64, 64]
    }
}

```

