Skip to main content

pydantic-parse

Pydantic adaptor for argparse

Example

def main():

    class TestChoices(enum.StrEnum):
        alice = "Alice"
        bob = "Bob"

    class TestModel(ArgModel):
        name: TestChoices = ArgField(description="Name")
        some_value: Optional[str] = ArgField(
            description="value",
            optional=True,
            default=None,
            flag=True
        )
        flag: bool = ArgField(description="flag", default=False, flag=True)

    parser = PydanticArgParser()
    parser.add_arguments_from_model(TestModel)
    args = parser.parse_args()

CLI

my-package Alice --some-value 42

Results in vars(args):

{
  'name': <TestChoices.alice: 'Alice'>,
  'some_value': '42',
  'flag': False
}

Or of course

model = TestModel(**vars(args))

gives

TestModel
name=<TestChoices.alice: 'Alice'> some_value='42' flag=False

Made with poetiq

Download files

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

Source Distribution

pydantic_parse-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

pydantic_parse-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydantic_parse-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for pydantic_parse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6743bd9d7d6e682392b38fa4aae5de27afcc4458cb0b7e16e6f8497ce20d204b
MD5 779647a4f2e943d871684a22edc7b397
BLAKE2b-256 5eedd43469d96e2eedf74c08c12630031e31ee8e510e42b55650c4f6d87cc75e

See more details on using hashes here.

File details

Details for the file pydantic_parse-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_parse-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for pydantic_parse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5dbcf90ba0492fa0d9873b264ec0a177e8df9278d53b523120ddfb8d590c5d86
MD5 e81a627050c36b3055d6f22fdd4a66a9
BLAKE2b-256 2be491761d6f4653b8e0e02551767523c9009b0ba9596b71e8ddbe915b2c99ce

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page