Snakemake Storage Plugin Interface

4.4.1 · active · verified Thu Apr 16

This package provides a stable and consistent interface for developers to build custom storage plugins that integrate with Snakemake. It defines the abstract base classes and helper functions necessary for Snakemake to interact with various storage backends. The current version is 4.4.1, with a release cadence of roughly every 1-3 months, primarily focusing on new features, bug fixes, and compatibility with Snakemake core.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core components required to implement a minimal Snakemake storage plugin. You need to define a `StorageObject` (representing a file/directory on your custom storage) and a `StorageProviderBase` (which provides `StorageObject` instances). Finally, register your plugin using `StoragePlugin` to make it discoverable by Snakemake.

from snakemake_interface_storage_plugins.storage_object import StorageObject
from snakemake_interface_storage_plugins.storage_provider import StorageProviderBase
from snakemake_interface_storage_plugins.registry import StoragePlugin
from typing import Optional

# 1. Define your custom StorageObject, implementing required methods
class MyMinimalStorageObject(StorageObject):
    def exists(self) -> bool:
        # Placeholder: In a real plugin, check if the remote object exists.
        return True

    def mtime(self) -> float: return 0.0 # Last modified time
    def size(self) -> int: return 0      # Size in bytes
    def download_obj(self) -> None: pass # Download object to local path
    def upload_obj(self) -> None: pass   # Upload local object to remote
    def list_local_files(self) -> list[str]: return [] # List files in local path
    def cleanup(self) -> None: pass      # Cleanup temporary files

# 2. Define your custom StorageProvider
class MyMinimalStorageProvider(StorageProviderBase):
    def get_storage_object(self, url: str) -> StorageObject:
        # Return an instance of your custom StorageObject for the given URL.
        # 'query' and 'protocol' are typically parsed from the URL.
        return MyMinimalStorageObject(query=None, protocol=self.name, path=url)

    def example_path(self, protocol: Optional[str] = None) -> str:
        # Provide an example path for your protocol (e.g., for documentation).
        return f"{self.name}://path/to/file.txt"

    @property
    def name(self) -> str:
        # The unique name for your storage protocol (e.g., 's3', 'gcs', 'my-minimal').
        return "my-minimal"

# 3. Register your plugin with Snakemake
# This makes your plugin discoverable by Snakemake when it parses Snakefiles.
StoragePlugin(
    name="my-minimal",
    storage_provider=MyMinimalStorageProvider,
    # settings_cls=None # Optionally register a custom settings class
)

print("Minimal Snakemake storage plugin 'my-minimal' defined and registered.")
# To make this plugin active for Snakemake, save this code in a Python file
# (e.g., my_storage_plugin.py) and ensure it's on your PYTHONPATH or installed
# as part of a Snakemake extension package.

view raw JSON →