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.2.tar.gz (67.8 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.2-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: argdump-0.1.2.tar.gz
  • Upload date:
  • Size: 67.8 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.2.tar.gz
Algorithm Hash digest
SHA256 82f9dfb82034314bcdb27734eb50eac487fe3edab9bd3732c9f3e6820c8daa82
MD5 d5ef730c5ceaa87e393fe5201cd7a56b
BLAKE2b-256 dda8362c5c455e99b645e385a5853411764090fb68e8edf75add9891c768d345

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: argdump-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ae62a65b15d8f432ac3b2561f06fbd2b3932e2ea7e4ccbf9904e22dd3235386c
MD5 37e4dfd430b41f0b594b7d2a53e1729c
BLAKE2b-256 f2ab4952878a36ca22b1f004484b493e5f7966604f3189d38e955e4fecff505d

See more details on using hashes here.

Provenance

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