No project description provided
Project description
pydargs
Pydargs converts a dataclass to command line arguments in argparse.
Installation
Pydargs can be installed with your favourite package manager. For example:
pip install pydargs
Usage
A minimal usage example would be:
from dataclasses import dataclass
from pydargs import parse
@dataclass
class Config:
number: int
some_string: str = "abc"
if __name__ == "__main__":
config = parse(Config)
After which this entrypoint can be called with
entrypoint --number 42
or
entrypoint --number 42 --some-string abcd
Supported Types
The base types are supported: int
, float
, str
, bool
, as well as:
- Enums or literals comprised of those types.
- Date and datetime, with an optional
date_format
metadata field:your_date: date = field(metadata=dict(date_format="%m-%d-%Y"))
. When not provided dates in ISO 8601 format are accepted. - Lists of those types, either denoted as e.g.
list[int]
ortyping.Sequence[int]
. Multiple arguments to anumbers: list[int]
field can be provided as--numbers 1 2 3
. - Optional types, denoted as e.g.
typing.Optional[int]
orint | None
(for Python 3.10 and above). Any argument passed is assumed to be of the provided type and can never beNone
. - Unions of types, denoted as e.g.
typing.Union[int, str]
orint | str
. Each argument will be parsed into the first type that returns a valid result. Note that this means thatstr | int
will always result in a value of typestr
. - Any other type that can be instantiated from a string, such as
Path
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pydargs-0.3.0.tar.gz
(8.8 kB
view hashes)