Overview
Pydantic Settings 2.3, released on June 15, 2024, adds a CLI settings source to load configuration from command-line arguments.
Main Features
CLI source
The new CliSettingsSource automatically generates a CLI argument parser from the Pydantic model.
python
from pydantic_settings import BaseSettings
class AppConfig(BaseSettings):
host: str = 'localhost'
port: int = 8000
debug: bool = False
model_config = {'cli_parse_args': True}
# python app.py --host 0.0.0.0 --port 9000 --debug
config = AppConfig()
print(config.host, config.port)
