Make rich an optional dependency of logfire-sdk

Merged
SA
3d ago
+315-114

Summary

Make rich an optional dependency of logfire-sdk, available with pip install 'logfire-sdk[rich]'. The logfire compatibility package still installs rich through that extra, so pip install logfire keeps its existing behavior.

When rich is absent, the SDK's console exporter prints plain text, and the project URL summary prints without styling. Requesting colors='always' emits a warning that the output cannot be colored. The Python CLI (python -m logfire) raises an ImportError with installation guidance before importing CLI modules that require rich.

Rich output and its plain-text fallbacks live in logfire/_internal/maybe_rich.py. The current main branch already exposes logfire_info from _internal/logfire_info.py, so importing the SDK does not load the CLI.

Verification

  • tests/test_rich_optional.py checks the fallbacks with rich unavailable, including a fresh-process import and logging check.
  • Focused CLI, console exporter, and Logfire info tests: 223 passed.
  • Ruff, Ruff Format, and Pyright commit hooks passed.