Package: dbtunnel
dbtunnelProxy solution to run elegant Web UIs natively inside databricks notebooks.YOU CAN ONLY USE THIS IN DATABRICKS NOTEBOOKS WITH A RUNNING CLUSTERFOR SECURE ACCESS PLEASE USE A SINGLE USER CLUSTER (ANYONE WITH ATTACH CAN ACCESS THE UIs)DescriptionEasy way to test the following things on a databricks cluster and notebooksFramework Supportfastapi:fastapi.pygradio:gradio-demo.pystable diffusion webui:stable-diffusion-example.pystreamlit:streamlit_example.pynicegui:nicegui-example.pyflask:flask-app.pydash:dask-example.pybokeh:bokeh-example.pyshiny for python:shiny-python-example.pypanelsolara:solara-example.pychainlit:chainlit-foundation-model-rag-example.pycode-server on reposcode-server-example.pyEasy way to test out llm chatbots; look in examples/gradioFile or Directory SupportThis is to support decoupling your UI code from your databricks notebooks.
Usually will have a script_path argument instead of directly passing your "app" object. This is convenient for
shipping your app outside of a notebook.fastapi:fastapi.pygradio:gradio-demo.pystreamlit:streamlit_example.py: This is partially implemented, it only works with one file.nicegui:nicegui-example.pyflask:flask-app.pydash:dask-example.pybokeh:bokeh-example.pyshiny for pythonpanelsolara:solara-example.pychainlit:chainlit-foundation-model-rag-example.pyFrameworks that leverage asgiproxyDBTunnel provides a proxy layer using asgiproxy fork to support UIs that do not support proxy root paths, etc. It also
comes with a simple token based auth provider that only works on databricks to help you get access to user information.DBTunnel Proxy features:Token based auth: This is a simple token based auth that only works on databricks.
This token is saved in the app memory as a python TTLCache object.Support for frameworks that dont support proxies: This proxy solution intercepts requests and rewrites js and html files
to allow support for hosting behind proxies that are dynamic. This is a temporary measure before researching a way of
exposing root path details. Then this step will be skipped. If you are running into issues with this please file a github issue.Support for audit logging: This is simply logging tracked users and saving them to a file. Its yet to be implemented.Support for frameworks that do not support root pathsInject auth headers: This is to provide user information directly to your app via request object. Most frameworks
support the access to request object to access headers, etc.fastapigradiostreamlitniceguiflaskdashbokehshiny for pythonpanelsolarachainlitChatbot SupportYou must use A10 GPU instances or higherMistral-7bgradio-chat-mistral7b-demo.pyMixtral 8x7Bchainlit-foundation-model.pyLlama-2-7bmpt-7bStreaming support (vllm, etc.)Streaming support foundation model apiTypewriter effectTunnel Support:ngrokdevtunnelscloudflareddbtunnel custom relay (private only)SetupPlease do not use this in production!!Clone this repo into databricks reposGo to any of the examples to see how to use themEnjoy your proxy experience :-)If you want to share the link ensure that the other user has permission to attach to your cluster.Passing databricks auth to your app viainject_authYou can pass databricks user auth from your notebook session to any of the frameworks by doing the following:fromdbtunnelimportdbtunneldbtunnel.<framework>(<script_path>).inject_auth().run()For example:fromdbtunnelimportdbtunneldbtunnel.gradio(demo).inject_auth().run()This exposes the user information via environment variable DATABRICKS_HOST and DATABRICKS_TOKEN.Passing a warehouse to your app viainject_sql_warehouseYou can pass databricks warehouse auth from your notebook session to any of the frameworks by doing the following:fromdbtunnelimportdbtunneldbtunnel.<framework>(<script_path>).inject_sql_warehouse().run()This exposes the warehouse information via environment variable DATABRICKS_HOST, DATABRICKS_TOKEN and DATABRICKS_HTTP_PATH.Passing custom environment variables viainject_envYou can pass custom environment variables from your notebook to any of the frameworks by doing the following:fromdbtunnelimportdbtunneldbtunnel.<framework>(<script_path>).inject_env({"MY_CUSTOM_ENV":"my_custom_env_value"}).run()For example:fromdbtunnelimportdbtunneldbtunnel.gradio(demo).inject_env({"MY_CUSTOM_ENV":"my_custom_env_value"}).run()Keep in mind environment variables need to be strings!Exposing to internet using ngrokWARNING: IT WILL BE PUBLICLY AVAILABLE TO ANYONE WITH THE LINK SO DO NOT EXPOSE ANYTHING SENSITIVEThe reason for doing this is to test something with a friend or colleague who is not logged in into databricks.
The proxy option requires you to be logged in into databricks.Go tongrokand create an account and get an api token and a tunnel auth tokenYou can get a tunnel token fromhere.You can get an api token fromhere.Go to a databricks notebook:If you are using free tier of ngrok you can only have one tunnel and one session at a time so enablekill_all_tunnel_sessions=TrueTake a look at the full example herestreamlit-example-ngrok.pyfromdbtunnelimportdbtunnel# again this example is with streamlit but works with any frameworkdbtunnel.streamlit("<script_path>").share_to_internet_via_ngrok(ngrok_api_token="<ngrok api token>",ngrok_tunnel_auth_token="<ngrok tunnel auth token>").run()# if you need to kill tunnels because you are on free tier:# again this example is with streamlit but works with any frameworkdbtunnel.streamlit("<script_path>").share_to_internet_via_ngrok(ngrok_api_token="<ngrok api token>",ngrok_tunnel_auth_token="<ngrok tunnel auth token>",kill_all_tunnel_sessions=True,).run()Killing processes on a specific portfromdbtunnelimportdbtunneldbtunnel.kill_port(<portnumberasint>)Disclaimerdbtunnel is not developed, endorsed not supported by Databricks. It is provided as-is; no warranty is derived from using this package. For more details, please refer to the license.