stactask


Namestactask JSON
Version 0.4.2 PyPI version JSON
download
home_page
SummaryClass interface for running custom algorithms and workflows on STAC Items
upload_time2024-03-08 14:18:27
maintainer
docs_urlNone
author
requires_python>=3.8
licenseApache-2.0
keywords pystac imagery raster catalog stac
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # STAC Task (stactask)

This Python library consists of the Task class, which is used to create custom tasks based
on a "STAC In, STAC Out" approach. The Task class acts as wrapper around custom code and provides
several convenience methods for modifying STAC Items, creating derived Items, and providing a CLI.

This library is based on a [branch of cirrus-lib](https://github.com/cirrus-geo/cirrus-lib/tree/features/task-class) except aims to be more generic.

## Quickstart for Creating New Tasks

```python
from typing import Any, Dict, List

from stactask import Task

class MyTask(Task):
    name = "my-task"
    description = "this task does it all"

    def validate(self, payload: Dict[str, Any]) -> bool:
        return len(self.items) == 1

    def process(self, **kwargs: Any) -> List[Dict[str, Any]]:
        item = self.items[0]

        # download a datafile
        item = self.download_item_assets(item, assets=['data'])

        # operate on the local file to create a new asset
        item = self.upload_item_assets_to_s3(item)

        # this task returns a single item
        return [item.to_dict(include_self_link=True, transform_hrefs=False)]
```

## Task Input

| Field Name    | Type | Description |
| ------------- | ---- | ----------- |
| type          | string | Must be FeatureCollection |
| features      | [Item] | A list of STAC `Item` |
| process       | ProcessDefinition | A Process Definition |

### ProcessDefinition Object

A STAC task can be provided additional configuration via the 'process' field in the input
ItemCollection.

| Field Name    | Type | Description |
| ------------- | ---- | ----------- |
| description | string | Optional description of the process configuration |
| upload_options | UploadOptions | Options used when uploading assets to a remote server |
| tasks       | Map<str, Map> | Dictionary of task configurations. A List of [task configurations](#taskconfig-object) is supported for backwards compatibility reasons, but a dictionary should be preferred. |

#### UploadOptions Object

| Field Name    | Type | Description |
| ------------- | ---- | ----------- |
| path_template | string | **REQUIRED** A string template for specifying the location of uploaded assets |
| public_assets | [str] | A list of asset keys that should be marked as public when uploaded |
| headers | Map<str, str> | A set of key, value headers to send when uploading data to s3 |
| collections   | Map<str, str> | A mapping of output collection name to a JSONPath pattern (for matching Items) |
| s3_urls | bool | Controls if the final published URLs should be an s3 (s3://*bucket*/*key*) or https URL |

##### path_template

The path_template string is a way to control the output location of uploaded assets from a STAC Item using metadata from the Item itself.
The template can contain fixed strings along with variables used for substitution.
See [the PySTAC documentation for `LayoutTemplate`](https://pystac.readthedocs.io/en/stable/api/layout.html#pystac.layout.LayoutTemplate) for a list of supported template variables and their meaning.

##### collections

The collections dictionary provides a collection ID and JSONPath pattern for matching against STAC Items.
At the end of processing, before the final STAC Items are returned, the Task class can be used to assign
all of the Items to specific collection IDs. For each Item the JSONPath pattern for all collections will be
compared. The first match will cause the Item's Collection ID to be set to the provided value.

For example:

```json
"collections": {
    "landsat-c2l2": "$[?(@.id =~ 'LC08.*')]"
}
```

In this example, the task will set any STAC Items that have an ID beginning with "LC08" to the `landsat-c2l2` collection.

See [Jayway JsonPath Evaluator](https://jsonpath.herokuapp.com/) to experiment with JSONpath and [regex101](https://regex101.com/) to experiment with regex.

#### tasks

The tasks field is a dictionary with an optional key for each task. If present, it contains
a dictionary that is converted to a set of keywords and passed to the Task's `process` function.
The documentation for each task will provide the list of available parameters.

```json
{
    "tasks": {
        "task-a": {
            "param1": "value1"
        },
        "task-c": {
            "param2": "value2"
        }
    }
}
```

In the example above a task named `task-a` would have the `param1=value1` passed as a keyword, while `task-c`
would have `param2=value2` passed. If there were a `task-b` to be run it would not be passed any keywords.

#### TaskConfig Object

**DEPRECATED**: `tasks` should be a dictionary of parameters, with task names as keys. See [tasks](#tasks) for more information.

A Task Configuration contains information for running a specific task.

| Field Name    | Type | Description |
| ------------- | ---- | ----------- |
| name          | str  | **REQUIRED** Name of the task |
| parameters    | Map<str, str> | Dictionary of keyword parameters that will be passed to the Tasks `process` function |

## Full Process Definition Example

Process definitions are sometimes called "Payloads":

```json
{
    "description": "My process configuration",
    "collections": {
        "landsat-c2l2": "$[?(@.id =~ 'LC08.*')]"
    },
    "upload_options": {
        "path_template": "s3://my-bucket/${collection}/${year}/${month}/${day}/${id}"
    },
    "tasks": {
        "task-name": {
            "param": "value"
        }
    }
}
```

## Development

Clone, install in editable mode with development requirements, and install the **pre-commit** hooks:

```shell
git clone https://github.com/stac-utils/stac-task
cd stac-task
pip install -e '.[dev]'
pre-commit install
```

To run the tests:

```shell
pytest
```

To lint all the files:

```shell
pre-commit run --all-files
```

## Contributing

Use Github [issues](https://github.com/stac-utils/stac-task/issues) and [pull requests](https://github.com/stac-utils/stac-task/pulls).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "stactask",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Pete Gadomski <pete.gadomski@gmail.com>",
    "keywords": "pystac,imagery,raster,catalog,STAC",
    "author": "",
    "author_email": "Matthew Hanson <matt.a.hanson@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a6/74/451ad643873a10898480f6a15e03b7f46eeb9b8147965af9fcf0292fcda5/stactask-0.4.2.tar.gz",
    "platform": null,
    "description": "# STAC Task (stactask)\n\nThis Python library consists of the Task class, which is used to create custom tasks based\non a \"STAC In, STAC Out\" approach. The Task class acts as wrapper around custom code and provides\nseveral convenience methods for modifying STAC Items, creating derived Items, and providing a CLI.\n\nThis library is based on a [branch of cirrus-lib](https://github.com/cirrus-geo/cirrus-lib/tree/features/task-class) except aims to be more generic.\n\n## Quickstart for Creating New Tasks\n\n```python\nfrom typing import Any, Dict, List\n\nfrom stactask import Task\n\nclass MyTask(Task):\n    name = \"my-task\"\n    description = \"this task does it all\"\n\n    def validate(self, payload: Dict[str, Any]) -> bool:\n        return len(self.items) == 1\n\n    def process(self, **kwargs: Any) -> List[Dict[str, Any]]:\n        item = self.items[0]\n\n        # download a datafile\n        item = self.download_item_assets(item, assets=['data'])\n\n        # operate on the local file to create a new asset\n        item = self.upload_item_assets_to_s3(item)\n\n        # this task returns a single item\n        return [item.to_dict(include_self_link=True, transform_hrefs=False)]\n```\n\n## Task Input\n\n| Field Name    | Type | Description |\n| ------------- | ---- | ----------- |\n| type          | string | Must be FeatureCollection |\n| features      | [Item] | A list of STAC `Item` |\n| process       | ProcessDefinition | A Process Definition |\n\n### ProcessDefinition Object\n\nA STAC task can be provided additional configuration via the 'process' field in the input\nItemCollection.\n\n| Field Name    | Type | Description |\n| ------------- | ---- | ----------- |\n| description | string | Optional description of the process configuration |\n| upload_options | UploadOptions | Options used when uploading assets to a remote server |\n| tasks       | Map<str, Map> | Dictionary of task configurations. A List of [task configurations](#taskconfig-object) is supported for backwards compatibility reasons, but a dictionary should be preferred. |\n\n#### UploadOptions Object\n\n| Field Name    | Type | Description |\n| ------------- | ---- | ----------- |\n| path_template | string | **REQUIRED** A string template for specifying the location of uploaded assets |\n| public_assets | [str] | A list of asset keys that should be marked as public when uploaded |\n| headers | Map<str, str> | A set of key, value headers to send when uploading data to s3 |\n| collections   | Map<str, str> | A mapping of output collection name to a JSONPath pattern (for matching Items) |\n| s3_urls | bool | Controls if the final published URLs should be an s3 (s3://*bucket*/*key*) or https URL |\n\n##### path_template\n\nThe path_template string is a way to control the output location of uploaded assets from a STAC Item using metadata from the Item itself.\nThe template can contain fixed strings along with variables used for substitution.\nSee [the PySTAC documentation for `LayoutTemplate`](https://pystac.readthedocs.io/en/stable/api/layout.html#pystac.layout.LayoutTemplate) for a list of supported template variables and their meaning.\n\n##### collections\n\nThe collections dictionary provides a collection ID and JSONPath pattern for matching against STAC Items.\nAt the end of processing, before the final STAC Items are returned, the Task class can be used to assign\nall of the Items to specific collection IDs. For each Item the JSONPath pattern for all collections will be\ncompared. The first match will cause the Item's Collection ID to be set to the provided value.\n\nFor example:\n\n```json\n\"collections\": {\n    \"landsat-c2l2\": \"$[?(@.id =~ 'LC08.*')]\"\n}\n```\n\nIn this example, the task will set any STAC Items that have an ID beginning with \"LC08\" to the `landsat-c2l2` collection.\n\nSee [Jayway JsonPath Evaluator](https://jsonpath.herokuapp.com/) to experiment with JSONpath and [regex101](https://regex101.com/) to experiment with regex.\n\n#### tasks\n\nThe tasks field is a dictionary with an optional key for each task. If present, it contains\na dictionary that is converted to a set of keywords and passed to the Task's `process` function.\nThe documentation for each task will provide the list of available parameters.\n\n```json\n{\n    \"tasks\": {\n        \"task-a\": {\n            \"param1\": \"value1\"\n        },\n        \"task-c\": {\n            \"param2\": \"value2\"\n        }\n    }\n}\n```\n\nIn the example above a task named `task-a` would have the `param1=value1` passed as a keyword, while `task-c`\nwould have `param2=value2` passed. If there were a `task-b` to be run it would not be passed any keywords.\n\n#### TaskConfig Object\n\n**DEPRECATED**: `tasks` should be a dictionary of parameters, with task names as keys. See [tasks](#tasks) for more information.\n\nA Task Configuration contains information for running a specific task.\n\n| Field Name    | Type | Description |\n| ------------- | ---- | ----------- |\n| name          | str  | **REQUIRED** Name of the task |\n| parameters    | Map<str, str> | Dictionary of keyword parameters that will be passed to the Tasks `process` function |\n\n## Full Process Definition Example\n\nProcess definitions are sometimes called \"Payloads\":\n\n```json\n{\n    \"description\": \"My process configuration\",\n    \"collections\": {\n        \"landsat-c2l2\": \"$[?(@.id =~ 'LC08.*')]\"\n    },\n    \"upload_options\": {\n        \"path_template\": \"s3://my-bucket/${collection}/${year}/${month}/${day}/${id}\"\n    },\n    \"tasks\": {\n        \"task-name\": {\n            \"param\": \"value\"\n        }\n    }\n}\n```\n\n## Development\n\nClone, install in editable mode with development requirements, and install the **pre-commit** hooks:\n\n```shell\ngit clone https://github.com/stac-utils/stac-task\ncd stac-task\npip install -e '.[dev]'\npre-commit install\n```\n\nTo run the tests:\n\n```shell\npytest\n```\n\nTo lint all the files:\n\n```shell\npre-commit run --all-files\n```\n\n## Contributing\n\nUse Github [issues](https://github.com/stac-utils/stac-task/issues) and [pull requests](https://github.com/stac-utils/stac-task/pulls).\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Class interface for running custom algorithms and workflows on STAC Items",
    "version": "0.4.2",
    "project_urls": {
        "Changelog": "https://github.com/stac-utils/stac-task/blob/main/CHANGELOG.md",
        "Github": "https://github.com/stac-utils/stac-task",
        "Issues": "https://github.com/stac-utils/stactask/issues"
    },
    "split_keywords": [
        "pystac",
        "imagery",
        "raster",
        "catalog",
        "stac"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "949a284bc8f10bf01792bfcc4259abf08d93cfa60801b655e4934ed7faddf64d",
                "md5": "b8ef0507e0121e7bd518c0b4a3e565e6",
                "sha256": "4a847ac82b5b7c8cac96fe48ecfd9d9cbc4af5fd33e4a6eb935126e76c040cad"
            },
            "downloads": -1,
            "filename": "stactask-0.4.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b8ef0507e0121e7bd518c0b4a3e565e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16440,
            "upload_time": "2024-03-08T14:18:25",
            "upload_time_iso_8601": "2024-03-08T14:18:25.877691Z",
            "url": "https://files.pythonhosted.org/packages/94/9a/284bc8f10bf01792bfcc4259abf08d93cfa60801b655e4934ed7faddf64d/stactask-0.4.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a674451ad643873a10898480f6a15e03b7f46eeb9b8147965af9fcf0292fcda5",
                "md5": "0716362c770c2a7e716967390ee7dadc",
                "sha256": "ede0aa92805182ae3291fca7a709c955d4151a1f42a27663d5f52db4e378b269"
            },
            "downloads": -1,
            "filename": "stactask-0.4.2.tar.gz",
            "has_sig": false,
            "md5_digest": "0716362c770c2a7e716967390ee7dadc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 19518,
            "upload_time": "2024-03-08T14:18:27",
            "upload_time_iso_8601": "2024-03-08T14:18:27.233257Z",
            "url": "https://files.pythonhosted.org/packages/a6/74/451ad643873a10898480f6a15e03b7f46eeb9b8147965af9fcf0292fcda5/stactask-0.4.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-08 14:18:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stac-utils",
    "github_project": "stac-task",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "stactask"
}
        
Elapsed time: 0.20195s