tyro-based CLI with TOML/YAML config file support for ML
Project description
Pydantic Config
A drop-in replacement for tyro.cli with TOML/YAML/JSON config file support.
# Instead of:
from tyro import cli
# Use:
from pydantic_config import cli
Built on top of tyro for type-safe CLI parsing and Pydantic for validation.
Install
pip install git+https://github.com/samsja/pydantic_config
For TOML support (recommended):
pip install "pydantic_config[toml] @ git+https://github.com/samsja/pydantic_config"
Quick Start
from pydantic_config import cli, BaseConfig
class TrainConfig(BaseConfig):
lr: float = 1e-4
batch_size: int = 32
class ModelConfig(BaseConfig):
hidden_size: int = 256
num_layers: int = 4
class Config(BaseConfig):
train: TrainConfig = TrainConfig()
model: ModelConfig = ModelConfig()
hello: int
if __name__ == "__main__":
config = cli(Config)
Help output
python train.py --help
Missing required argument
python train.py
Config file validation error
python train.py --train @ train_config.toml
Config file not found
python train.py @ nonexistent.toml
Config Files
Load config from TOML/YAML/JSON files using the @ syntax:
# Load config file
python train.py @ config.toml
# Override values from CLI
python train.py @ config.toml --train.lr 0.001
# Load nested configs from separate files
python train.py --model @ model.toml --train @ train.toml
Example config.toml:
[train]
lr = 0.0003
batch_size = 64
[model]
hidden_size = 512
CLI arguments always override config file values.
Development
uv sync --extra all
uv run pytest
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 prime_pydantic_config-0.3.0.dev78.tar.gz.
File metadata
- Download URL: prime_pydantic_config-0.3.0.dev78.tar.gz
- Upload date:
- Size: 45.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e03cb96b1ce743faf822cdc6d95139eb50859f9d52fc84c9127d63631beb6e7
|
|
| MD5 |
6ee305ed7669cae014b5d52c0597a30e
|
|
| BLAKE2b-256 |
78b7ae107f1b8e4a99c20bba6a54fdbfd50af5a35639d524eec5036e6e8f2574
|
File details
Details for the file prime_pydantic_config-0.3.0.dev78-py3-none-any.whl.
File metadata
- Download URL: prime_pydantic_config-0.3.0.dev78-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae5b568955918b200b5eb1ec616b199335252b2326bf5c10d51b20facb8b6ecc
|
|
| MD5 |
295d60ca87a193a381732d4d118349dc
|
|
| BLAKE2b-256 |
096cee4d5478d821a26190405dc9f36543ccf4216a429159c75c82f4ceea153d
|