Skip to main content

Serialize and deserialize argparse parsers

Project description

argdump

Serialize and deserialize Python argparse parsers.

Installation

pip install argdump
# or
uv add argdump

Usage

import argparse
import argdump

# Create a parser
parser = argparse.ArgumentParser(prog="mytool")
parser.add_argument("input")
parser.add_argument("-v", "--verbose", action="count", default=0)
parser.add_argument("--format", choices=["json", "csv"])

# Serialize
data = argdump.dump(parser)       # dict
json_str = argdump.dumps(parser)  # JSON string

# Deserialize
restored = argdump.load(data)
restored = argdump.loads(json_str)

# Use normally
args = restored.parse_args(["input.txt", "-vvv", "--format", "json"])

JSON Schema

A JSON Schema for validating serialized output is available at docs/schema-v1.json.

Features

  • All standard actions (store, append, count, etc.)
  • Subparsers with aliases and per-command help text
  • Mutual exclusion and argument groups
  • Type converters (builtins, FileType, importable functions)
  • Choices, defaults, metavar, help text
  • Environment metadata ($env) for reproducibility

Options

# Exclude environment metadata
argdump.dump(parser, include_env=False)

# Non-strict mode: skip unresolvable types instead of raising
argdump.load(data, strict=False)

Limitations

Lambdas and closures cannot be serialized. Use strict=False to skip them:

parser.add_argument("--value", type=lambda x: int(x) * 2)

argdump.load(argdump.dump(parser), strict=False)  # type becomes None
argdump.load(argdump.dump(parser), strict=True)   # raises UnresolvableTypeError

A mutually exclusive group nested inside a named argument group is reconstructed as a top-level mutex group: exclusivity is still enforced, but in --help its members appear under the default options heading rather than the named group.

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

argdump-0.1.3.tar.gz (70.7 kB view details)

Uploaded Source

Built Distribution

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

argdump-0.1.3-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file argdump-0.1.3.tar.gz.

File metadata

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

File hashes

Hashes for argdump-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b63f71b10476be30c22c8927b82cf29cfedbbaba841cf236b107724acbc03b93
MD5 498169d86ebcbd3dfa6944da15e28b5b
BLAKE2b-256 a03eda29c64ad69fd0428b3ae227f25b4103f1e10d936743400d3b226b93014a

See more details on using hashes here.

Provenance

The following attestation bundles were made for argdump-0.1.3.tar.gz:

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

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

File details

Details for the file argdump-0.1.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for argdump-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 803c8cb83e325fbcd1091e33ee03de7a8ce3556ddf727e5eb79e1772c63f2f5b
MD5 0cdbfd9256ed7cd14bc47b834098d904
BLAKE2b-256 42383c85141c85d9253f0904a4b2cf9d779ffa4c25cc228cac1c9b7cb912cf9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for argdump-0.1.3-py3-none-any.whl:

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

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