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.4.2.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

typer_config-1.4.2-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typer_config-1.4.2.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0

File hashes

Hashes for typer_config-1.4.2.tar.gz
Algorithm Hash digest
SHA256 69dffc0e06095b57754bfe9fb3e4caf28ab9c2c430dade6433b0ca128510f600
MD5 4e66d7f2445b2590c0663f8e2b232e87
BLAKE2b-256 2eaf78f802bc49eaa5855082cca10e9c9d7d03469c957c149aa159561dc3d744

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typer_config-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0

File hashes

Hashes for typer_config-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b3e1f59bacc8276e5b830f35c9ca403cd85f14173169c23c3756fa816357a34f
MD5 082d1a6afe54f066a027a0f983f8172c
BLAKE2b-256 dfbd2e9d407d7ed3f33a40d8211a481b76a0507ba4f117da9dec116c0de9871e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page