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.21.tar.gz (52.7 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.21-py3-none-any.whl (61.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dcargs-0.3.21.tar.gz
  • Upload date:
  • Size: 52.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.8.14 Linux/5.15.0-1020-azure

File hashes

Hashes for dcargs-0.3.21.tar.gz
Algorithm Hash digest
SHA256 3655855e7bbeea76c3c871d5cec7d1b1c9f689b56a1d767349f1b7fd722b03cf
MD5 bf0dd1ae63d1c38f8280c2a94b89b4de
BLAKE2b-256 f36af924f818b3fef577e815488c5284d71c38a0588a37644170e900a834094f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dcargs-0.3.21-py3-none-any.whl
  • Upload date:
  • Size: 61.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.8.14 Linux/5.15.0-1020-azure

File hashes

Hashes for dcargs-0.3.21-py3-none-any.whl
Algorithm Hash digest
SHA256 7937549b31913791b08cdf3165b9f7832e87161e3849360b59dad6f98041f40e
MD5 c7a3490df2456538c327a6793656aa67
BLAKE2b-256 648929fcaa4e9e0c3b282707b12cbc29745fd3754d0a205656c18a7949a8b17d

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