Skip to main content

Hello Community,

 

I’m looking at using Automation Anywhere alongside my Python/PostgreSQL pipeline, but here’s the catch:

I’ve got 6 Python scripts (total line of code ~4000) that runs sequential —:

  1. Downloads attachments from specific O365 folders (filtered by sender and subject)

  2. Converts and reformats them into CSVs

  3. Loads that CSV data straight into PostgreSQL

  4. Runs queries to pull out insights

  5. Builds custom HTML reports

  6. Emails each customer their report

All the logging, error handling, config, O365 retrieval/send and DB logic lives neatly inside that script. Splitting it up into a ton of tiny AA calls feels like way more work than it’s worth.

Ideally, I’d love for Automation Anywhere to just treat my scripts as a black box—kick it off, let Python handle the heavy lifting, and then grab the exit code or logs when it’s done.  if it’s possible? if yes, how to make it work, thanks

Yes, our software can do this. See the Python package in our docs site for more detail. 

https://docs.automationanywhere.com/bundle/enterprise-v2019/page/enterprise-cloud/topics/aae-client/bot-creator/commands/cloud-python-command.html

I have a Python script that calls Whisper for AI transcription of videos. The script can run for a long time. No issues whatsoever. 


@Aaron.Gleason thanks

I checked the link and it looks like I need a top‑level execute() function to actually kick off my Python scripts.

But each script already has its own helper functions —DB connect/query/update/insert, logging, error handling, file processing, etc. Since I’m using dotenv to pull in my .env vars, how do I get Functions (AA) to load that file, and what’s the best way to wire up my DB connection and logger inside execute()?

Also, is there any way to tap into the Functions credential locker for database creds? I don’t see any mention of it in the docs.

thanks


Honestly, once you’re in Python, you’re on your own. You won’t have access to the credential vault or the database connection. You can still use that functionality in the task bot and pass any relevant information to the next Python script.

Going back to what you said at the beginning:

Ideally, I’d love for Automation Anywhere to just treat my scripts as a black box—kick it off, let Python handle the heavy lifting, and then grab the exit code or logs when it’s done.

That’s what we can do for you. The task bot can do any preparation for the logs and environment, fire off one of your Python scripts, gather any returned data/logs and log that, then execute the next Python script, etc.

When we run a Python script, it’s just like you firing it off from a PowerShell or Terminal window. Any database connections you have established in Python will continue to function as expected and will not be affected by any database connections created by the task bot.


@Aaron Gleason  thanks

That’s what we can do for you. The task bot can do any preparation for the logs and environment, fire off one of your Python scripts, gather any returned data/logs and log that, then execute the next Python script, etc.


I checked the log folder, and while the bot’s log file keeps getting its timestamp updated, when I unzip the Azure Functions (AA) logs, there’s nothing recent in there—no new logs that show what actually happened or why the script didn’t run. my script’s log—which normally shows detailed step-by-step info—isn’t being updated at all. It looks like the bot finishes in about 10 seconds, but my script usually takes closer to 50 seconds when run outside of AA. So the script isn't actually running in the background, even though the bot log makes it look like something happened. Do I need to do anything extra to enable AA logging?

When we run a Python script, it’s just like you firing it off from a PowerShell or Terminal window. Any database connections you have established in Python will continue to function as expected and will not be affected by any database connections created by the task bot.


Since I’m using dotenv (from dotenv import load_dotenv) to load my .env vars, how do I get Functions (AA) to pick up that file? What’s the cleanest way to wire my DB connection and logger inside execute()? And is there any support for tapping into the Functions credential locker for database creds? I can’t find any reference to it in the docs.

thank you


@DanC 

For logging, check that you aren’t getting an error when running the python script through AA.

Check the “Throw an exception if the python script fails” checkbox on your python action.

Without checking this, the AA step will always “succeed” but the output will simply be “bot error”.

 

For dotenv, you’ll need to pass in the location of your .env file since by default it checks within the script’s directory and this is dynamic when run through AA.

I would set up a wrapper function to be called from AA that takes the .env full path as an input, then initializes the rest of your script after calling load_dotenv

def aa_wrapper(your_input_param):
load_dotenv(dotenv_path=your_input_param)
main_function()

 


@sleemand
 

thanks for the tip—I spent a few hours banging my head against it, but finally got it working.

Here’s what I learned (for anyone else using the Community Edition):

When you use AA’s Python Script “Execute function” action, it only runs the exact function you name (in my case, aa_wrapper). Nothing else in your file—even your main() or any module-level code—will ever run unless you explicitly call it from inside aa_wrapper.

That’s why I kept seeing four “Logging configured to…” messages (because I was calling aa_wrapper four times) but never hit any of my DB-connect, CSV-compare, etc. logic—it was all hiding in main() and never getting invoked.

I ended up hard-coding the .env path because the function kept prompting me to confirm .env file location. I’ll revisit this later and may open a new thread. Thanks, everyone! ​@Aaron Gleason

@sleemand

 

Here’s the fixed wrapper (and the standalone block) I ended up with:

def aa_wrapper(env_path: str = None):
# 1) load .env
path = env_path or default_env_path
if not os.path.exists(path):
return f"ERROR: .env not found at {path}"
load_dotenv(dotenv_path=path, override=True)

# 2) configure logging
log_path = os.getenv("ERROR_LOG_PATH_thon_cvlt")
if not log_path:
return "ERROR: ERROR_LOG_PATH_thon_cvlt not set"
setup_logging(log_path)

# 3) test DB
try:
db = DatabaseConnection()
with db.get_connection():
logger.info("DB connection test succeeded")
except Exception as e:
return f"ERROR: DB test failed: {e}"

# 4) prompt & process
customers = select_customer_interactive()
results = {c: process_customer_reports(c) for c in customers}

# 5) return summary
succ = 5c for c, ok in results.items() if ok]
fail = tc for c, ok in results.items() if not ok]
return f"Done. Success: {', '.join(succ)}; Failed: {', '.join(fail)}"

# ---------------------------
# If run standalone
# ---------------------------
if __name__ == "__main__":
out = aa_wrapper(default_env_path)
print(out)
sys.exit(0 if out.startswith("Done") else 1)

 


Reply