Skip to content

Commit

Permalink
Documentation updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdlaird committed Jan 5, 2025
1 parent 620e4bf commit 5b77819
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
43 changes: 32 additions & 11 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ and this returned object has a reference to the public URL generated by ``ngrok`
ssh_tunnel = ngrok.connect("22", "tcp")
# Open a named tunnel from the config file
named_tunnel = ngrok.connect(name="my_tunnel_name")
named_tunnel = ngrok.connect(name="my-config-file-tunnel")
The :func:`~pyngrok.ngrok.connect` method takes ``kwargs`` as well, which allows us to pass
additional tunnel configurations that are supported by ngrok,
`as documented here <#tunnel-configurations>`__.
additional tunnel configurations that are supported by ``ngrok`` (or the ``name`` of a tunnel defined in ``ngrok``'s
config file), `as documented here <#tunnel-configurations>`__.

.. note::

Expand Down Expand Up @@ -164,7 +164,7 @@ Tunnel Configurations
---------------------

It is possible to configure the tunnel when it is created, for instance adding authentication,
a subdomain, or other additional `tunnel configurations that are supported by ngrok <https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_.
a subdomain, or other additional `tunnel configurations that are supported by ngrok <https://ngrok.com/docs/agent/config/v2/#common-tunnel-configuration-properties>`_.
This is accomplished by passing them as ``kwargs`` to :func:`~pyngrok.ngrok.connect`, then they will be used as
properties for the tunnel when it is created.

Expand All @@ -180,6 +180,17 @@ circuit breaker.
auth="username:password",
circuit_breaker=50)
If we have already have a tunnel `defined in ngrok's config file <https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_,
we can start it by its ``name``.

.. code-block:: python
from pyngrok import conf, ngrok
# <NgrokTunnel: "http://<public_sub>.ngrok.io" -> "http://localhost:??">
ngrok_tunnel = ngrok.connect(name="my-config-file-tunnel")
The ``ngrok`` Process
=====================

Expand Down Expand Up @@ -308,13 +319,13 @@ set ``ngrok_version`` in :class:`~pyngrok.conf.PyngrokConfig`.
conf.get_default().ngrok_version = "v2"
Setting the ``authtoken``
-------------------------
Setting the ``authtoken`` or ``api_key``
----------------------------------------

Running ``ngrok`` with an auth token enables additional features available on our account (for
instance, the ability to open multiple tunnels concurrently, or use `ngrok's Edges <https://ngrok.com/docs/network-edge/edges/>`_).
We can obtain our auth token from the `ngrok dashboard <https://dashboard.ngrok.com>`_ and install it to ``ngrok``'s
config file.
Running ``ngrok`` with an auth token and/or API key enables additional features available on our account (for
instance, the ability to open multiple tunnels concurrently, custom domains, use of `ngrok's Edges <https://ngrok.com/docs/network-edge/edges/>`_),
etc. We can obtain our auth token from the `ngrok dashboard <https://dashboard.ngrok.com>`_ and install it to
``ngrok``'s config file.

.. code-block:: python
Expand All @@ -323,23 +334,33 @@ config file.
# Setting an auth token allows us to open multiple
# tunnels at the same time
ngrok.set_auth_token("<NGROK_AUTHTOKEN>")
# Setting an API key allows us to use labeled tunnels
ngrok.set_api_key("<NGROK_API_KEY>")
# <NgrokTunnel: "https://<public_sub1>.ngrok.io" -> "http://localhost:80">
ngrok_tunnel1 = ngrok.connect()
# <NgrokTunnel: "https://<public_sub2>.ngrok.io" -> "http://localhost:8000">
ngrok_tunnel2 = ngrok.connect("8000")
# <NgrokTunnel: "https://<public_sub3>.ngrok.io" -> "http://localhost:??">
ngrok_tunnel2 = ngrok.connect(name="some-edge-tunnel")
We can also override ``ngrok``'s installed auth token using :class:`~pyngrok.conf.PyngrokConfig`.
For a more complete example of using labeled tunnels with the API key, see `the section on ngrok's Edges <#ngrok-s-edges>`_.

We can also override ``ngrok``'s installed auth token or API key using :class:`~pyngrok.conf.PyngrokConfig`.

.. code-block:: python
from pyngrok import conf, ngrok
conf.get_default().auth_token = "<NGROK_AUTHTOKEN>"
conf.get_default().api_key = "<NGROK_API_KEY>"
# <NgrokTunnel: "https://<public_sub>.ngrok.io" -> "http://localhost:80">
ngrok_tunnel = ngrok.connect()
Lastly, we could instead define ``NGROK_AUTHTOKEN`` or ``NGROK_API_KEY`` as environment variables, if we don't want to
define them in code.

Setting the ``region``
----------------------

Expand Down
4 changes: 2 additions & 2 deletions pyngrok/ngrok.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def set_auth_token(token: str,
pyngrok_config: Optional[PyngrokConfig] = None) -> None:
"""
Set the ``ngrok`` auth token in the config file, enabling authenticated features (for instance,
more concurrent tunnels, custom subdomains, etc.).
opening multiple tunnels concurrently, custom domains, etc.).
If ``ngrok`` is not installed at :class:`~pyngrok.conf.PyngrokConfig`'s ``ngrok_path``, calling this method
will first download and install ``ngrok``.
Expand Down Expand Up @@ -320,7 +320,7 @@ def connect(addr: Optional[str] = None,
:param proto: A valid `tunnel protocol
<https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_, defaults to "http".
:param name: A friendly name for the tunnel, or the name of a `ngrok tunnel definition
<https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_ to be used.
<https://ngrok.com/docs/agent/config/v2/#tunnel-configurations>`_ defined in ``ngrok``'s config file.
:param pyngrok_config: A ``pyngrok`` configuration to use when interacting with the ``ngrok`` binary,
overriding :func:`~pyngrok.conf.get_default()`.
:param options: Remaining ``kwargs`` are passed as `configuration for the ngrok
Expand Down

0 comments on commit 5b77819

Please sign in to comment.