Snakemake Interface Common

1.23.0 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates how a Snakemake plugin's common settings class would inherit from `CommonSettingsBase` provided by `snakemake-interface-common`. It shows how to define configuration parameters, including those that might be sensitive and loaded from environment variables, establishing a standardized interface for plugin configuration.

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.

view raw JSON →