a close up of a cell phone on a table

Get Notified When Your Jupyter Notebook Finishes Using a Telegram Bot

Disclaimer: This blog post is not affiliated with or endorsed by Telegram. As part of our workflow experimentation in the DEPRIMAP project, we explored multiple ways to receive remote notifications for long-running Jupyter Notebook tasks. Among the options tested, Telegram offered the simplest and secure implementation with minimal setup. We are sharing this solution purely as a practical tip based on our experience.

Have you ever found yourself waiting around for a Jupyter Notebook cell to finish running? Maybe you are training a large model, exporting data from cloud servers, or processing heavy geospatial files. You step away for a coffee or switch to another task, only to return much later, unsure if your code finished 10 seconds ago or 10 minutes ago.

In large-scale projects like DEPRIMAP, where notebooks can take time to execute due to high-resolution geospatial datasets or remote API requests, this is more than just an inconvenience; it’s a break in workflow.

That’s where Telegram comes in.

In this guide, I’ll show you how to:

  • Set up a Telegram bot
  • Connect it to your Jupyter notebook
  • Receive a message when your code completes

All using a few lines of Python and zero third-party dependencies beyond ‘requests’.

No need to configure email servers or expose passwords. Telegram is fast, secure, and already on your phone (hopefully), so why not let it tell you when your code is done?

Github Repository link: https://github.com/saiga143/telegram-jupyter-notify


What You’ll Need

You don’t need any complex setup or heavy libraries to make this work. Just a few basic tools:

a) A Telegram account

If you’re reading this on your phone, chances are you already have one. If not, download the Telegram app from the Play Store or App Store, or use the web version.

b) Access to Jupyter Notebook

This can be:

  • A local Jupyter environment (Anaconda, JupyterLab, VS Code, etc.)
  • A hosted environment (like Binder, Colab, or a remote server).

c) Python’s ‘requests’ Library

This handles sending the actual message to Telegram. You can install it by running:

pip install requests

That’s all – no need for email server configs or messaging API subscriptions.


βš™οΈStep-by-Step Setup

In this section, we’ll walk through how to:

  • Create your own Telegram bot
  • Get your unique chat ID
  • Connect it to a Python function
  • Send your first notification from a Jupyter Notebook

Step 1: Create a Telegram Bot

1. Open the Telegram App

2. In the search bar, type and select ‘@BotFather

3. Click ‘Start’ to begin

4. Then type ‘/newbot’ and follow the prompts:

  • Give your bot a name (e.g., ‘jupyter_notify_bot’)
  • Give it a username (must end in ‘bot’, like ‘notifier_xyz_bot’)

πŸͺͺ Once done, BotFather will send you a message that contains an API token that looks like the image below.

The code highlighted in the yellow box is your API token.

πŸ“ŒCopy this token somewhere safe – it’s what allows your code to send you messages.

Step 2: Start a Chat with your Bot

1. In Telegram, search for the bot you just created by its username (or you can also click on the link mentioned in the previous message, which mentions your API token.

2. Click Start to activate the bot.

3. Send it a message – even a simple ‘hi’ will do.

This is important. Telegram only allows bots to send messages to users who’ve initiated a chat.

Step 3: Get Your Chat ID

To send yourself a message, you need your unique chat ID.

1. Open the link below in your browser (replace ‘<YOUR_TOKEN>’) with your API token:

 https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates

So it looks something like this:

https://api.telegram.org/bot8070205656:AAEnxNEtUpdTtbK2z7NIqni5W5UpLK-K984/getUpdates

When you open the above link in your browser, you should see something like below (if you don’t see that, send another message to your bot and refresh the page)

πŸ” The number next to ‘id’ under ‘chat’ shown using the orange arrow in the above picture is your chat ID.

Copy it – you’ll use it in your Python script.

Step 4: Add the Notification Function to Your Notebook

Now it’s time this into your Jupyter Notebook. Refer to the ‘telegram_notify_example.ipynb’ file in the GitHub repo, which contains the following function. Replace the token and chat ID with your API token ID and chat ID, respectively.

🧠 Tip: Keep this function cell near the top of your notebook so you can reuse it easily.

Step 5: Send a Message When Your Task Finishes

After any cell or block of code that takes time, you can trigger the bot to notify you. Below is a basic example use case.

πŸ”§ Customise it by:

  • Changing the message text
  • Embedding timestamps
  • Adding emojis to signal success/failure visually

You can even wrap this into a function to notify only on error. All examples are shown in the Jupyter notebook in the GitHub repo.

Below is an example picture of how the notifications look in the Telegram app.


🌍Use Cases for Research Workflows

So, where does this fit into your workflow?

Here are a few common situations, especially in data-heavy, geospatial, or machine learning projects, where a Telegram bot notification can be a game-changer:

πŸ›°οΈEarth Observation Tasks

When exporting large image collections or processing satellite imagery, cell execution can take several minutes or hours. Instead of checking repeatedly, let Telegram alert you when the export or processing is complete.

🧠Model Training

Whether it’s a deep learning model for slum detection or a Random Forest Classifier, training time varies widely based on data and parameters. You can insert a Telegram notification once the model finishes running or achieves a certain validation score.

πŸ—ΊοΈGeospatial Analysis

Operations like zonal statistics, projection, tiling, or merging large raster/vector files can be heavy. If your notebooks handle global-scale or high-resolution city data (as in DEPRIMAP), even simple joins can take minutes. Add a notification at the end and free yourself from waiting.

πŸ§ͺBatch Jobs and Experiments

When running parameter sweeps or looping through datasets for multiple countries/cities, insert a notification after each iteration to monitor progress, especially useful when working with remote or headless servers.

πŸ‘©β€πŸ’»Remote Notebooks

If your Jupyter Notebook is hosted on a cloud VM, university server, or even Google Colab, Telegram lets you stay updated without needing to keep the browser tab open.

This tiny automation can save hours of passive waiting and keep you informed even while multitasking, away from your desk, or working on other parts of your project.


Closing Thoughts

This Telegram notification setup is simple, secure, and surprisingly effective.

In research workflows like those in DEPRIMAP, where processing tasks can be long, unpredictable, and distributed, small automation like this help keep focus where it matters. Instead of checking your notebook tab every few minutes, you’ll get a message on your phone the moment it’s done. Telegram is easy to use, has cross-platform support, and has privacy; no need to deal with email servers or share passwords.

It takes just 5-10 minutes to set up and can save hours of passive waiting over time.

If you’re interested in trying it out, you can start with the example notebook and code from our GitHub repo. Feel free to adapt it to your own case, and if you build on top of this idea (e.g., notify on errors, looped batches, etc), we’d love to hear how you’ve extended it.

Happy coding – and happy not waiting!πŸ””

πŸ”— GitHub Repository

https://github.com/saiga143/telegram-jupyter-notify


No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *