Skip to main content
This guide shows you how to use ngrok from a Google Colab notebook using the pyngrok library. It covers installing pyngrok, adding your ngrok authtoken, and starting a tunnel from Colab.

What you’ll need

1. Install pyngrok in your notebook

In a Colab cell, install pyngrok:
!pip -q install pyngrok

2. Add your ngrok authtoken

In a new cell, add your ngrok authtoken:
from pyngrok import ngrok

ngrok.set_auth_token("YOUR_AUTHTOKEN")

3. Start a tunnel

Start a tunnel to your local port (for example, 8080):
tunnel = ngrok.connect(8080)
print(tunnel.public_url)
Use the printed URL to access your service through ngrok.