pyngrok - a Python wrapper for ngrok
install
pyngrok is available on PyPI and can be installed using pip.
pip install pyngrok
The package comes with support for downloading and using its own version of ngrok, or you can specify a path to a binary when establishing a connection.
connect
from pyngrok import ngrok
public_url1 = ngrok.connect() # tunnel to port 80
public_url2 = ngrok.connect(5000) # tunnel to port 5000
The connect method also takes an optional options dictionary, which can accept any arbitrary parameter defined in the ngrok documentation.
Retreiving a list of active NgrokTunnel objects is just as easy.
tunnels = ngrok.get_tunnels()
public_url = tunnels[0].public_url # a public ngrok URL that tunnels to port 80 (ex. http://64e3ddef.ngrok.io)
The ngrok process itself is also available to you in the NgrokProcess object. This object also holds reference to the client API URL.
ngrok_process = ngrok.get_ngrok_process()
api_url = ngrok_process.api_url # the ngrok client API URL (usually http://127.0.0.1:4040)
After the ngrok process is invoked (by calling connect or get_tunnels), it will remain alive until the Python process terminates. If your app is long-lived, this means the tunnels will stay open until you call
ngrok.disconnect(5000) to shutdown a port, ngrok.kill() to end the ngrok process, or kill the entire process.
If you have a short-lived app, like a CLI, but want the tunnels to remain open until the user terminates, do the following on the ngrok_process retrieved above:
ngrok_process.process.wait() # block until CTRL-C or some other terminating event
authtoken
If you have a ngrok account, you can set your authtoken to enable your account's features with this package.
from pyngrok import ngrok
ngrok.set_auth_token("807ad30a-73be-48d8")
config file
By default, the ngrok config file lives in the .ngrok2 folder in your home
directory. If you would like to specify a custom config file, pass the config_path parameter:
from pyngrok import ngrok
CONFIG_PATH = "/opt/ngrok/config.yml"
ngrok.connect(config_path=CONFIG_PATH)
binary path
If you would like to use your own ngrok binary instead of the one that comes with this package, you can
do this in one of two ways. Either pass the ngrok_path argument to each command:
from pyngrok import ngrok
NGROK_PATH = "/usr/local/bin/ngrok"
ngrok.get_tunnels(ngrok_path=NGROK_PATH)
or override the DEFAULT_NGROK_PATH variable:
from pyngrok import ngrok
ngrok.DEFAULT_NGROK_PATH = "/usr/local/bin/ngrok"
ngrok.connect(5000)
Metadata
Release files for pyngrok 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyngrok-0.3.2.tar.gz | 6.3 kB | Details |
Release files / pyngrok-0.3.2.tar.gz
| Download URL | pyngrok-0.3.2.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ae8cbd82e937d24431c08bceef4bd095d68f57a6cb88e6f8d57a0702103d9221
|
|
BLAKE2b-256 checksum How to use checksums |
01f87a34071fe53349ff1d185de7bb9425b8a6475ec97eff776dc798ab1a6daa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3
|