pyngrok is a Python wrapper for ngrok, a reverse proxy tool that opens secure tunnels from public URLs to localhost. It manages its own ngrok binary, making the ngrok client available via a convenient Python API and the command line. This allows for rapid development, testing webhooks, and exposing local services. The current version is 8.0.0, and the library is actively maintained.
pip install pyngrokVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize pyngrok, set an ngrok authtoken (preferably via an environment variable), and open a basic HTTP tunnel to a local port. It then prints the public ngrok URL and waits for user input before gracefully closing the tunnel. An ngrok authtoken is highly recommended for full functionality and can be obtained from the ngrok dashboard.
Ensure that `pyngrok` is managing its own `ngrok` binary by checking `ngrok`'s version (`ngrok -v` in terminal, looking for `PYNGROK VERSION`). If conflicts occur, reorder your `$PATH` or explicitly manage `ngrok`'s binary path via `pyngrok.conf.get_default().ngrok_path`. If upgrading, delete the old `ngrok` binary to force `pyngrok` to download the latest version.
Obtain an authtoken from the ngrok dashboard and set it using `ngrok.set_auth_token("YOUR_AUTHTOKEN")` or by exporting it as an environment variable `NGROK_AUTHTOKEN`.Debug by running the `ngrok` command directly from your terminal to see its output and error messages. Ensure no other processes are binding to the `ngrok`'s API port (default 4040). Check `ngrok`'s logs for more detailed error information. Ensure `ngrok` has necessary permissions to run.
Ensure your local web server, API, or service is fully started and listening on the specified port *before* `ngrok.connect()` is called.
Install pyngrok using pip: `pip install pyngrok`
Check ngrok's logs for more details by enabling pyngrok logging (`logging.basicConfig(level=logging.DEBUG)`), ensure no other ngrok process is running, and verify your ngrok authtoken is correctly set using `ngrok.set_auth_token("YOUR_AUTHTOKEN")` if needed. Running `ngrok start --none --log stdout` directly in the terminal can also help debug ngrok startup issues.Ensure your local web service is fully started and listening on the exact port specified (e.g., `80`, `5000`) *before* calling `ngrok.connect()`. You might need to add a small delay or a retry mechanism in your code to wait for the local service to become available.
For pyngrok 8.0.0, pass tunnel configurations directly as keyword arguments. Refer to the pyngrok documentation for the correct and supported keyword arguments for `ngrok.connect()` (e.g., `addr`, `proto`, `auth`, `subdomain`). Remove or correct the 'some_argument' keyword.
Run `pyngrok.install_ngrok()` to download and install the ngrok binary, or ensure ngrok is installed and its path is accessible or configured correctly.