StayPresent — Keep Your Python Bots Alive Without the Boilerplate 🚀
If you've ever deployed a Discord bot, Telegram bot, or any long-running Python script to a platform like Render, Railway, Koyeb, or Heroku, you've probably run into the same problem.
Your application needs an active HTTP service, but your project isn't a web application.
Most people end up writing a tiny Flask server just to satisfy the hosting platform's health checks. It works... but it also means copying the same boilerplate into every project.
I got tired of doing that.
So I built StayPresent.
What is StayPresent?
StayPresent is a lightweight Python package that lets you run a web server alongside your bot or background script with almost no setup.
Instead of writing and maintaining a Flask server yourself, you simply do:
import staypresent
staypresent.run("bot.py")
That's it.
StayPresent starts an HTTP server in the background while your bot runs normally. If your bot crashes, it automatically restarts it.
Why I Built It
Almost every bot deployment tutorial includes something like this:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Bot is running"
app.run(host="0.0.0.0", port=8080)
The code itself isn't difficult.
The problem is having to copy it into every single project.
I wanted something that worked like this instead:
- Install one package
- Import it
- Run your bot
- Forget about the web server forever
That idea eventually became StayPresent.
Features
✨ One-line setup
staypresent.run("bot.py")
🚀 Automatic crash recovery
If your bot exits unexpectedly, StayPresent can automatically restart it.
🤖 Multiple bot support
staypresent.run([
"telegram_bot.py",
"discord_bot.py",
])
Each process is monitored independently.
🌐 Built-in web responses
Serve:
- Plain text
- JSON
- HTML
- Markdown
Example:
staypresent.web.markdown("CHANGELOG.md")
Now your changelog becomes a nice-looking web page.
🎨 Built-in Markdown renderer
No extra Markdown package required.
It supports:
- Tables
- Images
- Code blocks
- Nested lists
- GitHub-like styling
- Light & Dark themes
⚙ Production ready
If waitress is installed, StayPresent automatically uses it instead of Flask's development server.
Example
import staypresent
staypresent.web.markdown("README.md")
staypresent.run(
"bot.py",
port=5000,
)
A web server starts, your bot launches, and everything runs together.
Optional Keep-Warm
Some free hosting platforms suspend inactive services.
StayPresent also includes an optional self-ping utility.
import staypresent
staypresent.cron(
"https://my-app.onrender.com",
interval=300
)
Enable it only if you actually need it.
Installation
pip install staypresent
Production installation:
pip install staypresent[prod]
Open Source
StayPresent is completely open source.
GitHub:
https://github.com/StayElite/StayPresent
PyPI:
https://pypi.org/project/staypresent/
I'd love feedback, bug reports, feature requests, or even just ideas for improving it.
If you find it useful, consider giving the repository a ⭐.
Happy coding! 🚀
Top comments (0)