Python Jupyter Notebook expose local data in the web? - python

I'm a total noob at Python, I just downloaded Anaconda and started to use Jupyter Notebook.
I was wondering: since Jupyter Notebook looks web based, should I have any privacy concerns using it? i.e. are the data on my pc exposed out in the web?

You probably shouldn't worry about running notebooks on your localhost. If you want more info (e.g. if you ever intend to run your notebook at a remote server), this link will give you some insight regarding security concerns.
TL;DR: no, your data are not exposed.

Related

What's the best way of sharing jupyter notebook script with others to be able to run it on their windows computer?

I just wrote a script in jupyer notebook and I'm wondering what's the best format I should save this file as if I want to share it with other people so they can run it on their windows computer? I tried to convert my .ipynb to both .py and .exe, but none seem to work... maybe I'm doing something wrong.
Converting a Jupyter Notebook to a .py or .exe file would make no sense, as notebooks are used for the purpose to execute certain blocks of code on click. You could convert the notebook and it's output to a .pdf File, as you can read here: How to convert IPython notebooks to PDF and HTML?
If you want to port your Jupyter Notebook to a Python file, you'd have to make sure that you include all the code in the .py file, which is written down in the notebook as well. Keep in mind that, when using a regular Python File, things obviously won't look as great as in Jupyter.
The best way to share your Notebooks, would be to send them the actual file, so they can open the notebook in Jupyter notebook, or - in case they don't want to install Jupyter or Python on their device - they could use an online version of Jupyter Notebook like: https://nbviewer.jupyter.org/ - There are multiple websites available, which offer that kind of service.
You can try to use Mercury framework for converting Jupyter Notebook into web application. The Mercury can generate the widgets for your notebook, so don't need to use GUI packages (like tkinter). The widgets are generated by YAML header. Widgets are connected with variables in the notebook code. Your users can change the widgets values and execute the notebook. The final result can be easily exported to PDF. You can read more in the tutorial on how to share Jupyter Notebook with non-technical users.
The example notebook with YAML header
The example notebook converted to web app
Please notice that notebook's code is hidden (show-code: False in the YAML).
The Mercury can be easily deployed to Heroku or any cloud provider (Digital Ocean, GCP, Azure, AWS), please check the docs for details. You just send the server URL to share the app.

How to allow users to run jupyter notebooks stored in my database on my server?

I have a problem and I need a hint how to approach the problem.
I have django application, in which I have sme jupyter notebooks stored in my database. At this point, users can download notebooks and run them on their compuers.
I would like to add functionality, where user could run notebook online. I was thinking of two solutions:
first one is to use some free to use online service, like google colab, but I haven't found any with api where I could send file from my database (maybe you know about some?),
second is to run jupyter hub on my server. I saw how to run jupyter hub remotely, but I don't know how to grant users the access, so they can run notebooks simultaneously, and they don't have access to server itself thorugh it, and do all of this in django.
Do you have any hints that could help me get this functionality?
JupyterHub is a good approach if you trust your users. However, if you want to run untrusted code (like Google Colab does), you need sandboxing. In that case, you can use a Docker image to run notebooks. For example, mikebirdgeneau/jupyterlab. And there is a docker-compose file example: https://github.com/mikebirdgeneau/jupyterlab-docker/blob/master/docker-compose.yml

Hosting interactive jupyter notebook on private website

I currently run a personal website using Wordpress (but hosted on siteground) that is a set of engineering study guides. I would like to move towards making these study guides interactive (i.e. refreshing graphics based on sliders, doing basic calculations to indicate if a design works or not, so I need numpy). A friend recommended that I utilize Jupyter notebooks for this purpose, as you can both render LaTeX (which I'm currently using Mathjax with Wordpress to do), as well as have the types of interactive graphics I want using either Bokeh or Plotly.
While I've seen tutorials for sharing notebooks on specific servers, what I'm after is being able for others to run my notebook in their browser (read-only), where the notebook is privately hosted.
I'm still not sure if Jupyter is the correct avenue to accomplish what I want, so I'm open to other suggestions (someone also recommended using Julia, but I've seen fewer examples of this).
I agree with your friend that Jupyter Notebooks is an excellent approach. And while it's by no means the only method to accomplish what you're after, I'm hard-pressed to come up with an immediate alternative that doesn't require significant work to set up.
I can think of three primary methods of using Jupyter Notebooks which suit your needs:
1. Azure Notebooks
Microsoft has a new service called Azure Notebooks, which is (currently) totally free.
Azure Notebooks boasts the complete functionality of Jupyter Notebooks, and in addition to Python, users can also program cells in R and F#. As for typical usage of the service, here's a snippet from their FAQ:
Jupyter (formerly IPython), is a multi-lingual REPL on steroids. This is a free service that provides Jupyter notebooks along with supporting packages for R, Python and F# as a service. This means you can just login and get going since no installation/setup is necessary. Typical usage includes schools/instruction, giving webinars, learning languages, sharing ideas, etc. The service is provided by the Python team # Microsoft, which is part of the Data Group.
2. nbviewer
The top banner of the main Jupyter site contains a link link to an application called nbviewer.
Evidently, you can create your markdown / Jupyter syntax as a discrete page somewhere else, feed the URL to your page into nbviewer, and it'll render it for you right there in the results. If I were going to use this, I would either;
Create a discrete WordPress page for my Jupyter syntax, then feed that into nbviewer; or, more likely
Use GitHub to host my Jupyter Notebook pages (mainly for posterity and version control, over the Gist option), and use the raw text link as the source to feed into nbviewer.
3. Hosting Your Own Solution
If you're technically savy enough, I'd recommend this approach over nbviewer.
When you launch Jupyter Notebooks on your own machine, you access it through your browser using the default URL of http://localhost:8888. That means there must exist some mechanism to expose that port to external users, and allow them to have access to your Notebook, using the exact same interface. Two methods of doing so:
Using Jupyter Notebooks public server
Remotely accessing your normal Jupyter Notebook
Hope that helps! I'm curious to know if any of these options works out for you.
The Iodide Project (and subsequently, Pyodide) are two projects that aim to allow this. They're still in development, but might be worth looking into.
You can try to use Mercury framework. It allows you to transform notebooks into web applications (with interactive widgets). You need to add YAML header to the beginning of the notebook. Based on YAML the widgets will be generated. Your users can change widgets values and click Run button to execute the notebook with new inputs. You can decide whether to show or hide code for your users. You can serve multiple notebooks with Mercury on single server. It is based on Django so can be easily deployed on any server/cloud.
The example notebook:
The generated application for the above notebook:
The screenshot of app/notebooks gallery in the Mercury:

How to use Google Colaboratory server as python interpreter in Python IDE?

Google Colaboratory currently by default provides Jupyter notebook like interface for code development. But I feel that code development on this interface without advanced IDE features is constraining.
If I can use Google Colaboratory as a remote python console server for code development in IDE like Spyder or Pycharm it will be great. How do I do this?
I don't know if that's possible but you can use the PyCharm IDE supports this type of interface and features. Plus, it provides many more features. Please check out https://www.jetbrains.com/help/pycharm/using-ipython-notebook-with-product.html.
Google Collaboratory cannot be used as a remote python console.
Check out this FAQ which states clearly that it is just a Jupyter notebook environment.

How to enable shared trust in Jupyter notebook?

In our group we have a common Jupyter server running on a machine in the local network. Two or three people write and edit notebooks collaboratively using their individual PCs and browsers.
Now the Jupyter/IPython security model does not trust notebooks written by others unless you explicitly enable trust (therefore re-writing the notebook).
How can my colleagues open a notebook which I authored without re-writing the key in the notebook?
The manual provides a tiny hint that one can use
c.NotebookApp.secret_file = "/path/to/notebook_secret"
to share trust but is short on details how this should work in practice. Where does the notebook_secret file be stored, on the common server or on each client PC? Where do add this code, in each notebook or in a common configuration file?

Categories