Framework Components¶
BeaPro is organized into modules, each responsible for one stage of the automation lifecycle. Except for bot.py, all of them live in the framework/ folder.
bot.py: Main Flow¶
The automation entry point. It coordinates the full execution flow:
- Calls
initialize()to prepare the environment. - Goes through the items of the configured data source.
- Calls
process_item(item)for each item. - Routes each result to the matching handler in
status_handling.py. After a system exception, it callsinitialize(restart=True)before moving on to the next item. - At the end, or after an interruption, calls
cleanup()andfinalize().
In general, you do not need to modify bot.py. Your automation logic goes in framework/process.py.
framework/process.py: Automation Logic¶
This is where you add your automation steps.
The process_item(item) function is called once for each data source item. The item arrives as a dictionary, with the CSV columns or the Datapool fields as keys:
def process_item(item):
STATE.raise_for_interrupt_requested()
logger.info(f"Item processing has started: {item}.")
bot = STATE.webbot
name = item['name']
email = item['email']
# ... your automation steps here
result_message = f"Processing successful for item {item}."
return result_message
STATE.raise_for_interrupt_requested(): checks in the Orchestrator whether the task received an interruption request. Keep this call at the start of the function.STATE.webbot:WebBotinstance already created during initialization. UseSTATE.desktopbotfor desktop automations.- Return value: the returned message is recorded as the item's success message in the log and in the data source.
framework/state.py: State Management¶
Defines the STATE object, shared across all modules. It stores:
- Orchestrator connection: the BotCity Maestro SDK instance and the task ID.
- Current item: the item being processed.
- Counters: items processed successfully, with errors, and the total.
- Bot instances:
WebBotandDesktopBot.
It also provides the interruption check and the final task status calculation:
SUCCESS: no item ended with an error.FAILED: all processed items ended with an error.PARTIALLY_COMPLETED: some items succeeded and some ended with an error.
On import, state.py detects the execution mode (BotCity Runner, local with authentication, or Test Mode). See the details in Execution Modes.
framework/exceptions.py: Exception Types¶
Defines three exception types that control how the main flow reacts to errors:
| Exception | When to Use | Behavior |
|---|---|---|
BusinessException |
Validation errors, invalid data, failures expected by the business rules | Records the error and continues with the next item |
SystemException |
Technical failures, application frozen or not responding | Records the error, reinitializes the environment, and continues |
InterruptException |
Interruption request made from the Orchestrator | Records a warning and ends the execution |
from framework.exceptions import BusinessException, SystemException
if not item.get('email'):
raise BusinessException("Email not found")
if not app_is_running():
raise SystemException("The target application is not responding")
Interruptions count as errors
The item being processed when the interruption happens is counted as an error. For this reason, an interrupted task ends as FAILED or PARTIALLY_COMPLETED.
framework/datasources.py: Data Sources¶
Provides two ready-to-use data sources and a base class for custom implementations. The source used by the automation is set in the data_source variable, at the end of the file.
Choose the data source
The step-by-step guide to switching between Datapool and CSV is in Configure the Data Source.
CSVSource¶
Reads items from a CSV file and delivers each row as a dictionary, with the column names as keys.
- Result file: generates in
output/a copy of the CSV with theTIMESTAMP,STATUS, andMESSAGEcolumns added. - Status per item:
SUCCESS,BUSINESS EXCEPTION,SYSTEM EXCEPTION, orINTERRUPTION REQUESTED.
DatapoolSource¶
Consumes items from an Orchestrator Datapool, based on the given label.
- Status per item: marks each item as done or as an error in the Datapool, classifying the error as business or system.
- End of processing: ends the loop when the Datapool has no more items or is inactive.
Custom Data Sources¶
Create a class that inherits from BaseSource and implement __iter__, __next__, report_success, and report_error to read data from databases, APIs, or other systems.
framework/initialize.py: Initialization¶
Prepares the environment at the start of the execution. On the first initialization, it:
- Deletes and recreates the
output/andtemp/folders. - Configures the file log and creates the automation log in the Orchestrator.
- Runs the steps to open and log into systems, which you implement in the sections marked in the code.
- Creates the
WebBotandDesktopBotinstances.
The contents of output/ and temp/ are deleted
On every new execution, the output/ and temp/ folders are emptied. Do not keep files there that need to be preserved, such as the input CSV.
After a system exception, initialization runs with restart=True: it closes the browser, repeats the open and login steps, and recreates the bots, without deleting the folders.
Customize init_webbot() to configure the browser:
from botcity.web import Browser, WebBot
def init_webbot():
STATE.webbot = WebBot()
bot = STATE.webbot
bot.headless = False
bot.browser = Browser.CHROME # Example
framework/finalize.py: Finalization¶
Contains the two functions called at the end of the execution:
cleanup(): closes the browser and is the place to log out and close applications, connections, and sessions. It is also called before each restart.finalize(): records the summary message in the automation log in the Orchestrator, uploads all files from theoutput/folder as Result Files, and finishes the task with the computed status and the total, processed, and failed item counts.
Add information to the final message
Use append_finish_status_message("your text") to include extra information in the summary message shown when the task finishes.
framework/status_handling.py: Status Handling¶
Contains the handlers called by bot.py for each result:
| Handler | Orchestrator Alert | Screenshot |
|---|---|---|
register_success |
None | No |
handle_business_exception |
ERROR |
Yes |
handle_system_exception |
ERROR |
Yes |
handle_interrupt_requested |
WARN |
No |
Besides the alert, each handler updates the STATE counters, records the result in the log, and reports the item status to the data source. For business and system exceptions, the handler saves a screenshot of the screen in temp/ and records the error in the Orchestrator with the image attached.
Each handler has a reserved section where you can add your own steps, such as email notifications, updates to external databases, or retry logic.
framework/logger.py: Logs¶
Configures the logs for each execution:
- File log: written to
output/Log_BotCity_task-{task_id}_date-{date}.log, with timestamp, level, module, and function on each line. - Orchestrator log: a log named after the automation, where
finalize()records the summary message of each execution.
To log messages in your own modules, use the standard Python logger:
import logging
logger = logging.getLogger(__name__)
logger.info(f"Add your message including {variables}.")
Generated Files¶
| File | Description |
|---|---|
output/Log_BotCity_task-{id}_date-{date}.log |
Full execution log, with timestamps |
output/CSV_BotCity_task-{id}_date-{date}.csv |
Input data with the TIMESTAMP, STATUS, and MESSAGE columns (only with CSVSource) |
temp/error-{date}.png |
Screenshots captured on business and system exceptions |
The files in the output/ folder are uploaded to the Orchestrator as Result Files at the end of the execution. The screenshots in temp/ are not uploaded as Result Files: they are attached to the task's error records.