pyinfra.api.output module

Pluggable output formatting for pyinfra.

Provides format_text and echo functions that default to plain-text no-ops, allowing the API layer to work without any CLI dependency. The CLI layer replaces them at startup via set_formatter and set_echo.

pyinfra.api.output.echo(message: Any = None, **kwargs: Any) None

Echo a message. Mirrors click.echo signature.

pyinfra.api.output.format_text(text: str, *args: Any, **kwargs: Any) str

Format text with optional styling (color, bold, etc.).

Mirrors click.style signature. Accepts positional fg argument for compatibility with click.style("text", "red").

pyinfra.api.output.is_output_active() bool

Return True if a non-default echo function has been installed.

pyinfra.api.output.set_echo(func: Callable[[...], None]) None

Replace the default echo function (e.g. with click.echo).

pyinfra.api.output.set_formatter(func: Callable[[...], str]) None

Replace the default formatter (e.g. with click.style).