Registry / observability / snakemake-interface-logger-plugins

snakemake-interface-logger-plugins

JSON →
library2.1.0pypypiunverified

The `snakemake-interface-logger-plugins` library provides the abstract base classes and registry for implementing custom logger plugins for Snakemake. It defines the interface for `LoggerPlugin` and `LoggerWrapper` classes, allowing users to extend Snakemake's logging capabilities. The current version is 2.0.1 and it follows the Snakemake plugin API's release cadence, typically tied to major Snakemake versions.

pip install snakemake-interface-logger-plugins
INSTALL
IMPORT
SIG · SNAKEMAKE-INTERFAC
S
snakemake-interface-logger-plugins
observabilitypythonv2.1.0
Install
6.3s avg
Import
Disk
15MB
Pass rate
6/ 10
Env Coverage6 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✕ build_error
py 3.11
✓ —
✓ 6.66s
py 3.12
✓ —
✓ 6.15s
py 3.13
✓ —
✓ 6.03s
py 3.9
✕ build_error
✕ build_error
15MB installed
● package 15MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LoggerPlugin
from snakemake_interface_logger_plugins import LoggerPlugin
from snakemake_interface_logger_plugins import LoggerPlugin

This quickstart demonstrates how to create a basic Snakemake logger plugin. It defines `MyLoggerPlugin` (the entry point for Snakemake) and `MyLoggerWrapper` (which handles the actual logging messages). It also shows how to register custom command-line arguments and access them via settings. To use, save the code as `my_custom_logger.py` and run Snakemake with `--logger-plugin my_custom_logger.py`.

import os from argparse import ArgumentParser from snakemake_interface_logger_plugins.plugin import LoggerPlugin from snakemake_interface_logger_plugins.wrapper import LoggerWrapper from snakemake_interface_logger_plugins.settings import CommonLoggerSettings # Save this as my_custom_logger.py class MyLoggerPlugin(LoggerPlugin): """A simple custom logger plugin for Snakemake.""" def __init__(self, settings: CommonLoggerSettings | None = None): self.settings = settings def register_args(self, argparser: ArgumentParser): """Register command line arguments for this plugin.""" argparser.add_argument( "--my-logger-prefix", default="[CUSTOM LOG]", help="Prefix for custom logger messages." ) def setup(self): """Perform setup actions before any logging occurs.""" # Access custom args via self.settings if defined # print(f"{self.settings.my_logger_prefix} Initializing MyLoggerPlugin...") pass # For this minimal example, we don't need complex setup def get_wrapper(self) -> LoggerWrapper: """Return an instance of the logger wrapper.""" return MyLoggerWrapper(self.settings) class MyLoggerWrapper(LoggerWrapper): """Handles actual logging events.""" def __init__(self, settings: CommonLoggerSettings | None = None): self.settings = settings def handle_info(self, msg: str): prefix = getattr(self.settings, 'my_logger_prefix', '[MYLOGGER]') print(f"{prefix} INFO: {msg}") def handle_error(self, msg: str): prefix = getattr(self.settings, 'my_logger_prefix', '[MYLOGGER]') print(f"{prefix} ERROR: {msg}") # Implement other handle_* methods as needed for full functionality # e.g., handle_log, handle_job_info, handle_job_error, handle_start, handle_finish, etc. # For this example, we only show info and error. # All abstract methods must be implemented, even if with a 'pass' def handle_log(self, msg: str): prefix = getattr(self.settings, 'my_logger_prefix', '[MYLOGGER]') print(f"{prefix} LOG: {msg}") def handle_start(self): prefix = getattr(self.settings, 'my_logger_prefix', '[MYLOGGER]') print(f"{prefix} Workflow started.") def handle_finish(self): prefix = getattr(self.settings, 'my_logger_prefix', '[MYLOGGER]') print(f"{prefix} Workflow finished.") def handle_job_info(self, job_info: dict): prefix = getattr(self.settings, 'my_logger_prefix', '[MYLOGGER]') print(f"{prefix} Job info: {job_info.get('jobid')} - {job_info.get('output')}") def handle_job_error(self, job_info: dict): prefix = getattr(self.settings, 'my_logger_prefix', '[MYLOGGER]') print(f"{prefix} Job error: {job_info.get('jobid')} - {job_info.get('output')}") # To run this with Snakemake, save it as `my_custom_logger.py` and then run: # snakemake --snakefile Snakefile --logger-plugin my_custom_logger.py --my-logger-prefix "[SNAKEMAKE-CUSTOM]" -c1 # (Requires a simple Snakefile, e.g., 'rule all: run: print("Hello from Snakemake")')
Debug
Known issues
breakingThe logger plugin API underwent a significant redesign with Snakemake 8.0. Versions of `snakemake-interface-logger-plugins` prior to 2.0.0 (e.g., 1.x) are not compatible with Snakemake 8.0+.
fix
Upgrade `snakemake-interface-logger-plugins` to version 2.0.0 or higher to match Snakemake 8.0+ requirements. If targeting older Snakemake versions, pin `snakemake-interface-logger-plugins` to a compatible 1.x version.
affects: <2.0.0
gotchaSnakemake's plugin discovery requires the `--logger-plugin` argument to point to a valid Python file (e.g., `my_plugin.py`) or a discoverable Python module (e.g., `my_package.my_module`). Incorrect paths or non-discoverable modules will prevent the plugin from loading.
fix
Ensure the path provided to `--logger-plugin` is correct and the Python file/module is accessible from where Snakemake is run. For packages, ensure the plugin module is importable and that it contains a class named `LoggerPlugin`.
affects: All
gotchaWhen implementing `LoggerPlugin` or `LoggerWrapper`, you must implement all abstract methods defined in the interface. Failing to do so will result in `TypeError` when attempting to instantiate your plugin.
fix
Refer to the `LoggerPlugin` and `LoggerWrapper` base classes for the full list of abstract methods (e.g., `handle_info`, `handle_error`, `handle_job_info`, `setup`, `register_args`, `get_wrapper`). Implement all of them, even if with a `pass` statement, if no specific action is needed.
affects: All
Upgrade
Version history
2.1.0latest on PyPI · released May 20, 2026
Audit
Dependencies
pluggyrequiredUsed internally for the plugin system.
snakemakerequiredThis library provides an interface for Snakemake; it cannot be used standalone.
Agent activity
29 hits · last 30 days
node
24
OpenAI (training)
1
Resources