PTB Django Cookiecutter

PTB Django Cookiecutter

A simple cookiecutter to create Python Telegram bots, wrapped with Django.

All Contributors

Latest release Chat on Telegram

Based on this cool projects

What's inside


Install the latest Cookiecutter if you haven't installed it yet:

pip install -U cookiecutter

Create your bot using this cookiecutter:

cookiecutter gh:lugodev/ptb-django-cookiecutter

This will clone the cookiecutter and launch a wizard to help you customize your new bot.


Bot engine folder structure

Once you have generated your new bot, you will get this folders structure:

Install your bot dependencies

You have two primary options to install de bot Python dependencies: pip or Poetry. You can also use pipenv, virtualenvwrapper or another package managers. We recommend Poetry.

  1. Install dependencies using Poetry:

    curl -sSL | python - cd src/bot poetry install

Tip (optional): Create these aliases on on your .bashrc or .zshrc, like this

alias poetry="python3 -m poetry"
alias django="poetry run ./"
alias djr="django runserver"
alias djm="django makemigrations && django migrate"
alias djmr="djm && djr"
  1. Or install your dependencies using pip.

    pip3 install -r requirements.txt

Initialize your bot environment variables

Place your env vars to the .env file (never push this file to the repo):

SECRET_KEY=your django random secret key
TELEGRAM_TOKEN=your bot token

Start the bot

Start the bot (using the previously suggested alias, optional):

django runbot

Or using Poetry:

python3 -m poetry run ./ runbot

Or using Python:

python3 runbot

Deploy your bot

Clone your repo to the server, and create this folder structure:

Create and fill the ./codebase/.env file with the environment vars.

Then, deploy, using docker-compose:

cd codebase
docker-compose up --build -d

Bots created with this cookiecutter

None yet. Want to be the first? Submit your bot if it's open source.

Related videos

Crea tu bot de Telegram usando esta plantilla - PTB  + Django + Cookiecutter