Mobile Monitoring Solutions

Close this search box.

Ngrok JavaScript and Python SDKs Aim to Turn Ingress into a High-Level Abstraction

MMS Founder
MMS Sergio De Simone

Article originally posted on InfoQ. Visit InfoQ

The new ngrok JavaScript and Python SDKs enable embedding secure ingress into apps with a single line of code. It includes out-of-the-box support for capabilities such as high performance, resilience, security and observability, allowing developers to focus on their functional requirements.

The new SDKs provide a native mechanism for apps to deliver their services or for APIs to publish their endpoints through ngrok’s global network. This is in addition to the stand-alone ngrok service which can be used through the command line or as a Kubernetes Ingress Controller. The SDKs can be used for example to provide ingress to customer’s developer environments, to APIs in customer networks, or to APIs on devices running on external networks.

Thanks to the ngrok SDKs, developers need not concern themselves with low-level, non-functional details such as network primitives, IPs, NATs, certificates, load balancers, or ports, says ngrok.

Declaring ingress, which encompasses non-functional capabilities such as high performance, resilience, security and observability needed for flawless delivery of their software, directly in the application itself, radically simplifies the development process.

According to ngrok, the SDKs allow developers to precisely define the expected behavior between their applications and the ingress layer. Furthermore, by decoupling application ingress from the hosting environment, the ngrok SDKs enable platform independence and portability.

The following snippet shows how you can distribute a “Hello World” app using ngrok-python by simply calling ngrok.forward() on the same port where the HTTPServer is listening:

from http.server import HTTPServer, BaseHTTPRequestHandler
import ngrok, os
import asyncio

class HelloHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        body = bytes("Hello", "utf-8")
        self.protocol_version = "HTTP/1.1"
        self.send_header("Content-Length", len(body))

server = HTTPServer(("localhost", 8080), HelloHandler)
listener = ngrok.forward("localhost:8080", authtoken_from_env=True)

Calling ngrok.forward() creates a secure and persistent outbound TLS connection to ngrok’s ingress-as-a-service platform, similar to what the ngrok agent would do when used through the command line.

Ngrok says they validated the design of their SDKs by collecting feedback from several open-source Python and JavaScript communities, including Stable Diffusion Web UI, Text Generation Web UI, Twurple, and Solana Payments App.

About the Author

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.