Skip to main content

Serialize click commands to JSON (compatible with argdump schema)

Project description

clickdump

Serialize Click commands and groups.

Installation

pip install clickdump

Usage

import click
import clickdump

@click.command()
@click.option("-v", "--verbose", count=True, help="Verbosity")
@click.option("--name", default="world", help="Who to greet")
@click.argument("files", nargs=-1)
def cli(name, verbose, files):
    """A simple CLI tool."""

# Serialize to dict
data = clickdump.dump(cli)

# Serialize to JSON string
json_str = clickdump.dumps(cli, indent=2)

Groups and subcommands

@click.group()
@click.option("--debug/--no-debug", default=False)
def cli(debug):
    """A CLI with subcommands."""

@cli.command()
@click.option("--output", "-o", default="out.txt")
@click.argument("src")
def build(output, src):
    """Build the project."""

# Subcommand with parent for full program name
data = clickdump.dump(build, parent=cli)
# -> prog="cli build"

JSON Schema

Output follows the same schema as argdump ($schema: https://niwrap.dev/argdump/schema-v1.json).

Features

  • All Click parameter types: options, arguments, flags, counts, choices, paths, files
  • Nested groups with subparsers (click.Group)
  • Type introspection: builtins, Path, Choice, File, IntRange, FloatRange, DateTime, UUID, Tuple, and callable converters
  • Click-specific extensions: hidden, envvar, prompt, show_default, is_flag, count, multiple, flag_value
  • Program name resolution via parent tree traversal for nested subcommands
  • Mutual exclusion and argument group serialization
  • Environment metadata ($env) for reproducibility

Options

# Exclude environment metadata
clickdump.dump(cmd, include_env=False)

# Exclude hidden options
clickdump.dump(cmd, include_hidden=False)

# Compute full program name from parent group
clickdump.dump(subcmd, parent=root_group)

# Override the root program name
clickdump.dump(subcmd, parent=root_group, prog="mycli")

Limitations

  • This is a serialize-only library (no load/loads equivalent).
  • Lambda and closure type converters cannot be fully serialized and will have serializable: false.
  • Custom click.ParamType subclasses that are not standard built-in types may be marked as unknown.

License

MIT

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

clickdump-0.1.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

clickdump-0.1.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file clickdump-0.1.0.tar.gz.

File metadata

  • Download URL: clickdump-0.1.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clickdump-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1b6d86dfc23ee2c682eedc05a752ee4c2bd51aed4bb8c046728ee7702967987e
MD5 38ed780267307d58bf22e721032a8c3c
BLAKE2b-256 4a0f7a81072a9591d029587864753a2334a24e6331cd985b3553168a1d86c68e

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickdump-0.1.0.tar.gz:

Publisher: publish-pypi.yml on styx-api/clickdump

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clickdump-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: clickdump-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clickdump-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6eb1a28fa4ec6d8e4a609099e6383f6254f5acf9107f9a3362336e7225f0d477
MD5 5314ba59e18d2cafe447af043624cf0f
BLAKE2b-256 43138a3a7ea213cd2a1a50ef57878bb32a48088221b75852ccc0405153fe2cd8

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickdump-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on styx-api/clickdump

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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