flask-ngrok3 0.3.1
A successor to flask-ngrok and flask-ngrok2 for demo Flask apps using ngrok.
Keywords: flask ngrok demo

# flask-ngrok3
[![Run it button](https://img.shields.io/badge/-run%20it%20now-brightgreen.svg?longCache=true&style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAF96VFh0UmF3IHByb2ZpbGUgdHlwZSBBUFAxAAAImeNKT81LLcpMVigoyk/LzEnlUgADYxMuE0sTS6NEAwMDCwMIMDQwMDYEkkZAtjlUKNEABZiYm6UBoblZspkpiM8FAE+6FWgbLdiMAAAF4ElEQVRYhe2WS2xdVxWGv7X2Pvf6Ppw4dqMAKkFJDWmcpqSxS1RhYVxBZ0Wo0gVUQBmCIhBCnRAmhQl0QFGYIMEQlIAcFcQkiFfd9CHR2qalqZ2octzmVcd52YmN7+OcvReDe6/jxEkoHQASXZOjc/ZZ+1/Pfy14X/7fRe50aIZCpfnPYaByOIpg71qnqWgIJtxZb/UFYjbkb39ecWYVt+b76JC3J9Hb6w15s7UO3/DBRoe8DB/N2u+1yQd6nerd4sRb1AXfqJ6U+4/Ntw0VwZoeY+3I1MZ33JMv+82IL4QYUpdlc+x841g7AjdjyM3gNt5fjJ3xm5j7MsK92uESFKgbMbXLqD0fgxxI+saet/H+RAYmUgCbuv+rht9nKv1a9AkigEE1YMHetBgO6oVzP5bhi0s2ipdhshUDVsBP9A9H0V9ol7+bWsTqEcNCK3uqXoW8QiLEhfR7btv4922yb3PQjkNuQ+6TpGDVgJmFVYFVzTuhqNjlxqyofUW2/e3ZthHSBg/jvY/rxp6DGMRaaCA4TEzEzBABM1pPdZqkqQwk/7j6TiwXp3RdviteSxsIrvVnXG0AmBDJtJjkCCmcfusx+fSV39oovhWBDYO46gsUNxPWdwWJUQHTslecQDDwAtcyWOexq9lT+rGx/eHE7hkt57bExayBSg7INBFP0TXDLwL1SKyGYKgTi5leOO2pLUCxdJ8Mzk82qz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okFMWh4ogohhBRRBx5cazTHA3OIPlPtcFlmOzfW0gyu4zEF2KUA8n28aM3LCR/KX0Js31YeJC8dKw0cM0M9Di4X1Lu+ok8dLa6ZiG52Yj2+5qVrFA9KR+580pmL27YTCPdQqwWcD4llGblM1emrmNcB7+lvPellDsvpaPccim9o5ihbUAbqbh3c4E9idoIzgzXev7X6f59+d+WfwIud1aCxWHYtAAAAABJRU5ErkJggg==)](https://colab.research.google.com/github/Partycode/flask-ngrok3/blob/master/examples/flask_ngrok3_example.ipynb)

[![PyPI version](https://badge.fury.io/py/flask-ngrok3.svg)](https://badge.fury.io/py/flask-ngrok3)

The successor for [flask-ngrok](https://github.com/gstaff/flask-ngrok) and [flask-ngrok2](https://github.com/MohamedAliRashad/flask-ngrok2) for making demo Flask apps from personal machine.

## Compatability
Python 3.6+ is required.

## Installation

```bash
pip install flask-ngrok3
```
### Inside Jupyter / Colab Notebooks
Notebooks have [an issue](https://stackoverflow.com/questions/51180917/python-flask-unsupportedoperation-not-writable) with newer versions of Flask, so force an older version if working in these environments.
```bash
!pip install flask==0.12.2
```
See the [example notebook](https://colab.research.google.com/github/Partycode/flask-ngrok3/blob/master/examples/flask_ngrok3_example.ipynb) 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  
```python
# 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:
```bash
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 -
```