Skip to main content

Utilities for working with configuration files in typer CLIs.

Project description

typer-config

GitHub Workflow Status (with branch) Codecov PyPI PyPI - Downloads Libraries.io dependency status for latest release

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(foo: FooType):
    ...


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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typer_config-1.0.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

typer_config-1.0.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file typer_config-1.0.1.tar.gz.

File metadata

  • Download URL: typer_config-1.0.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for typer_config-1.0.1.tar.gz
Algorithm Hash digest
SHA256 05c78a364ea8f779f34ccbcb3738c99cb316613903fed103d603f3e21ad2fef6
MD5 5d653ab61a4f18ed5d5b6a6bba776f85
BLAKE2b-256 57490c0d317aa27414ccfb54c4c0b3ca4900a487479841574f49aca8db585bdc

See more details on using hashes here.

File details

Details for the file typer_config-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: typer_config-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.4 Darwin/22.6.0

File hashes

Hashes for typer_config-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2ac4dc02f4cb190186e65c819fce31ecbe9b3ee6fcce4ea2a3764639acf4b5f5
MD5 071212ff783e6021acf50ec3eecb959f
BLAKE2b-256 1fd4e45111b3715fb0b5c0d3ce7f06f84adba8db444239d8e8947c5ba0acae70

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