{"id":6479,"library":"typer-config","title":"Typer-Config","description":"Typer-Config is a collection of utilities that enable Typer CLI applications to utilize configuration files for setting command parameters. This is particularly useful for CLIs with numerous options and arguments, reducing the need to repeatedly type long commands. It supports various formats including YAML, JSON, TOML, and Dotenv. The current version is 1.5.1, and it typically follows the release cadence of its dependencies or as new features/fixes are required.","status":"active","version":"1.5.1","language":"en","source_language":"en","source_url":"https://github.com/maxb2/typer-config","tags":["CLI","Typer","configuration","YAML","JSON","TOML","dotenv"],"install":[{"cmd":"pip install typer-config","lang":"bash","label":"Base installation"},{"cmd":"pip install typer-config[all]","lang":"bash","label":"With all optional dependencies (YAML, TOML, Dotenv)"},{"cmd":"pip install typer-config[yaml]","lang":"bash","label":"With YAML support"},{"cmd":"pip install typer-config[toml]","lang":"bash","label":"With TOML support"},{"cmd":"pip install typer-config[dotenv]","lang":"bash","label":"With Dotenv support"}],"dependencies":[{"reason":"Core dependency as typer-config extends Typer CLI functionality.","package":"typer"},{"reason":"Required for YAML configuration file support.","package":"PyYAML","optional":true},{"reason":"Required for TOML configuration file support.","package":"toml","optional":true},{"reason":"Required for Dotenv configuration file support.","package":"python-dotenv","optional":true}],"imports":[{"symbol":"use_yaml_config","correct":"from typer_config import use_yaml_config"},{"symbol":"use_json_config","correct":"from typer_config import use_json_config"},{"symbol":"use_toml_config","correct":"from typer_config import use_toml_config"},{"symbol":"use_dotenv_config","correct":"from typer_config import use_dotenv_config"},{"symbol":"use_config","correct":"from typer_config import use_config"}],"quickstart":{"code":"import typer\nfrom typer_config import use_yaml_config\nfrom typing import Optional\n\napp = typer.Typer()\n\n@app.command()\n@use_yaml_config()\ndef main(\n    name: str = \"World\",\n    age: Optional[int] = None,\n    config_file: Optional[str] = typer.Option(None, hidden=True) # Added for registry example clarity\n):\n    \"\"\"A simple CLI app using a YAML config file.\"\"\"\n    print(f\"Hello, {name}!\")\n    if age:\n        print(f\"You are {age} years old.\")\n    if config_file:\n        print(f\"Using config file: {config_file}\")\n\nif __name__ == \"__main__\":\n    # Example config.yml content (create this file for testing):\n    # name: Alice\n    # age: 30\n    app()","lang":"python","description":"This quickstart demonstrates how to integrate `typer-config` using the `@use_yaml_config()` decorator. Create a `config.yml` file in the same directory with `name: Alice` and `age: 30`. Run the script with `python your_script.py` or `python your_script.py --config config.yml`. The parameters `name` and `age` will be populated from the config file, which can be overridden by command-line arguments."},"warnings":[{"fix":"Ensure the `@use_yaml_config()` (or similar) decorator is applied beneath `@app.command()`.","message":"When using configuration decorators like `@use_yaml_config()`, they must be placed *after* the `@app.command()` decorator on the function definition. Incorrect placement will prevent the configuration from being loaded and applied correctly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement a conditional check within your custom loader function to return an empty dictionary or handle `None` for the config path gracefully if no file is meant to be loaded.","message":"When providing a custom loader function to `@use_config()`, ensure it gracefully handles cases where no config file path is provided or the file doesn't exist. Otherwise, the CLI might raise an error during `--help` output or when the `--config` option is omitted, leading to a poor user experience.","severity":"gotcha","affected_versions":"All versions, particularly with custom loaders."},{"fix":"Install `typer-config` with the required extras, e.g., `pip install typer-config[yaml]` for YAML support.","message":"Optional dependencies for specific config formats (e.g., `PyYAML` for YAML) are not automatically installed with `pip install typer-config`. If you intend to use a particular format, you must install the corresponding optional dependencies using `pip install typer-config[format_name]` or `typer-config[all]`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}