flask-ngrok3

A successor to flask-ngrok and flask-ngrok2 for demo Flask apps using ngrok.


Keywords
flask, ngrok, demo
License
Apache-2.0
Install
pip install flask-ngrok3==0.3.1

Documentation

flask-ngrok3

Run it button

PyPI version

The successor for flask-ngrok and flask-ngrok2 for making demo Flask apps from personal machine.

Compatability

Python 3.6+ is required.

Installation

pip install flask-ngrok3

Inside Jupyter / Colab Notebooks

Notebooks have an issue with newer versions of Flask, so force an older version if working in these environments.

!pip install flask==0.12.2

See the example notebook for a working example.

Quickstart

  1. Import with from flask_ngrok3 import run_with_ngrok
  2. Add run_with_ngrok(app) to make your Flask app available upon running
  3. Now you can run with your custom host app.run(host='192.168.1.5')
  4. Also, you can get ngrok address on startup
# flask_ngrok3_example.py
from flask import Flask
from flask_ngrok3 import run_with_ngrok, get_host

app = Flask(__name__)
run_with_ngrok(app)  # Start ngrok when app is run

@app.route("/")
def hello():
    return "Hello World!"

def get_ngrok_host():
    print(f"ngrok host is: {get_host()}")

app.before_first_request(get_ngrok_host)  # Register function for run before the first request

if __name__ == '__main__':
    app.run()

Running the example:

python flask_ngrok3_example.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Running on http://<random-address>.ngrok.io
 * Traffic stats available on http://127.0.0.1:4040 
ngrok host is: http://<random-address>.ngrok.io
127.0.0.1 - - [...] "GET / HTTP/1.1" 200 -