{"id":19607118,"url":"https://github.com/robocorp/template-python-workitems","last_synced_at":"2026-02-27T22:42:41.412Z","repository":{"id":177225117,"uuid":"652598816","full_name":"robocorp/template-python-workitems","owner":"robocorp","description":"Template for producer-consumer automations using Robocorp -libraries","archived":false,"fork":false,"pushed_at":"2025-05-11T05:34:00.000Z","size":176,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-11T06:28:13.736Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","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/robocorp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-06-12T12:02:30.000Z","updated_at":"2025-05-11T05:34:03.000Z","dependencies_parsed_at":"2023-10-11T20:59:54.042Z","dependency_job_id":"e0190b66-06ab-41a7-9e7c-1554fe48b636","html_url":"https://github.com/robocorp/template-python-workitems","commit_stats":null,"previous_names":["robocorp/template-python-workitems"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robocorp/template-python-workitems","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Ftemplate-python-workitems","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Ftemplate-python-workitems/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Ftemplate-python-workitems/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Ftemplate-python-workitems/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robocorp","download_url":"https://codeload.github.com/robocorp/template-python-workitems/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robocorp%2Ftemplate-python-workitems/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29917942,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"ssl_error","status_checked_at":"2026-02-27T19:37:41.463Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-11T10:08:56.070Z","updated_at":"2026-02-27T22:42:41.405Z","avatar_url":"https://github.com/robocorp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Template: Python - Producer-Consumer\n\nThis template leverages the new [Python framework](https://github.com/robocorp/robocorp)\n\nThis template contains a working robot implementation that has the basic structure where the first part produces work items from an input and the second one consumes those newly created output work items.\n\n![process.png](./docs/process.png)\n\nThe template tries to keep the amount of functional code at a minimum so you have less to clear out and replace with your own implementation, but some functional logic is needed to have the template working and guiding the key parts.\n\n\u003e We recommended checking out the article \"[Using work items](https://robocorp.com/docs-robot-framework/development-guide/control-room/work-items)\" before diving in.\n\n## Tasks\n\nThe robot is split into two tasks, meant to run as separate steps in Control Room. The first task generates (produces) data, and the second one reads (consumes) and processes that data.\n\n### The first task (the producer)\n\n- Load the example Excel file from work item\n- Split the Excel file into work items for the consumer\n\n### The second task (the consumer)\n\n\u003e We recommended checking out the article \"[Work item exception handling](https://robocorp.com/docs-robot-framework/development-guide/control-room/work-items#work-item-exception-handling)\" before diving in.\n\n- Loop through all work items in the queue and access the payloads from the previous step\n\n## Local testing\n\nFor best experience to test the work items in this example we recommend using [Sema4.ai SDK extension for VS Code](https://robocorp.com/docs/visual-studio-code/extension-features). With the Sema4 extension you can simply run and [select the input work items](https://robocorp.com/docs/visual-studio-code/extension-features#using-work-items) to use, create inputs to simulate error cases, and so on.\n\n## Extending the template\n\n\u003e The [producer-consumer](https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem) model is not limited to two steps, it can continue so that the consumer generates further work items for the next step and so on.\n\nHere's how you can add a third step, let's say a **reporter**, which will collect inputs from the previous one (the **consumer**) and generate a simple report with the previously created data. But first, see below what you need to add extra:\n\n### The `reporter` step code\n\n```python\n@task\ndef reporter():\n    \"\"\"Collect and combine all the consumer outputs into a single report.\"\"\"\n    complete_orders = sum(\"complete\" in item.payload[\"Order\"] for item in workitems.inputs)\n    print(f\"Complete orders: {complete_orders}\")\n```\n\nAnd as you can see, we collect some `\"Order\"` info from the previously created outputs, but we don't have yet such outputs created in the previous step (the **consumer**), so let's create them:\n\n```python\n@task\ndef consumer():\n    \"\"\"Process all the produced input Work Items from the previous step.\"\"\"\n    for item in workitems.inputs:\n        try:\n            ...\n            workitems.outputs.create(payload={\"Order\": f\"{name} is complete\"})\n            item.done()\n        except AssertionError as err:\n            ...\n```\n\nThe magic happens in this single line added right before the `item.done()` part: `workitems.outputs.create(payload={\"Order\": f\"{name} is complete\"})`. This creates a new output for every processed input with an `\"Order\"` field in the payload data. This is retrieved in the next step (**reporter**) through `item.payload[\"Order\"]`.\n\n### The `reporter` task entry\n\nAll good on the code side, but we need now to make this new task visible and runnable right in our [*robot.yaml*](./robot.yaml) configuration. So add this under `tasks:`:\n\n```yaml\nReporter:\n    shell: python -m robocorp.tasks run tasks.py -t reporter\n```\n\nNow you're good to go, just run the **consumer** again (so you'll have output items created), then run the newly introduced 3rd step called **reporter**.\n\n----\n\n🚀 Now, go get'em\n\nStart writing Python and remember that the AI/LLM's out there are getting really good and creating Python code specifically.\n\n👉 Try out [Robocorp ReMark 💬](https://chat.robocorp.com)\n\nFor more information, do not forget to check out the following:\n\n- [Robocorp Documentation -site](https://robocorp.com/docs)\n- [Portal for more examples](https://robocorp.com/portal)\n- Follow our main [robocorp -repository](https://github.com/robocorp/robocorp) as it is the main location where we developed the libraries and the framework.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobocorp%2Ftemplate-python-workitems","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobocorp%2Ftemplate-python-workitems","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobocorp%2Ftemplate-python-workitems/lists"}