Robocorp
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
- breaking The `robocorp.browser` and `robocorp.windows` modules included directly in the `robocorp` package are frozen at older versions (1.x as of `robocorp` v3.x). For up-to-date and feature-rich browser or Windows automation, you must explicitly install `rpaframework-browser` and `rpaframework-windows` and import from those packages (e.g., `from rpaframework.browser import ...`).
- breaking Major refactor in v2.0.0 moved primary task and work item functionalities into dedicated sub-packages. Old imports like `from robocorp import task` or `from robocorp import workitems` no longer work.
- gotcha Robocorp tasks operate within a specific environment, heavily relying on 'work items' for input and output data. When running tasks locally or debugging, ensure you provide valid `work-items/input.json` files to simulate the expected inputs, or tasks might fail attempting to access non-existent data.
- gotcha While `robocorp` is the core Python library, Robocorp's ecosystem includes other critical tools like `rcc` (Robocorp Command Center) for environment management and `Action Server` for exposing automations as APIs. These are separate installations and tools, and the `robocorp` library itself doesn't directly provide their functionality.
Install
-
pip install robocorp
Imports
- task
from robocorp import task
from robocorp.tasks import task
- inputs
from robocorp import workitems
from robocorp.workitems import inputs
- outputs
from robocorp.workitems import outputs
- page
from robocorp.browser import browser
from rpaframework.browser import page
Quickstart
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