Comparison

Deploying a Python bot (aiogram, discord.py, FastAPI) to production

Four habits make any Python bot deployable.

Comparison2 min readUpdated

Prepare the project

  1. Pin dependencies in requirements.txt.
  2. Read tokens with os.environ, never hard-code them.
  3. Log to stdout so the host shows logs.
  4. Add a Dockerfile (our templates include one).
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
USER nobody
CMD ["python", "-m", "bot.main"]

Deploy

Railway: connect the GitHub repository, add the variables, deploy. Tutorial: deploy a bot on Railway.

Vultr: create a venv on the server and a systemd unit. Tutorial: bot on a Vultr VPS with systemd.

Templates: aiogram · discord.py · FastAPI WhatsApp

Frequently asked questions

Which Python version?

Our templates require Python 3.10 or newer; use a currently supported release.

Do I need Docker?

No, but it makes the build reproducible on any host.

How do I keep it running after crashes?

Use the platform restart policy or systemd Restart=always.