Ngrok Module#

The ngrok Agent SDK for Python

ngrok.connect(addr=None, proto=None, **options)#

Alias for forward()

See forward() for the full set of options.

ngrok.default(session=None)#

Create a default HTTP listener. Optionally pass in a connected Session to use.

Returns the listener if no async loop is running, otherwise returns a Task to await with a listener result.

Parameters:

session (Session or None) – The Session to use to create the listener.

Returns:

The created listener.

Return type:

Listener

ngrok.disconnect(url=None)#

Shut down Listener with the given url, or if no url is given, shut down all Listeners.

Parameters:

url (str or None) – The url of the Listener to disconnect, or None to disconnect all listeners.

ngrok.fd(session=None)#

Create a default HTTP listener and get its file descriptor. Optionally pass in a connected Session to use.

Returns the file descriptor if no async loop is running, otherwise returns a Task to await with a file descriptor result.

Parameters:

session (Session or None) – The Session to use to create the listener.

Returns:

The file descriptor of the created listener’s forwarding socket.

Return type:

int

ngrok.forward(addr=None, proto=None, **options)#

Establish ngrok ingress, returning an Listener object.

Parameters:
  • addr (int, str or None) – The address to forward traffic to, this can be an integer port, or a host:port string, or url, e.g. “80”, “localhost:8080”, “https://192.168.1.100:8443”, or “unix:/path/to/unix.sock”

  • proto (str or None) – The protocol type of the Listener, one of “http”, “tcp”, “tls”, “labeled”

  • options – A dict of options to pass to the Listener.

Returns:

A Listener object.

ngrok.getsockname(session=None)#

Create a default HTTP listener and get its socket name. Optionally pass in a connected Session to use.

Returns the socket name if no async loop is running, otherwise returns a Task to await with a socket name result.

Parameters:

session (Session or None) – The Session to use to create the listener.

Returns:

The name of the created listener’s forwarding socket.

Return type:

str

ngrok.kill()#

Shut down all listeners and sessions.

ngrok.listen(server=None, listener=None)#

Create and return a listening default HTTP listener. Optionally pass in an object with a “server_address” attribute, such as a http.server.HTTPServer, and the listener will forward TCP to that server_address. Optionally also pass in a previously created listener.

Returns the created listener if no async loop is running, otherwise returns a Task to await with a listener result.

Parameters:
  • server (http.server.HTTPServer or None) – The server to link with a listener.

  • listener (Listener or None) – The Listener to use to link with the server.

Returns:

The listener linked with the server, or a Task to await for said listener.

Return type:

Listener or Task

ngrok.log_level(level='INFO')#

Set the log level for the bridge to Python logging. The log level defaults to INFO, it can be set to one of ERROR, WARN, INFO, DEBUG, or TRACE.

Parameters:

level (str) – The logging level to use (ERROR, WARN, INFO, DEBUG, or TRACE).

ngrok.pipe_name()#

Create a path name to use for pipe forwarding. This will be a file path in the temp directory on unix-like systems, or a named pipe on Windows. Files will be removed at program exit.

ngrok.werkzeug_develop(listener=None)#

Set the WERKZEUG_SERVER_FD environment variable with a file descriptor from a default HTTP listener. Also sets WERKZEUG_RUN_MAIN to “true” to engage the use of WERKZEUG_SERVER_FD.

Returns the created listener if no async loop is running, otherwise returns a Task to await with a listener result.

Parameters:

listener (Listener or None) – The Listener to use to link with the werkzeug server.

Returns:

The listener linked with the server, or a Task to await for said listener.

Return type:

Listener or Task