zrok/sdk/python/examples/proxy/proxy.ipynb
2025-01-29 04:33:24 -05:00

101 lines
2.3 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "52d42237",
"metadata": {},
"outputs": [],
"source": [
"! pip install zrok"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0a33915c",
"metadata": {},
"outputs": [],
"source": [
"\n",
"import zrok\n",
"from zrok.proxy import ProxyShare\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0db6b615",
"metadata": {},
"outputs": [],
"source": [
"\n",
"target_url = \"http://127.0.0.1:8000/\"\n",
"unique_name = \"myuniquename\" # a name to reuse each run or 'None' for random\n",
"share_mode = \"public\" # \"public\" or \"private\"\n",
"frontend = \"public\" # custom domain frontend or \"public\"\n",
"\n",
"if unique_name.lower() == \"none\":\n",
" unique_name = None\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d3efcfa5",
"metadata": {},
"outputs": [],
"source": [
"\n",
"zrok_env = zrok.environment.root.Load() # Load the environment from ~/.zrok\n",
"\n",
"proxy_share = ProxyShare.create(\n",
" root=zrok_env,\n",
" target=target_url,\n",
" frontends=[frontend],\n",
" share_mode=share_mode,\n",
" unique_name=unique_name,\n",
" verify_ssl=True # Set 'False' to skip SSL verification\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21966557",
"metadata": {},
"outputs": [],
"source": [
"\n",
"if share_mode == \"public\":\n",
" print(f\"Access proxy at: {', '.join(proxy_share.endpoints)}\")\n",
"elif share_mode == \"private\":\n",
" print(f\"Run a private access frontend: 'zrok access private {proxy_share.token}'\")\n",
"\n",
"proxy_share.run()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}