ngrok#

class platypush.plugins.ngrok.NgrokPlugin(auth_token: str | None = None, ngrok_bin: str | None = None, region: str | None = None, **kwargs)[source]#

Bases: Plugin

Plugin to dynamically create and manage network tunnels using ngrok.

Requires:

  • pyngrok (pip install pyngrok)

Triggers:

__init__(auth_token: str | None = None, ngrok_bin: str | None = None, region: str | None = None, **kwargs)[source]#
Parameters:
  • auth_token – Specify the ngrok auth token, enabling authenticated features (e.g. more concurrent tunnels, custom subdomains, etc.).

  • ngrok_bin – By default pyngrok manages its own version of the ngrok binary, but you can specify this option if you want to use a different binary installed on the system.

  • region – ISO code of the region/country that should host the ngrok tunnel (default: us).

close_tunnel(tunnel: str)[source]#

Close an ngrok tunnel.

Parameters:

tunnel – Name or public URL of the tunnel to be closed.

create_tunnel(resource: int | str = 80, protocol: str = 'tcp', name: str | None = None, auth: str | None = None, **kwargs) dict[source]#

Create an ngrok tunnel to the specified localhost port/protocol.

Parameters:
  • resource

    This can be any of the following:

    • A TCP or UDP port exposed on localhost.

    • A local network address (or address:port) to expose.

    • The absolute path (starting with file://) to a local folder - in such case, the specified directory will be served over HTTP through an ngrok endpoint (see https://ngrok.com/docs#http-file-urls).

    Default: localhost port 80.

  • protocol – Network protocol (default: tcp).

  • name – Optional tunnel name.

  • auth – HTTP basic authentication credentials associated with the tunnel, in the format of username:password.

  • kwargs – Extra arguments supported by the ngrok tunnel, such as hostname, subdomain or remote_addr - see the ngrok documentation for a full list.

Returns:

{
  "name": "tcp-8080-my-tunnel",
  "protocol": "tcp",
  "url": "tcp://8.tcp.ngrok.io:12345"
}

get_tunnels()[source]#

Get the list of active ngrok tunnels.

Returns:

[
  {
    "name": "tcp-8080-my-tunnel",
    "protocol": "tcp",
    "url": "tcp://8.tcp.ngrok.io:12345"
  }
]

kill_process()[source]#

The first created tunnel instance also starts the ngrok process. The process will stay alive until the Python interpreter is stopped or this action is invoked.