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.3.tar.gz (49.2 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.3-py3-none-any.whl (57.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dcargs-0.3.3.tar.gz
Algorithm Hash digest
SHA256 d735d6b34a6cd854c6573516550055ed8207de7f52ace50aaef159e1cf2723e8
MD5 d22812cafdb028c0a48b728c8654893d
BLAKE2b-256 0db4ab9204988477273590a19665c0ae82fa651a664f4e0baa3ebc4315679511

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dcargs-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9b3fcec2b541669fa16e02952c4e9fc14dfcf543c67fc551e25b9b3a6aad0bf6
MD5 884663c3c653d8745fa7fd3b23f14413
BLAKE2b-256 2b5cb87051a7b357c0f24c5d3b7504df7ec26fe790df8433375aed14959e2926

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