Skip to main content

Add your description here

Project description

cli-pydantic

Turn a Pydantic model into a CLI. I dislike every other CLI library so here's yet another one.

  • CLI defined by Pydantic
  • Use multiple YAML / JSON configs with --flag CLI overrides.

Install

pip install cli-pydantic

Usage

# train.py
from pydantic import BaseModel
from cli_pydantic import cli

class Data(BaseModel):
    path: str = "./data"
    splits: list[str] = ["train", "val"]

class Model(BaseModel):
    arch: str = "resnet50"
    lr: float = 1e-3
    layers: list[int] = [64, 128, 256]

class Config(BaseModel):
    data: Data = Data()
    model: Model = Model()
    epochs: int = 10
    verbose: bool = False

cfg = cli(Config, desc="Training pipeline")
# CLI, use default from Pydantic
python train.py --model.arch vit_base --model.lr 3e-4 --epochs 50

# From a config file
python train.py base.yaml

# Layer multiple configs, then override with flags
python train.py base.yaml fast.yaml --model.lr 0.05 --epochs 3

# Lists and booleans
python train.py --model.layers 16,32 --verbose

Semantics:

  • Use --foo bar or --foo=bar
  • For lists: --nums=1,2,3 or --nums 1 --nums=2 --nums 3
  • For bools: --enable / --no-enable
  • Lists will replace previous configs on override -- not append!

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

cli_pydantic-0.2.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

cli_pydantic-0.2.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file cli_pydantic-0.2.0.tar.gz.

File metadata

  • Download URL: cli_pydantic-0.2.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cli_pydantic-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c2f7165d8a23303754d8b96249e807f92f8a552aa34a421afefbad40b45e422c
MD5 2a5d0d7bb179c0b1bedc0705e416e8be
BLAKE2b-256 6c9c87d8f8eb1b701e0621bb9b15ee5015352c7cba85c810c858f9a0c26e9282

See more details on using hashes here.

File details

Details for the file cli_pydantic-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cli_pydantic-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cli_pydantic-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b89b5e66d5728823518c9b9555e94f589125d5d451390f08d6edfb1bc394d94
MD5 7dd86f43ebe48441cd2939e23561049c
BLAKE2b-256 60945330261a3f89c50c273531eac0f1eb0eae468e17c5c57a66d112d16430ae

See more details on using hashes here.

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