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.0.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.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: argdump-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d9a2a1274cd23838bf34be0b48b5a844cc646865742466d9b3773fdb3915529b
MD5 e380d024a544521fc34fcf49c86ec15d
BLAKE2b-256 98523efa42e04fc52ac7ef6c4abd186476b02754c80a8a0a999eed8979703b2f

See more details on using hashes here.

Provenance

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

Publisher: publish-pypi.yml on childmindresearch/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.0-py3-none-any.whl.

File metadata

  • Download URL: argdump-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18626d5d5f5816039ae8a3de7e3c83adbffe534f4c4279536253fbf7fb14fa88
MD5 29b2136f073147ee6e5d173b8d7aad6f
BLAKE2b-256 f19741971380aa0a2c66008954eb28a41297de619743c11799167dacc5f7e924

See more details on using hashes here.

Provenance

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

Publisher: publish-pypi.yml on childmindresearch/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