Create lightweight CLI arg parsers from pydantic models
Project description
Quickparser
Create lightweight CLI arg parsers from pydantic models.
This provides a clean, declarative way to create a command-line interface by allowing you to define the interface using Pydantic models.
For example,
from pydantic import BaseModel, Field
from quickparser import parser
@parser
class SimpleModel(BaseModel):
"""
Example CLI for demonstration.
"""
name: str
age: int = Field(default=30)
hobby: str | None
employed: bool
args = SimpleModel.parse()
Is the equivalent of the following argparse code:
import argparse
parser = argparse.ArgumentParser(description="Example CLI for demonstration.")
parser.add_argument("--name", type=str, required=True)
parser.add_argument("--age", type=int, default=30)
parser.add_argument("--hobby", type=str, default=None)
parser.add_argument("--employed", action="store_true")
args = parser.parse_args()
Installation
pip install quickparser
Usage
We can take the example above and put it into an example.py script to demonstrate the basic usage:
# example.py
from pydantic import BaseModel, Field
from quickparser import parser
@parser
class SimpleModel(BaseModel):
"""
Example CLI for demonstration.
"""
name: str
age: int = Field(default=30)
hobby: str | None
employed: bool
if __name__ == "__main__":
args = SimpleModel.parse()
print(args)
This script can be run from the command line, and it will parse the arguments provided to it. For example:
python example.py --name John --age 25 --hobby "reading" --employed
This will output:
SimpleModel(name='John', age=25, hobby='reading', employed=True)
Built on top of argparse, the parser provided automatically includes a help message,
type casting based on type hints, default values, and required vs optional arguments.
Help can be accessed by running the script with the --help flag:
python example.py --help
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 quickparser-0.1.1.tar.gz.
File metadata
- Download URL: quickparser-0.1.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f133937473dce3ac214a5d579ec68442b8148d40f925f73b103a429c0bfff55
|
|
| MD5 |
6e2c0d519e1f4c04bd78812ab2725e1f
|
|
| BLAKE2b-256 |
a2fd1b39207fbe76d7ca5ce337bd95ad59435268fd62e00793e4eb201f91e9f4
|
Provenance
The following attestation bundles were made for quickparser-0.1.1.tar.gz:
Publisher:
workflow.on-pr-merge.yml on jdraines/quickparser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quickparser-0.1.1.tar.gz -
Subject digest:
1f133937473dce3ac214a5d579ec68442b8148d40f925f73b103a429c0bfff55 - Sigstore transparency entry: 202956314
- Sigstore integration time:
-
Permalink:
jdraines/quickparser@b9cf630747e3dbed02a9f304764895ac782ed8fc -
Branch / Tag:
refs/heads/master - Owner: https://github.com/jdraines
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.on-pr-merge.yml@38199ccf89b5d50552dd68eb1bb129fe0669cae5 -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file quickparser-0.1.1-py3-none-any.whl.
File metadata
- Download URL: quickparser-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
982b6a4af243128127aa409ed127773a0bd6f17f3fa2450bbfa6e4a1c13a0816
|
|
| MD5 |
e43397bd27b9c5e1154c100c039a43f2
|
|
| BLAKE2b-256 |
1709c56c2262bec123f04f664378c5cb5cbe18cbfca834e7e19aba0631a1be09
|
Provenance
The following attestation bundles were made for quickparser-0.1.1-py3-none-any.whl:
Publisher:
workflow.on-pr-merge.yml on jdraines/quickparser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quickparser-0.1.1-py3-none-any.whl -
Subject digest:
982b6a4af243128127aa409ed127773a0bd6f17f3fa2450bbfa6e4a1c13a0816 - Sigstore transparency entry: 202956319
- Sigstore integration time:
-
Permalink:
jdraines/quickparser@b9cf630747e3dbed02a9f304764895ac782ed8fc -
Branch / Tag:
refs/heads/master - Owner: https://github.com/jdraines
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.on-pr-merge.yml@38199ccf89b5d50552dd68eb1bb129fe0669cae5 -
Trigger Event:
pull_request
-
Statement type: