Scripts

How scripts work in Humrun.

Overview

A script in Humrun is a single Python file that runs on a schedule. Each script runs in isolation with its own environment.

Python version

Scripts run on Python 3.11. We update to new Python versions periodically, with advance notice.

Available packages

The following packages are pre-installed:

  • requests - HTTP requests
  • beautifulsoup4 - HTML parsing
  • lxml - XML parsing
  • icalendar - Calendar ICS parsing

Need a package that's not listed? Contact us and we'll consider adding it.

Humrun does not include cloud provider SDKs (AWS, GCP, Azure). If your automation requires cloud infrastructure access, Humrun may not be the right tool — and that's intentional.

Restricted modules

For security, the following modules cannot be imported:

  • sys
  • subprocess
  • socket
  • ctypes
  • multiprocessing
  • threading
  • signal

If your script tries to import these, it will fail before execution.

Templates

When creating a new script, you can start from one of our pre-built templates:

  • Monitor a webpage - Check if a page has changed since last run
  • Check API health - Ping an endpoint and track consecutive failures
  • Send a daily digest - Summarize content with AI and send via email
  • Track price changes - Monitor a product page for price updates
  • Backup to S3 - Upload data to an S3 bucket using presigned URLs
  • Post to Slack - Send updates to your Slack channel

Templates come with sensible defaults for schedules and environment variables. You can customize them after creation.

Script structure

Your script should be a standard Python file. Here's a typical structure:

import requests
import os

# Get configuration from environment variables
API_KEY = os.environ.get("API_KEY")
WEBHOOK_URL = os.environ.get("WEBHOOK_URL")

def main():
    # Your logic here
    response = requests.get(
        "https://api.example.com/data",
        headers={"Authorization": f"Bearer {API_KEY}"}
    )

    data = response.json()
    print(f"Fetched {len(data)} items")

    # Send results somewhere
    requests.post(WEBHOOK_URL, json={"count": len(data)})

if __name__ == "__main__":
    main()

Output

Anything printed to stdout is captured and stored in the run log:

print("Starting check...")
print(f"Found {count} items")
print("Done!")

This output appears in your run history and can be included in notifications.

Errors

If your script raises an exception, the run is marked as failed:

if response.status_code != 200:
    raise Exception(f"API returned {response.status_code}")

The full traceback is captured and included in failure notifications.

Best practices

Keep scripts focused. One script should do one thing. If you need multiple tasks, create multiple scripts.

Handle errors explicitly. Don't let exceptions bubble up silently. Either handle them or let them fail loudly so you get notified.

Log useful output. Print enough information to understand what happened when reviewing run history.

Use environment variables for configuration. Never hardcode API keys or URLs in your script.