Registry / devops / pyngrok

pyngrok

JSON →
library8.1.2pypypi✓ verified 27d ago

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 pyngrok
INSTALL
IMPORT
SIG · PYNGROK
P
pyngrok
devopspythonv8.1.2
Install
1.8s avg
Import
288ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v8.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.294s · 20.1MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.8s · import 0.282s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ngrok
✓ from pyngrok import ngrok
✗ import pyngrok.ngrok
The primary interface is directly accessible via `from pyngrok import ngrok`.
conf
✓ from pyngrok import conf
Used for global configuration settings like `auth_token` or `ngrok_path`.

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.

import os from pyngrok import ngrok, conf # Get your ngrok authtoken from the environment or replace with your actual token. # You can obtain one from https://ngrok.com/signup NGROK_AUTH_TOKEN = os.environ.get("NGROK_AUTHTOKEN", "YOUR_NGROK_AUTHTOKEN") if NGROK_AUTH_TOKEN == "YOUR_NGROK_AUTHTOKEN": print("WARNING: Please set the NGROK_AUTHTOKEN environment variable or replace 'YOUR_NGROK_AUTHTOKEN' in the code.") print(" Some ngrok features may be limited without an authtoken.") # Attempt to set the authtoken anyway, it might work for basic free-tier tunnels conf.get_default().auth_token = NGROK_AUTH_TOKEN else: ngrok.set_auth_token(NGROK_AUTH_TOKEN) try: # Open an HTTP tunnel to a local service running on port 8000 # Ensure a service is running on this port before connecting. http_tunnel = ngrok.connect(8000) print(f"ngrok tunnel is live: {http_tunnel.public_url}") # The tunnel will remain open until `ngrok.kill()` is called or the script exits. input("Press Enter to close the tunnel and exit...") except Exception as e: print(f"An error occurred: {e}") finally: # Disconnect any active ngrok tunnels and kill the ngrok process ngrok.kill() print("ngrok tunnel closed.")
ngrok --version
Debug
Known issues
breakingpyngrok version compatibility with ngrok binary. pyngrok 8.x aims to work with ngrok v3. If you have an older or conflicting ngrok binary on your system path, or if an older pyngrok (e.g., v7.x) installed ngrok v2, you might experience unexpected behavior or errors when trying to use v3-specific features.
fix
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.
affects: All versions, especially major upgrades
gotchaNgrok Authtoken is crucial for advanced features. Without an authenticated ngrok agent, features like custom subdomains, reserved addresses, or increased tunnel durations are unavailable. Failing to set the `NGROK_AUTHTOKEN` can lead to `ngrok` launching with limitations.
fix
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`.
affects: All versions
gotchaPyngrokNgrokError on process startup. This error (e.g., 'The ngrok process was unable to start') often indicates an issue with the underlying ngrok binary's configuration or environment, not necessarily a bug in pyngrok.
fix
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.
affects: All versions
gotchaTunnel connection refusal if no local service is running. If `ngrok.connect()` reports 'Failed to complete tunnel connection' or 'dial tcp 127.0.0.1:80: connect: connection refused', it means no service is actively listening on the target `localhost:port` specified.
fix
Ensure your local web server, API, or service is fully started and listening on the specified port *before* `ngrok.connect()` is called.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyngrok'
The pyngrok library is not installed in your current Python environment.
fix
Install pyngrok using pip: `pip install pyngrok`
pyngrok.exception.PyngrokNgrokError: The ngrok process was unable to start.
The underlying ngrok binary failed to start, often due to a configuration issue, missing dependencies, or an existing ngrok process occupying the API port (4040).
fix
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.
Failed to complete tunnel connection. The connection to <public_sub>.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:<port>. Make sure that a web service is running on localhost:<port> and that it is a valid address. The error encountered was: dial tcp 127.0.0.1:<port>: connect: connection refused.
ngrok successfully created a public tunnel, but no local service (e.g., a web server, Flask app) is listening on the specified localhost port, or the service started after pyngrok tried to connect.
fix
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.
TypeError: connect() got an unexpected keyword argument 'some_argument'
You are passing an unsupported or mistyped keyword argument to the `ngrok.connect()` method, or using syntax from an older pyngrok version that expected options in a dictionary format.
fix
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.
NgrokNgrokNotFound: ngrok binary not found!
The ngrok executable is not found in the expected locations by pyngrok, often because it hasn't been downloaded or installed correctly.
fix
Run `pyngrok.install_ngrok()` to download and install the ngrok binary, or ensure ngrok is installed and its path is accessible or configured correctly.
Upgrade
Version history
8.1.2latest on PyPI · released Apr 29, 2026
Audit
Dependencies
ngrok binaryrequiredpyngrok is a wrapper around the ngrok command-line tool. It manages the download and installation of the ngrok binary.
Agent activity
46 hits · last 30 days
node
42
Resources
pyngrok — pip install pyngrok · libregistry