snakemake-interface-storage-plugins


Namesnakemake-interface-storage-plugins JSON
Version 3.2.4 PyPI version JSON
download
home_pagehttps://github.com/snakemake/snakemake-interface-storage-plugins
SummaryThis package provides a stable interface for interactions between Snakemake and its storage plugins.
upload_time2024-08-14 07:50:49
maintainerNone
docs_urlNone
authorJohannes Koester
requires_python<4.0,>=3.11
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # snakemake-interface-storage-plugins

This package provides a stable interface for interactions between Snakemake and its storage plugins.

Plugins should implement the following skeleton to comply with this interface.
It is recommended to use Snakemake's poetry plugin to set up this skeleton (and automated testing) within a python package, see https://github.com/snakemake/poetry-snakemake-plugin.

```python
from dataclasses import dataclass, field
from typing import Any, Iterable, Optional, List
from snakemake_interface_storage_plugins.settings import StorageProviderSettingsBase
from snakemake_interface_storage_plugins.storage_provider import (
    StorageProviderBase,
    StorageQueryValidationResult,
    ExampleQuery,
    Operation,
)
from snakemake_interface_storage_plugins.storage_object import (
    StorageObjectRead,
    StorageObjectWrite,
    StorageObjectGlob,
    StorageObjectTouch,
    retry_decorator,
)
from snakemake_interface_storage_plugins.io import IOCacheStorageInterface


# Optional:
# Define settings for your storage plugin (e.g. host url, credentials).
# They will occur in the Snakemake CLI as --storage-<storage-plugin-name>-<param-name>
# Make sure that all defined fields are 'Optional' and specify a default value
# of None or anything else that makes sense in your case.
# Note that we allow storage plugin settings to be tagged by the user. That means,
# that each of them can be specified multiple times (an implicit nargs=+), and
# the user can add a tag in front of each value (e.g. tagname1:value1 tagname2:value2).
# This way, a storage plugin can be used multiple times within a workflow with different
# settings.
@dataclass
class StorageProviderSettings(StorageProviderSettingsBase):
    myparam: Optional[int] = field(
        default=None,
        metadata={
            "help": "Some help text",
            # Optionally request that setting is also available for specification
            # via an environment variable. The variable will be named automatically as
            # SNAKEMAKE_<storage-plugin-name>_<param-name>, all upper case.
            # This mechanism should only be used for passwords, usernames, and other
            # credentials.
            # For other items, we rather recommend to let people use a profile
            # for setting defaults
            # (https://snakemake.readthedocs.io/en/stable/executing/cli.html#profiles).
            "env_var": False,
            # Optionally specify a function that parses the value given by the user.
            # This is useful to create complex types from the user input.
            "parse_func": ...,
            # If a parse_func is specified, you also have to specify an unparse_func
            # that converts the parsed value back to a string.
            "unparse_func": ...,
            # Optionally specify that setting is required when the executor is in use.
            "required": True,
        },
    )


# Required:
# Implementation of your storage provider
# This class can be empty as the one below.
# You can however use it to store global information or maintain e.g. a connection
# pool.
class StorageProvider(StorageProviderBase):
    # For compatibility with future changes, you should not overwrite the __init__
    # method. Instead, use __post_init__ to set additional attributes and initialize
    # futher stuff.

    def __post_init__(self):
        # This is optional and can be removed if not needed.
        # Alternatively, you can e.g. prepare a connection to your storage backend here.
        # and set additional attributes.
        pass

    @classmethod
    def example_queries(cls) -> List[ExampleQuery]:
        """Return valid example queries (at least one) with description."""
        ...

    def rate_limiter_key(self, query: str, operation: Operation) -> Any:
        """Return a key for identifying a rate limiter given a query and an operation.

        This is used to identify a rate limiter for the query.
        E.g. for a storage provider like http that would be the host name.
        For s3 it might be just the endpoint URL.
        """
        ...

    def default_max_requests_per_second(self) -> float:
        """Return the default maximum number of requests per second for this storage
        provider."""
        ...

    def use_rate_limiter(self) -> bool:
        """Return False if no rate limiting is needed for this provider."""
        ...

    @classmethod
    def is_valid_query(cls, query: str) -> StorageQueryValidationResult:
        """Return whether the given query is valid for this storage provider."""
        # Ensure that also queries containing wildcards (e.g. {sample}) are accepted
        # and considered valid. The wildcards will be resolved before the storage
        # object is actually used.
        ...


# Required:
# Implementation of storage object. If certain methods cannot be supported by your
# storage (e.g. because it is read-only see
# snakemake-storage-http for comparison), remove the corresponding base classes
# from the list of inherited items.
class StorageObject(
    StorageObjectRead,
    StorageObjectWrite,
    StorageObjectGlob,
    StorageObjectTouch
):
    # For compatibility with future changes, you should not overwrite the __init__
    # method. Instead, use __post_init__ to set additional attributes and initialize
    # futher stuff.

    def __post_init__(self):
        # This is optional and can be removed if not needed.
        # Alternatively, you can e.g. prepare a connection to your storage backend here.
        # and set additional attributes.
        pass

    async def inventory(self, cache: IOCacheStorageInterface):
        """From this file, try to find as much existence and modification date
        information as possible. Only retrieve that information that comes for free
        given the current object.
        """
        # This is optional and can be left as is

        # If this is implemented in a storage object, results have to be stored in
        # the given IOCache object, using self.cache_key() as key.
        # Optionally, this can take a custom local suffix, needed e.g. when you want 
        # to cache more items than the current query: self.cache_key(local_suffix=...)
        pass

    def get_inventory_parent(self) -> Optional[str]:
        """Return the parent directory of this object."""
        # this is optional and can be left as is
        return None

    def local_suffix(self) -> str:
        """Return a unique suffix for the local path, determined from self.query."""
        ...

    def cleanup(self):
        """Perform local cleanup of any remainders of the storage object."""
        # self.local_path() should not be removed, as this is taken care of by
        # Snakemake.
        ...

    # Fallible methods should implement some retry logic.
    # The easiest way to do this (but not the only one) is to use the retry_decorator
    # provided by snakemake-interface-storage-plugins.
    @retry_decorator
    def exists(self) -> bool:
        # return True if the object exists
        ...

    @retry_decorator
    def mtime(self) -> float:
        # return the modification time
        ...

    @retry_decorator
    def size(self) -> int:
        # return the size in bytes
        ...

    @retry_decorator
    def retrieve_object(self):
        # Ensure that the object is accessible locally under self.local_path()
        ...

    # The following two methods are only required if the class inherits from
    # StorageObjectReadWrite.

    @retry_decorator
    def store_object(self):
        # Ensure that the object is stored at the location specified by
        # self.local_path().
        ...

    @retry_decorator
    def remove(self):
        # Remove the object from the storage.
        ...

    # The following method is only required if the class inherits from
    # StorageObjectGlob.

    @retry_decorator
    def list_candidate_matches(self) -> Iterable[str]:
        """Return a list of candidate matches in the storage for the query."""
        # This is used by glob_wildcards() to find matches for wildcards in the query.
        # The method has to return concretized queries without any remaining wildcards.
        # Use snakemake_executor_plugins.io.get_constant_prefix(self.query) to get the
        # prefix of the query before the first wildcard.
        ...

    # The following method is only required if the class inherits from
    # StorageObjectTouch
    @retry_decorator
    def touch(self):
        """Touch the object, updating its modification date."""
        ...
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/snakemake/snakemake-interface-storage-plugins",
    "name": "snakemake-interface-storage-plugins",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": null,
    "author": "Johannes Koester",
    "author_email": "johannes.koester@uni-due.de",
    "download_url": "https://files.pythonhosted.org/packages/a8/04/bf45ccc85ee1cf863f853856d3a74dcd1db5e3b0613315f52bdb5614d128/snakemake_interface_storage_plugins-3.2.4.tar.gz",
    "platform": null,
    "description": "# snakemake-interface-storage-plugins\n\nThis package provides a stable interface for interactions between Snakemake and its storage plugins.\n\nPlugins should implement the following skeleton to comply with this interface.\nIt is recommended to use Snakemake's poetry plugin to set up this skeleton (and automated testing) within a python package, see https://github.com/snakemake/poetry-snakemake-plugin.\n\n```python\nfrom dataclasses import dataclass, field\nfrom typing import Any, Iterable, Optional, List\nfrom snakemake_interface_storage_plugins.settings import StorageProviderSettingsBase\nfrom snakemake_interface_storage_plugins.storage_provider import (\n    StorageProviderBase,\n    StorageQueryValidationResult,\n    ExampleQuery,\n    Operation,\n)\nfrom snakemake_interface_storage_plugins.storage_object import (\n    StorageObjectRead,\n    StorageObjectWrite,\n    StorageObjectGlob,\n    StorageObjectTouch,\n    retry_decorator,\n)\nfrom snakemake_interface_storage_plugins.io import IOCacheStorageInterface\n\n\n# Optional:\n# Define settings for your storage plugin (e.g. host url, credentials).\n# They will occur in the Snakemake CLI as --storage-<storage-plugin-name>-<param-name>\n# Make sure that all defined fields are 'Optional' and specify a default value\n# of None or anything else that makes sense in your case.\n# Note that we allow storage plugin settings to be tagged by the user. That means,\n# that each of them can be specified multiple times (an implicit nargs=+), and\n# the user can add a tag in front of each value (e.g. tagname1:value1 tagname2:value2).\n# This way, a storage plugin can be used multiple times within a workflow with different\n# settings.\n@dataclass\nclass StorageProviderSettings(StorageProviderSettingsBase):\n    myparam: Optional[int] = field(\n        default=None,\n        metadata={\n            \"help\": \"Some help text\",\n            # Optionally request that setting is also available for specification\n            # via an environment variable. The variable will be named automatically as\n            # SNAKEMAKE_<storage-plugin-name>_<param-name>, all upper case.\n            # This mechanism should only be used for passwords, usernames, and other\n            # credentials.\n            # For other items, we rather recommend to let people use a profile\n            # for setting defaults\n            # (https://snakemake.readthedocs.io/en/stable/executing/cli.html#profiles).\n            \"env_var\": False,\n            # Optionally specify a function that parses the value given by the user.\n            # This is useful to create complex types from the user input.\n            \"parse_func\": ...,\n            # If a parse_func is specified, you also have to specify an unparse_func\n            # that converts the parsed value back to a string.\n            \"unparse_func\": ...,\n            # Optionally specify that setting is required when the executor is in use.\n            \"required\": True,\n        },\n    )\n\n\n# Required:\n# Implementation of your storage provider\n# This class can be empty as the one below.\n# You can however use it to store global information or maintain e.g. a connection\n# pool.\nclass StorageProvider(StorageProviderBase):\n    # For compatibility with future changes, you should not overwrite the __init__\n    # method. Instead, use __post_init__ to set additional attributes and initialize\n    # futher stuff.\n\n    def __post_init__(self):\n        # This is optional and can be removed if not needed.\n        # Alternatively, you can e.g. prepare a connection to your storage backend here.\n        # and set additional attributes.\n        pass\n\n    @classmethod\n    def example_queries(cls) -> List[ExampleQuery]:\n        \"\"\"Return valid example queries (at least one) with description.\"\"\"\n        ...\n\n    def rate_limiter_key(self, query: str, operation: Operation) -> Any:\n        \"\"\"Return a key for identifying a rate limiter given a query and an operation.\n\n        This is used to identify a rate limiter for the query.\n        E.g. for a storage provider like http that would be the host name.\n        For s3 it might be just the endpoint URL.\n        \"\"\"\n        ...\n\n    def default_max_requests_per_second(self) -> float:\n        \"\"\"Return the default maximum number of requests per second for this storage\n        provider.\"\"\"\n        ...\n\n    def use_rate_limiter(self) -> bool:\n        \"\"\"Return False if no rate limiting is needed for this provider.\"\"\"\n        ...\n\n    @classmethod\n    def is_valid_query(cls, query: str) -> StorageQueryValidationResult:\n        \"\"\"Return whether the given query is valid for this storage provider.\"\"\"\n        # Ensure that also queries containing wildcards (e.g. {sample}) are accepted\n        # and considered valid. The wildcards will be resolved before the storage\n        # object is actually used.\n        ...\n\n\n# Required:\n# Implementation of storage object. If certain methods cannot be supported by your\n# storage (e.g. because it is read-only see\n# snakemake-storage-http for comparison), remove the corresponding base classes\n# from the list of inherited items.\nclass StorageObject(\n    StorageObjectRead,\n    StorageObjectWrite,\n    StorageObjectGlob,\n    StorageObjectTouch\n):\n    # For compatibility with future changes, you should not overwrite the __init__\n    # method. Instead, use __post_init__ to set additional attributes and initialize\n    # futher stuff.\n\n    def __post_init__(self):\n        # This is optional and can be removed if not needed.\n        # Alternatively, you can e.g. prepare a connection to your storage backend here.\n        # and set additional attributes.\n        pass\n\n    async def inventory(self, cache: IOCacheStorageInterface):\n        \"\"\"From this file, try to find as much existence and modification date\n        information as possible. Only retrieve that information that comes for free\n        given the current object.\n        \"\"\"\n        # This is optional and can be left as is\n\n        # If this is implemented in a storage object, results have to be stored in\n        # the given IOCache object, using self.cache_key() as key.\n        # Optionally, this can take a custom local suffix, needed e.g. when you want \n        # to cache more items than the current query: self.cache_key(local_suffix=...)\n        pass\n\n    def get_inventory_parent(self) -> Optional[str]:\n        \"\"\"Return the parent directory of this object.\"\"\"\n        # this is optional and can be left as is\n        return None\n\n    def local_suffix(self) -> str:\n        \"\"\"Return a unique suffix for the local path, determined from self.query.\"\"\"\n        ...\n\n    def cleanup(self):\n        \"\"\"Perform local cleanup of any remainders of the storage object.\"\"\"\n        # self.local_path() should not be removed, as this is taken care of by\n        # Snakemake.\n        ...\n\n    # Fallible methods should implement some retry logic.\n    # The easiest way to do this (but not the only one) is to use the retry_decorator\n    # provided by snakemake-interface-storage-plugins.\n    @retry_decorator\n    def exists(self) -> bool:\n        # return True if the object exists\n        ...\n\n    @retry_decorator\n    def mtime(self) -> float:\n        # return the modification time\n        ...\n\n    @retry_decorator\n    def size(self) -> int:\n        # return the size in bytes\n        ...\n\n    @retry_decorator\n    def retrieve_object(self):\n        # Ensure that the object is accessible locally under self.local_path()\n        ...\n\n    # The following two methods are only required if the class inherits from\n    # StorageObjectReadWrite.\n\n    @retry_decorator\n    def store_object(self):\n        # Ensure that the object is stored at the location specified by\n        # self.local_path().\n        ...\n\n    @retry_decorator\n    def remove(self):\n        # Remove the object from the storage.\n        ...\n\n    # The following method is only required if the class inherits from\n    # StorageObjectGlob.\n\n    @retry_decorator\n    def list_candidate_matches(self) -> Iterable[str]:\n        \"\"\"Return a list of candidate matches in the storage for the query.\"\"\"\n        # This is used by glob_wildcards() to find matches for wildcards in the query.\n        # The method has to return concretized queries without any remaining wildcards.\n        # Use snakemake_executor_plugins.io.get_constant_prefix(self.query) to get the\n        # prefix of the query before the first wildcard.\n        ...\n\n    # The following method is only required if the class inherits from\n    # StorageObjectTouch\n    @retry_decorator\n    def touch(self):\n        \"\"\"Touch the object, updating its modification date.\"\"\"\n        ...\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This package provides a stable interface for interactions between Snakemake and its storage plugins.",
    "version": "3.2.4",
    "project_urls": {
        "Homepage": "https://github.com/snakemake/snakemake-interface-storage-plugins"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f4a7320ba91d6176d5441a74b7af992187aa01491c58ee593a58e00b2b5e0c29",
                "md5": "45177ed12eaa97a06e717a978e281f5e",
                "sha256": "4cc60329a186486a689ec932fe0d6c538b930f8c33dc21e657a3791b8161fbe9"
            },
            "downloads": -1,
            "filename": "snakemake_interface_storage_plugins-3.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "45177ed12eaa97a06e717a978e281f5e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 14872,
            "upload_time": "2024-08-14T07:50:48",
            "upload_time_iso_8601": "2024-08-14T07:50:48.143751Z",
            "url": "https://files.pythonhosted.org/packages/f4/a7/320ba91d6176d5441a74b7af992187aa01491c58ee593a58e00b2b5e0c29/snakemake_interface_storage_plugins-3.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a804bf45ccc85ee1cf863f853856d3a74dcd1db5e3b0613315f52bdb5614d128",
                "md5": "f534daf385a30b74793d8dd595746a74",
                "sha256": "a44b99339f369703e3cfa5f21f3f513ca2000c8790c364be0e5df7d03fb264d3"
            },
            "downloads": -1,
            "filename": "snakemake_interface_storage_plugins-3.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "f534daf385a30b74793d8dd595746a74",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 11944,
            "upload_time": "2024-08-14T07:50:49",
            "upload_time_iso_8601": "2024-08-14T07:50:49.773663Z",
            "url": "https://files.pythonhosted.org/packages/a8/04/bf45ccc85ee1cf863f853856d3a74dcd1db5e3b0613315f52bdb5614d128/snakemake_interface_storage_plugins-3.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-14 07:50:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "snakemake",
    "github_project": "snakemake-interface-storage-plugins",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "snakemake-interface-storage-plugins"
}
        
Elapsed time: 0.92560s