Skip to content

Optional Dependencies and Logging Abstraction #79

@plutopulp

Description

@plutopulp

Summary

Consider making typer, rich, loguru etc.. optional dependencies, and provide an abstract logger interface so users can inject their own logging implementation.

Motivation

Currently, all dependencies are required even for library-only usage:

  • CLI deps (typer, rich): not needed if using rheo as a library
  • Logging (loguru): users may prefer stdlib logging, structlog, or their own setup
  • Dependency conflicts: version pinning can clash with user's stack
  • Install size: unnecessary bloat for minimal use cases

Proposed Changes

1. Package Extras

Split optional dependencies into install extras:

pip install rheo          # Core only (aiohttp, pydantic)
pip install rheo[cli]     # Adds typer, rich
pip install rheo[loguru]  # Adds loguru integration
pip install rheo[all]     # Everything

2. Logger Abstraction

Introduce a Logger interface (ABC or Protocol) with adapters:

  • StdlibLogger: always available, uses Python's logging module
  • LoguruLogger: requires rheo[loguru], wraps loguru
  • NullLogger: no-op for silent operation or testing

Users can also implement the interface for custom backends (structlog, etc.).

3. Auto-Detection with Fallback

Default behaviour:

  1. If loguru is installed → use LoguruLogger
  2. Otherwise → use StdlibLogger
  3. Users can always inject their own logger explicitly

4. CLI Guard

The CLI entry point checks for dependencies and provides a clear error message if missing:

Error: CLI dependencies not installed.
Install with: pip install rheo[cli]

User-Facing API

# Default (auto-detects available backend)
manager = DownloadManager()

# Explicit stdlib
from rheo.adapters.stdlib_logger import StdlibLogger
manager = DownloadManager(logger=StdlibLogger())

# Custom implementation
from rheo.ports.logger import Logger

class MyLogger(Logger):
    def info(self, msg: str, **context) -> None:
        ...

manager = DownloadManager(logger=MyLogger())

# Silent operation
from rheo.adapters.null_logger import NullLogger
manager = DownloadManager(logger=NullLogger())

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions