Strongly typed, zero-effort CLI interfaces
Project description
dcargs
Documentation
•
pip install dcargs
dcargs
is a library for typed CLI interfaces
and configuration objects.
Our core interface, dcargs.cli()
, generates argument parsers from type-annotated
callables: functions, dataclasses, classes, and nested dataclasses and classes.
This can be used as a replacement for argparse
:
with argparse | with dcargs |
"""Sum two numbers from argparse."""
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--a",
type=int,
required=True,
)
parser.add_argument(
"--b",
type=int,
default=3,
)
args = parser.parse_args()
print(args.a + args.b)
|
"""Sum two numbers by calling a
function with dcargs."""
import dcargs
def main(a: int, b: int = 3) -> None:
print(a + b)
dcargs.cli(main)
"""Sum two numbers by instantiating
a dataclass with dcargs."""
from dataclasses import dataclass
import dcargs
@dataclass
class Args:
a: int
b: int = 3
args = dcargs.cli(Args)
print(args.a + args.b)
|
For more sophisticated examples, see our documentation.
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
dcargs-0.3.6.tar.gz
(49.3 kB
view hashes)
Built Distribution
dcargs-0.3.6-py3-none-any.whl
(57.4 kB
view hashes)