DEV Community

John Wick
John Wick

Posted on

10 Practical Uses for Python Automation with StayPresent

10 Real-World Ways Developers Use StayPresent

Python automation covers a huge range of projects — bots, scrapers, schedulers, monitors, agents — and almost all of them share one deployment problem: they're long-running scripts that don't naturally expose an HTTP port, which most hosting platforms expect. Here are ten concrete ways developers use StayPresent to solve that across very different kinds of projects.

Table of Contents

  1. Discord Bots
  2. Telegram Bots
  3. Web Scrapers
  4. Background Job Workers
  5. Scheduled Scripts
  6. API Polling Services
  7. IoT Control Scripts
  8. Monitoring Tools
  9. Personal Assistants
  10. AI Agents
  11. Best Practices Across Use Cases
  12. FAQs
  13. Conclusion ## 1. Discord Bots

A discord.py bot's bot.run() call blocks forever on a WebSocket connection, with no HTTP server of its own. Wrapping it in StayPresent gives hosting platforms the port they expect:

import staypresent

staypresent.web.json({"bot": "discord", "status": "online"})
staypresent.run("bot.py")
Enter fullscreen mode Exit fullscreen mode

2. Telegram Bots

The same pattern applies to Pyrogram or python-telegram-bot projects — including multi-bot pipelines where several bot instances share a queue or database:

staypresent.web.text("Telegram bot operational")
staypresent.run("telegram_bot.py", restart_on_crash=True)
Enter fullscreen mode Exit fullscreen mode

3. Web Scrapers

A scraper that runs continuously or on a loop benefits from crash recovery just as much as a bot does — a single malformed page or a network timeout shouldn't take the whole scraper offline permanently:

staypresent.run(
    "scraper.py",
    max_restarts=10,
    restart_delay=5.0,
)
Enter fullscreen mode Exit fullscreen mode

4. Background Job Workers

Queue-processing workers (email senders, image processors, transcoders) often run as always-on processes. StayPresent's health endpoint lets you point an external monitor at the worker independently of whatever queue dashboard you're already using:

staypresent.web.json({"worker": "email-queue"})
staypresent.run("worker.py")
Enter fullscreen mode Exit fullscreen mode

5. Scheduled Scripts

Some scripts aren't meant to run forever — they're meant to fire once and exit cleanly. StayPresent's repeat=False option on cron() supports a single delayed background execution, and a clean sys.exit(0) from your script is treated as intentional, so it won't trigger a restart:

staypresent.run("daily_report.py", restart_on_crash=False)
Enter fullscreen mode Exit fullscreen mode

6. API Polling Services

Services that poll a third-party API on an interval — checking for new data, watching for price changes, syncing records — are a natural fit for the combination of a keep-alive server and StayPresent's own scheduled cron() pings to prevent the hosting side from idling out between polls:

staypresent.cron("https://my-poller.onrender.com", interval=240)
staypresent.run("poller.py")
Enter fullscreen mode Exit fullscreen mode

7. IoT Control Scripts

Scripts that bridge to IoT devices over MQTT or a local API often run on small VPS instances or free-tier containers. StayPresent's HTML response mode is useful here for a lightweight on-disk status dashboard that updates without restarting the process:

staypresent.web.html("templates/device_status.html")
staypresent.run("iot_bridge.py")
Enter fullscreen mode Exit fullscreen mode

8. Monitoring Tools

Website or service health monitors — the kind of tool that itself checks other URLs on a schedule — need to stay online more reliably than almost anything else, since their entire job is uptime awareness. Wrapping the monitor itself in StayPresent, complete with crash recovery and its own /health endpoint, avoids the awkward situation of a monitoring tool going down unnoticed:

staypresent.run(
    "site_monitor.py",
    restart_on_crash=True,
    max_restarts=5,
    restart_reset_after=120.0,
)
Enter fullscreen mode Exit fullscreen mode

9. Personal Assistants

Custom personal-assistant scripts — calendar checkers, reminder bots, notification relays — tend to be smaller, more experimental projects where developers don't want to spend time on deployment plumbing. A single staypresent.run() call keeps the focus on the assistant's actual logic:

staypresent.web.json({"assistant": "online"})
staypresent.run("assistant.py")
Enter fullscreen mode Exit fullscreen mode

10. AI Agents

Long-running AI agent loops — polling for tasks, watching a queue, orchestrating tool calls — face the exact same hosting constraints as any other background process. StayPresent's env parameter is particularly useful here for injecting API keys or configuration into the agent process without hardcoding them:

staypresent.run(
    "agent.py",
    env={"AGENT_MODE": "production"},
)
Enter fullscreen mode Exit fullscreen mode

Best Practices Across Use Cases

  • Match max_restarts and restart_delay to how expensive a restart actually is for your script — a lightweight poller can restart aggressively; a scraper that re-authenticates on startup should back off more.
  • Use web.json() to expose lightweight status information (queue depth, last-run timestamp) that's useful for debugging without building a full dashboard.
  • Keep secrets in env= or your platform's environment variables rather than in bot_args. ## FAQs

Does StayPresent work for scripts that aren't bots at all?
Yes — anything that's a long-running Python process and needs an HTTP port to satisfy a hosting platform is a fit, regardless of what the script actually does.

Can I run a one-off script instead of a forever-loop?
Yes, with restart_on_crash=False and a clean exit code, StayPresent won't try to relaunch it.

Is there a limit to how many use cases this fits?
Not really — the common thread across all ten examples above is "long-running Python process + hosting platform that wants an HTTP port," which describes a large share of real-world automation work.

Conclusion

Whatever kind of python automation you're deploying — a Discord bot, a scraper, an AI agent, or something in between — the underlying hosting problem is almost always the same, and StayPresent solves it the same way every time: one HTTP server, one supervised subprocess, minimal setup.

pip install staypresent[prod]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)