Robocorp

3.1.1 · active · verified Wed Apr 15

Robocorp provides core Python libraries for robotic process automation (RPA), enabling developers to create and manage automated tasks. It includes modules for task orchestration, work item management, and integration with the Robocorp platform. The current version is 3.1.1, with regular updates typically released multiple times per quarter.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a simple Robocorp task that reads data from an input work item, processes it, and then writes the result to an output work item. It highlights the core 'task' decorator and 'workitems' modules, which are central to Robocorp automations.

import os
from robocorp.tasks import task
from robocorp.workitems import inputs, outputs

@task
def minimal_task():
    """
    A basic Robocorp task that reads an input and writes an output.
    
    To run locally, create a 'work-items/input.json' file in the root of your project
    with content like: `{"message": "Hello Robocorp!"}`
    Then execute with `python -m robocorp.tasks run -t minimal_task`.
    """
    try:
        # Access current input work item payload
        input_payload = inputs.current.payload
        message = input_payload.get("message", "No message provided.")
        print(f"Received message: {message}")

        # Process the message
        processed_message = f"Processed by Robocorp: {message.upper()}"

        # Create an output work item and save processed data
        output_item = outputs.create()
        output_item.payload["processed_message"] = processed_message
        output_item.save()

        print(f"Wrote output: {processed_message}")

    except Exception as e:
        # In a real scenario, you'd handle errors more robustly for Control Room visibility
        print(f"Task failed: {e}")
        raise # Re-raise to indicate task failure

view raw JSON →