Robocorp Tasks
robocorp-tasks is a Python framework designed to simplify the development of Python automations by providing a runner for tasks, offering logging out of the box, and managing the lifecycle for running such tasks. It is currently at version 4.1.1 and receives continuous updates as part of the broader Robocorp/Sema4.ai ecosystem.
Common errors
-
Error: "Sending logoff command to the desktop session"
cause This error can occur if the Windows Customer Experience Improvement Program interferes with desktop sessions, causing unexpected logoffs during automation.fixDisable the Windows Group Policy 'User Account Control: Behavior of the elevation prompt for standard users' and 'Windows Customer Experience Improvement Program' settings. Refer to Robocorp documentation for specific policy paths. -
UnicodeEncodeError or garbled characters in logs/output
cause Often related to Windows code page settings not being configured for Unicode, leading to character encoding issues.fixEnsure your Windows system's code page is set to Unicode. Check Robocorp's troubleshooting guide for detailed steps on adjusting locale settings. -
Encountering a PID lock in environment building
cause This typically indicates an issue during the creation or setup of the Python execution environment by RCC (Robocorp Command Center), possibly due to a stuck process or cache corruption.fixClear or clean up local environment caches using the `rcc` command-line tool. Consult RCC documentation for specific cache clearing commands. -
ImportError: cannot import name '_internal_module' from 'robocorp.tasks'
cause Attempting to import internal modules or functions that are not part of the public API (indicated by a leading underscore).fixOnly import symbols that are part of the documented public API. Avoid importing any modules or functions that begin with an underscore (`_`).
Warnings
- breaking The broader Robocorp ecosystem has transitioned focus from Robot Framework to Python. While existing Robot Framework bots continue to operate, all new development and tooling support is directed towards Python. Users should plan to migrate or develop new automations in Python.
- deprecated The `Robocorp Code` VS Code extension has been deprecated and replaced by the `Sema4.ai extension`. Users should uninstall the old extension and install the new one for continued support and new features.
- gotcha Robocorp libraries with versions `0.x.x` are considered in development and may introduce breaking changes on any update. Although `robocorp-tasks` is now `4.x.x`, developers should always check the changelog for major version updates (`X.0.0`) for specific migration guidance as per SemVer.
- gotcha Modules and functions within the Robocorp libraries that start with an underscore (`_`) are considered internal and are not part of the public API. Importing or relying on these can lead to unexpected behavior or breaking changes in minor updates.
- gotcha In current versions, the `python -m robocorp.tasks run` command is designed to execute only one task per invocation. If multiple tasks are found in the target script/directory without a specific task name (`-t`) being provided, an error will be raised.
Install
-
pip install robocorp-tasks -
pip install robocorp
Imports
- task
from robocorp.robot import task
from robocorp.tasks import task
- setup
from robocorp.tasks import setup
- teardown
from robocorp.tasks import teardown
Quickstart
import os
from robocorp.tasks import task
from robocorp import log
@task
def hello_robocorp_world():
"""A simple Robocorp task that logs a message."""
name = os.environ.get('ROBOCORP_USER_NAME', 'World')
log.info(f"Hello, {name} from Robocorp!")
log.critical("This is a critical log message.")
log.debug("This is a debug message.")
# To run: Save as tasks.py and execute 'python -m robocorp.tasks run tasks.py'
# You can also use 'python -m robocorp.tasks run . -t hello_robocorp_world' in a directory.