Reputation: 21
How can I start ngrok with python and copy the public link just executing python script ?
I tried with subprocess but it only launched the 'ngrok http 80' command , I want to copy the public link.
Upvotes: 2
Views: 1275
Reputation: 1293
Use the pyngrok
library, which you can install with pip install pyngrok
or put in your requirements file. Then open a tunnel and grab the public URL you're asking for like this:
from pyngrok import ngrok
# Open a HTTP tunnel on the default port 80
# <NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:80">
http_tunnel = ngrok.connect()
print(" * ngrok tunnel \"{}\" -> \"http://127.0.0.1\"".format(http_tunnel.public_url))
Upvotes: 2