Skip to main content

Serialize and deserialize argparse parsers

Project description

argdump

Serialize and deserialize Python argparse parsers.

Installation

pip install 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
  • 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

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.1.tar.gz (63.1 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.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for argdump-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ffd64d610e04e13c4749acb54364a1ea02495770eada81036cb1923fd3dec0dc
MD5 6ffcf89483c52211f45606b2120ecb4a
BLAKE2b-256 19c356dfdd51b906ebb75b84513eed73bbb2ddf755800cdb6659caa241eeab27

See more details on using hashes here.

Provenance

The following attestation bundles were made for argdump-0.1.1.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.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for argdump-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ffcad18b0caacc006701c769805cac67a48d306e47cb8647055b63835a1bd629
MD5 0f3fdcbeed62f201472caa3827c43f84
BLAKE2b-256 2f82b668e81808c1b0ad819d7cc64e01ddf537e1330f7a03f3260b9272bdd7ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for argdump-0.1.1-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