ngrok / ngrok-python

Embed ngrok secure ingress into your Python apps with a single line of code.
https://ngrok.com
Apache License 2.0
103 stars 19 forks source link

Specify an `edge` for the connection #83

Closed jimkring closed 6 months ago

jimkring commented 6 months ago

In the parameters for ngrok.forward() (see full configuration param's list) I don't see any option to specify an edge or other label for the tunnel.

Is this possible from the python api?

bobzilladev commented 6 months ago

Hello, thanks for your question! There is a labels kwarg that can be used, here's an example: ngrok.forward("localhost:8080", proto="labeled", labels="edge:edghts_2G...", authtoken_from_env=True)

We'll get the documentation updated to add it. Thanks again!

jimkring commented 6 months ago

That's great it's already supported by the API!

A couple other points:

  1. I created a suggestion to make this a named parameter.

  2. It would probably make sense to add an option to the ngrok dashboard for creating a tunnel using the Python (Rust, Go, etc.) APIs, as described in the screenshot below:

2024-01-04_12-45-55

jimkring commented 6 months ago

@bobzilladev another thought:

  1. The example you provided labels="edge:edghts_2G..." shows a truncated string. What's the format for passing multiple labels? e.g. is it a comma-delimited list like labels="key1:value1,key2:value2"?
bobzilladev commented 6 months ago

Will try to answer these questions here:

  1. For a more concrete style the builder pattern configuration can be used, here's an example of that which is more explicit: ngrok-labeled.py
  2. Adding to the start a tunnel pane has been discussed, for now the python getting started page is a dashboard resource to help initial setup: dashboard.ngrok.com/get-started/setup/python
  3. The labels kwarg can take an array as well, labels=["key1:value1", "key2:value2"]

Hopefully that's useful, thanks for the feedback!

jimkring commented 6 months ago

Yes, thanks!