Utilities for working with configuration files in typer CLIs.
Project description
typer-config
This is a collection of utilities to use configuration files to set parameters for a typer CLI. It is useful for typer commands with many options/arguments so you don't have to constantly rewrite long commands. This package was inspired by phha/click_config_file and prototyped in this issue. It allows you to set values for CLI parameters using a configuration file.
Installation
$ pip install typer-config[all]
Note: that will include libraries for reading from YAML, TOML, and Dotenv files as well. Feel free to leave off the optional dependencies if you don't need those capabilities.
Usage
# Long commands like this:
$ my-typer-app --opt1 foo --opt2 bar arg1 arg2
# Can become this:
$ my-typer-app --config config.yml
Quickstart
You can use a decorator to quickly add a configuration parameter to your typer
application:
import typer
from typer_config import use_yaml_config
app = typer.Typer()
@app.command()
@use_yaml_config() # MUST BE AFTER @app.command()
def main(...):
...
if __name__ == "__main__":
app()
Your typer command will now include a --config CONFIG_FILE
option at the command line.
Note: this package also provides
@use_json_config
,@use_toml_config
, and@use_dotenv_config
for those file formats. You can also use your own loader function and the@use_config(loader_func)
decorator.
See the documentation for more examples using typer-config.
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
Hashes for typer_config-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07d3ed62bc750a5fe170c0f0a6ad9f098ae40691f57b842007759bee33aa7116 |
|
MD5 | d095e8765898629eb300f270886b2679 |
|
BLAKE2b-256 | 784e9b12222f6441c3f729e15e32a34da840e76c19626d1326a5cdf05d74f52c |