Skip to main content

Drop-in replacement for robocorp-workitems with broader applicability

Project description

actions-work-items

A drop-in replacement for robocorp-workitems with broader applicability beyond robots.

Overview

actions-work-items provides work item management for producer-consumer workflows. It enables:

  • Robots/Automations: Traditional RPA producer-consumer patterns
  • Microservices: Async job queues with persistent state
  • ETL Pipelines: Data processing with tracking and error handling
  • Action Server Integration: Native REST API for work items

Installation

pip install actions-work-items

Or with poetry:

poetry add actions-work-items

Quick Start

robocorp-workitems Compatible API

from actions.work_items import inputs, outputs

# Process work items using singleton pattern
for item in inputs:
    data = item.payload
    # Process...
    outputs.create({"result": "processed"})
    item.done()

Context Manager Pattern (Recommended)

from actions.work_items import inputs, outputs, BusinessException

for item in inputs:
    with item:  # Auto-release on exit
        if not item.payload.get("required_field"):
            raise BusinessException("Missing required field")

        # Process item...
        outputs.create({"status": "success"})
        # item.done() called automatically

Explicit Initialization

from actions.work_items import init, create_adapter, inputs, outputs

# Create specific adapter
adapter = create_adapter("sqlite", db_path="./my-workitems.db")
init(adapter)

for item in inputs:
    # Process...

Adapters

SQLiteAdapter (Default)

Persistent local storage using SQLite database.

from actions.work_items import SQLiteAdapter, init

adapter = SQLiteAdapter(
    db_path="./workitems.db",
    queue_name="default",
    files_dir="./work_item_files",
)
init(adapter)

Environment variables:

  • RC_WORKITEM_DB_PATH: Database path (default: ./workitems.db)
  • RC_WORKITEM_QUEUE_NAME: Input queue (default: default)
  • RC_WORKITEM_OUTPUT_QUEUE_NAME: Output queue (default: {queue}_output)
  • RC_WORKITEM_FILES_DIR: Files directory (default: ./work_item_files)

FileAdapter

JSON file-based storage compatible with Robocorp Control Room format.

from actions.work_items import FileAdapter, init

adapter = FileAdapter(
    input_path="./output/work-items-in",
    output_path="./output/work-items-out",
)
init(adapter)

Environment variables:

  • RC_WORKITEM_INPUT_PATH: Input directory
  • RC_WORKITEM_OUTPUT_PATH: Output directory

Features

Producer Pattern

from actions.work_items import seed_input, init

init()

# Create work items for processing
for data in fetch_data():
    seed_input(
        payload={"url": data["url"], "name": data["name"]},
        queue_name="downloads",
    )

File Attachments

from actions.work_items import inputs, outputs

for item in inputs:
    with item:
        # List files
        files = item.list_files()

        # Get file content
        content = item.get_file("data.csv")

        # Add files (single or glob pattern)
        item.add_file(path="./report.pdf")
        item.add_files("./output/*.csv")

        # Remove files
        item.remove_file("temp.txt", missing_ok=True)
        item.remove_files("*.tmp")

Email Parsing

from actions.work_items import inputs

for item in inputs:
    with item:
        # Parse email attachment
        email = item.get_email("message.eml")

        print(f"From: {email.sender}")
        print(f"Subject: {email.subject}")
        print(f"Body: {email.body}")

Error Handling

from actions.work_items import (
    inputs,
    BusinessException,
    ApplicationException,
)

for item in inputs:
    with item:
        try:
            process(item.payload)
        except ValidationError as e:
            # Business error - don't retry
            raise BusinessException(str(e), code="VALIDATION_ERROR")
        except ConnectionError as e:
            # Application error - may retry
            raise ApplicationException(str(e), code="CONNECTION_ERROR")

Action Server Integration

The Action Server provides REST endpoints at /api/work-items:

# Create work item
curl -X POST http://localhost:8080/api/work-items \
  -H "Content-Type: application/json" \
  -d '{"payload": {"org": "sema4ai"}, "queue_name": "repos"}'

# List work items
curl http://localhost:8080/api/work-items?queue_name=repos&state=PENDING

# Get queue stats
curl http://localhost:8080/api/work-items/stats?queue_name=repos

API Reference

Singletons

  • inputs - Inputs collection singleton
  • outputs - Outputs collection singleton

Functions

  • init(adapter=None) - Initialize context
  • create_adapter(type=None, **kwargs) - Create adapter
  • seed_input(payload, files, queue_name) - Seed new input
  • get_context() - Get current context
  • get_input() - Get next input
  • create_output(payload, files, save) - Create output

Classes

  • Input - Input work item with done(), fail(), context manager
  • Output - Output work item with save()
  • Inputs - Collection with iteration, indexing, current, released
  • Outputs - Collection with create(), last

Adapters

  • BaseAdapter - Abstract interface
  • SQLiteAdapter - SQLite storage
  • FileAdapter - JSON file storage

Types

  • State - PENDING, IN_PROGRESS, DONE, FAILED
  • ExceptionType - BUSINESS, APPLICATION
  • Email - Parsed email dataclass
  • Address - Email address dataclass

Exceptions

  • EmptyQueue - No items available
  • BusinessException - Expected failure (no retry)
  • ApplicationException - Unexpected failure (may retry)

Migration from robocorp-workitems

# Before (robocorp-workitems)
from robocorp import workitems

for item in workitems.inputs:
    workitems.outputs.create(payload=item.payload)
    item.done()

# After (actions-work-items) - same API!
from actions.work_items import inputs, outputs

for item in inputs:
    outputs.create(payload=item.payload)
    item.done()

License

Apache 2.0 - Based on robocorp-workitems

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

actions_work_items-0.2.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

actions_work_items-0.2.0-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

Details for the file actions_work_items-0.2.0.tar.gz.

File metadata

  • Download URL: actions_work_items-0.2.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.0 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for actions_work_items-0.2.0.tar.gz
Algorithm Hash digest
SHA256 815e813a51d5d6ad48325d7cc852b8cb4df9c0a239b9504a4c55ab7c37350c10
MD5 edd2f6c75bf5f10da2ea6f184fa165f7
BLAKE2b-256 eda213abe6f80b25ec114f0e882255d8baf211e9338b0d486946c6cf93214087

See more details on using hashes here.

File details

Details for the file actions_work_items-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: actions_work_items-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.0 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for actions_work_items-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8c150ed79cf287028fe1234aebca740169d281b23af93086a9733924637c810
MD5 63f81e6de45813f3b488fae752f41479
BLAKE2b-256 5a0848c7b48720a0d9cb590eeaa7dcf30f976ce0fb9e305141eabd2706f6ada5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page