Skip to main content

Strongly typed, zero-effort CLI interfaces

Project description

dcargs

Documentation   •   pip install dcargs

build mypy lint codecov codecov

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


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.2.tar.gz (48.0 kB view details)

Uploaded Source

Built Distribution

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

dcargs-0.3.2-py3-none-any.whl (55.9 kB view details)

Uploaded Python 3

File details

Details for the file dcargs-0.3.2.tar.gz.

File metadata

  • Download URL: dcargs-0.3.2.tar.gz
  • Upload date:
  • Size: 48.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Linux/5.15.0-1019-azure

File hashes

Hashes for dcargs-0.3.2.tar.gz
Algorithm Hash digest
SHA256 0a8fc9f898788f6a7572258648a4a75e3e0bdca677b9941a22644acbf6d750c4
MD5 60344b63959793d04ee0b413a6e3bf1d
BLAKE2b-256 1da4ad975a9826ccdb071916a4f9c9091ffcae4c68b8b7095162ca94ffa9fb9f

See more details on using hashes here.

File details

Details for the file dcargs-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: dcargs-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 55.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Linux/5.15.0-1019-azure

File hashes

Hashes for dcargs-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 34bfa4d97007a64b7b885ec64606885d7bdeb36dbd12e8f0aee22838f837e0ce
MD5 8e79f50291ab4d45f1025d4516a0166a
BLAKE2b-256 0de1ced7ef1b9916e865d3f547d39374755c4ac2fe7401fc0f5a1c06e5dfc434

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