Skip to main content

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quickparser-0.1.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quickparser-0.1.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quickparser-0.1.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quickparser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c63d373554082a030facc37ef7ba3d148addff95de2081ff670c79c444a7689b
MD5 4eee252b941aabcdcbaed7cb4747fcbd
BLAKE2b-256 0d04f0ffba4c744fa160bcc7cfb0457ab466ced6e2afdce2a48d5eadb7465773

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickparser-0.1.2.tar.gz:

Publisher: manual.publish-pypi.yml on jdraines/quickparser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quickparser-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: quickparser-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for quickparser-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 14ce1550a4b167bbc9f0745a19338e5c933a3d41229f35b2e5a32646409c9266
MD5 f975b04cc3ea5d06198f1022bd3ee3ed
BLAKE2b-256 537516a5aa184aa105e55672e11baebcc766126e6e91dddb2a0b796bc9c277c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for quickparser-0.1.2-py3-none-any.whl:

Publisher: manual.publish-pypi.yml on jdraines/quickparser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page