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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9a2a1274cd23838bf34be0b48b5a844cc646865742466d9b3773fdb3915529b
|
|
| MD5 |
e380d024a544521fc34fcf49c86ec15d
|
|
| BLAKE2b-256 |
98523efa42e04fc52ac7ef6c4abd186476b02754c80a8a0a999eed8979703b2f
|
Provenance
The following attestation bundles were made for argdump-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on childmindresearch/argdump
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
argdump-0.1.0.tar.gz -
Subject digest:
d9a2a1274cd23838bf34be0b48b5a844cc646865742466d9b3773fdb3915529b - Sigstore transparency entry: 816993185
- Sigstore integration time:
-
Permalink:
childmindresearch/argdump@af6df7dde28bb6ab9dd57ffa817003b937c71a3f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/childmindresearch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@af6df7dde28bb6ab9dd57ffa817003b937c71a3f -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18626d5d5f5816039ae8a3de7e3c83adbffe534f4c4279536253fbf7fb14fa88
|
|
| MD5 |
29b2136f073147ee6e5d173b8d7aad6f
|
|
| BLAKE2b-256 |
f19741971380aa0a2c66008954eb28a41297de619743c11799167dacc5f7e924
|
Provenance
The following attestation bundles were made for argdump-0.1.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on childmindresearch/argdump
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
argdump-0.1.0-py3-none-any.whl -
Subject digest:
18626d5d5f5816039ae8a3de7e3c83adbffe534f4c4279536253fbf7fb14fa88 - Sigstore transparency entry: 816993255
- Sigstore integration time:
-
Permalink:
childmindresearch/argdump@af6df7dde28bb6ab9dd57ffa817003b937c71a3f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/childmindresearch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@af6df7dde28bb6ab9dd57ffa817003b937c71a3f -
Trigger Event:
push
-
Statement type: