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.2.4.tar.gz (32.6 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.2.4-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dcargs-0.2.4.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.15 CPython/3.10.6 Linux/5.15.0-1017-azure

File hashes

Hashes for dcargs-0.2.4.tar.gz
Algorithm Hash digest
SHA256 b178b66b2420162407e60bfbf26c80e25a4e5bcc76f58571736d35acdcce87c5
MD5 69e5b60e9d83525efd16acadbb8b254f
BLAKE2b-256 49e57ecd61779f1d8a0fc1dbdadaa9b73b895c9748a726821b39241def0ffc9f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dcargs-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5750f896ee12efc7d29eef24f7b311464840e168f21fee4cf0650dc435d523af
MD5 47bc75ff05dbc80006d9990468aef9e0
BLAKE2b-256 a6295e97eeddba162912d4a9d8fb3f2b22296673cd0348b01a37c0b88c17c5d1

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