Skip to main content

``argparse_dataclass``

Project description

Declarative CLIs with argparse and dataclasses.

Features

Features marked with a ✓ are currently implemented; features marked with a ⊘ are not yet implemented.

  • [✓] Boolean flags

  • [✓] Integer, string, float, and other simple types as arguments

  • [✓] Default values

  • [⊘] Arguments with a finite set of choices

  • [⊘] Subcommands

  • [⊘] Mutually exclusive groups

Examples

A simple parser with flags:

>>> from dataclasses import dataclass
>>> from argparse_dataclass import ArgumentParser
>>> @dataclass
... class Options:
...     verbose: bool
...     other_flag: bool
...
>>> parser = ArgumentParser(Options)
>>> print(parser.parse_args([]))
Options(verbose=False, other_flag=False)
>>> print(parser.parse_args(["--verbose", "--other-flag"]))
Options(verbose=True, other_flag=True)

Using defaults:

>>> from dataclasses import dataclass, field
>>> from argparse_dataclass import ArgumentParser
>>> @dataclass
... class Options:
...     x: int = 1
...     y: int = field(default=2)
...     z: float = field(default_factory=lambda: 3.14)
...
>>> parser = ArgumentParser(Options)
>>> print(parser.parse_args([]))
Options(x=1, y=2, z=3.14)

License

MIT License

Copyright (c) 2019 Michael V. DePalatis

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

argparse_dataclass-0.1.dev1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

argparse_dataclass-0.1.dev1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file argparse_dataclass-0.1.dev1.tar.gz.

File metadata

  • Download URL: argparse_dataclass-0.1.dev1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for argparse_dataclass-0.1.dev1.tar.gz
Algorithm Hash digest
SHA256 e1230e43927e0250a452c3ea45166214bbbea9ebc2885c33c47fde81507875ba
MD5 ae3c66de058edd4d8a4e7f40f69af369
BLAKE2b-256 e1ef0cd4f2be0c97dd3832aa1552b9423a096a89956dc751ff0c112a70d7c860

See more details on using hashes here.

File details

Details for the file argparse_dataclass-0.1.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for argparse_dataclass-0.1.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c451bfc274461f76de0bbe80a2b09fe00009cd29cd98b26e27715f3b72df456
MD5 3af9524fef0100eb9783ff6e155445c5
BLAKE2b-256 8804864b0e187b53d66bf3d03c68d912278abe2152a57cb0d6a77ebf9640eb6e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page