Snakemake Interface Common
Snakemake-interface-common (current version 1.23.0) is a foundational Python package within the Snakemake ecosystem, providing common functions and abstract base classes for Snakemake and its various plugins. It defines stable interfaces that ensure compatibility and facilitate interaction between the main Snakemake workflow management system and extensions such as executor, storage, and logger plugins. The library adheres to semantic versioning to minimize breaking changes for plugin developers.
Warnings
- breaking Snakemake 8 introduced a breaking change by moving 'remote provider functionality' into dedicated 'storage plugins'. Developers maintaining custom remote providers need to migrate their implementations to the new storage plugin interface.
- breaking Snakemake 9 changed how custom loggers are provided, requiring the use of 'logger plugins'. Existing custom logger implementations need to be adapted to conform to the new logger plugin interface.
- gotcha When developing Snakemake plugins, only interact with methods and properties of Snakemake objects that are explicitly defined within the stable interface packages (e.g., `snakemake-interface-common`, `snakemake-interface-executor-plugins`). Accessing internal or undocumented parts of Snakemake objects is not guaranteed to be stable across releases and can lead to unexpected breakages.
- gotcha Snakemake's profile handling (used for configuring plugins) has seen recent changes (e.g., in Snakemake 9.19.0), including defaulting to `profile.yaml` and allowing direct specification of YAML files. Plugin developers should be aware that user-provided configurations might vary based on these new profile mechanisms.
Install
-
pip install snakemake-interface-common
Imports
- CommonSettingsBase
from snakemake_interface_common.settings import CommonSettingsBase
Quickstart
import os
from dataclasses import dataclass, field
from snakemake_interface_common.settings import CommonSettingsBase
@dataclass
class MyPluginCommonSettings(CommonSettingsBase):
"""
A hypothetical plugin's common settings inheriting from CommonSettingsBase.
This demonstrates how shared configuration parameters for a Snakemake plugin
are defined using the interface.
"""
my_plugin_param: str = field(
default="default_plugin_value",
metadata={
"help": "A common setting for MyPlugin."
}
)
# Example of a sensitive setting, typically loaded from an environment variable
api_key: str = field(
default=os.environ.get("MYPLUGIN_API_KEY", ""),
metadata={
"help": "API key for MyPlugin service (from MYPLUGIN_API_KEY env var).",
"env_var": "MYPLUGIN_API_KEY",
"sensitive": True,
},
)
# Instantiate the settings. In a real Snakemake plugin, these would be populated
# from command-line arguments or Snakemake profiles.
settings = MyPluginCommonSettings(my_plugin_param="custom_value_from_profile_or_cli")
print(f"My plugin parameter: {settings.my_plugin_param}")
if settings.api_key:
print("API Key loaded (value not shown for security).")
else:
print("MYPLUGIN_API_KEY environment variable not set.")
# This class is primarily for defining structure; direct executable quickstarts
# are more relevant for full Snakemake plugins.