{"id":15022525,"url":"https://github.com/puppetlabs/puppetlabs-python_task_helper","last_synced_at":"2025-10-19T17:30:47.651Z","repository":{"id":49110326,"uuid":"153195865","full_name":"puppetlabs/puppetlabs-python_task_helper","owner":"puppetlabs","description":"A helper library for Puppet Tasks written in Python","archived":false,"fork":false,"pushed_at":"2024-12-19T10:44:33.000Z","size":54,"stargazers_count":4,"open_issues_count":0,"forks_count":8,"subscribers_count":83,"default_branch":"main","last_synced_at":"2025-01-30T17:34:24.378Z","etag":null,"topics":["module","supported"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/puppetlabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2018-10-15T23:45:54.000Z","updated_at":"2024-12-19T10:41:21.000Z","dependencies_parsed_at":"2022-09-26T20:30:38.567Z","dependency_job_id":null,"html_url":"https://github.com/puppetlabs/puppetlabs-python_task_helper","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppetlabs-python_task_helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppetlabs-python_task_helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppetlabs-python_task_helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puppetlabs%2Fpuppetlabs-python_task_helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/puppetlabs","download_url":"https://codeload.github.com/puppetlabs/puppetlabs-python_task_helper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236831094,"owners_count":19211640,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["module","supported"],"created_at":"2024-09-24T19:58:04.379Z","updated_at":"2025-10-19T17:30:42.350Z","avatar_url":"https://github.com/puppetlabs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# python_task_helper\n\nA Python helper library for use by [Puppet Tasks](https://puppet.com/docs/bolt/latest/writing_tasks.html). It provides a class that handles error generation, simplifies JSON input and output, and makes testing your task easier. It requires Bolt \u003e= 1.1 and Puppet Enterprise \u003e= 2019.0.\n\n#### Table of Contents\n\n1. [Description](#description)\n1. [Requirements](#requirements)\n1. [Setup](#setup)\n1. [Usage](#usage)\n1. [Debugging](#debugging)\n\n## Description\n\nThis library handles parsing JSON input, serializing the result as JSON output, and producing a formatted error message for errors.\n\n## Requirements\n\nThis library works with Python 2.7 and later.\n\n## Setup\n\nTo use this library, include this module in a `Puppetfile`\n```ruby\nmod 'puppetlabs-python_task_helper'\n```\n\nAdd it to your [task metadata](https://puppet.com/docs/bolt/1.x/writing_tasks.html#concept-677) (note that the helper expects to read arguments on stdin)\n```json\n{\n  \"files\": [\"python_task_helper/files/task_helper.py\"],\n  \"input_method\": \"stdin\"\n}\n```\n\n## Usage\n\nWhen writing your task include the library in your script, extend the `TaskHelper` module, and write the `task()` function. The `task()` function **must** take a hash of parameters as input (even if it's an empty hash), and **must** return a hash. The following is an example of a task that uses the library\n\n```python\n#!/usr/bin/env python\n\nimport os, sys\nsys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python_task_helper', 'files'))\nfrom task_helper import TaskHelper\n\nclass MyTask(TaskHelper):\n    def task(self, args):\n        return {'result': 'Hi, my name is '+args['name']}\n\nif __name__ == '__main__':\n    MyTask().run()\n```\n\nYou can then run the task like any other Bolt task\n```shell\nbolt task run mymodule::task -t target.example.com name='Robert'\n```\n\nYou can find this example in [examples](examples), as well as an example test in [tests](tests). For a real task, `examples` would be renamed to `tasks`.\n\nYou can additionally provide detailed errors by raising a `TaskError`, such as\n```python\nclass MyTask(TaskHelper):\n    def task(self, args):\n        raise TaskError('my task errored', 'mytask/error_kind', {'location': 'task entry'})\n```\n\n## Debugging\n\nWhen writing your task, it can be helpful to write debugging statements to locate\nthe source of any errors. The library includes a `debug` method that accepts arbitrary\nvalues and logs it as a debugging statement. If the task errors, the list of\ndebugging statements will be included in the resulting error message.\n\nThe list of debugging statements can also be accessed from the task itself by accessing\nthe `debug_statements` attribute. This can be used to include the debugging statements in\na `TaskError` that you explicitly raise.\n\nAdding a debugging statement:\n```python\nself.debug('Result of method call: {}'.format(result))\n```\nAdding the list of debugging statements to a `TaskError`:\n```python\nraise TaskError('my task error message',\n                'mytask/error-kind',\n                { 'debug': self.debug_statements })\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuppetlabs%2Fpuppetlabs-python_task_helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuppetlabs%2Fpuppetlabs-python_task_helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuppetlabs%2Fpuppetlabs-python_task_helper/lists"}