Developing a client application with the JupyterLab application¶
You can develop an API by using JupyterLab, a notetaking application for scripting languages that runs in a web browser. When you develop APIs, you typically work in a command-line shell interface at the beginning, and then switch between the shell session and the editor. By using JupyterLab, you can view all information that you require in a single window to streamline the development process.
Installing, starting, and using JupyterLab¶
Before you can use JupyterLab for API development, you must install and start the application.
To install JupyterLab, follow the instructions in the online product documentation.
To start JupyterLab, issue the following command:
$ jupyter lab &
The output is similar to the following example:
JupyterLab server extension not enabled, manually loading...
...
[C 15:12:05.230 LabApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=92bd5725f58178bd226ae4303fa0dff0e4ee820815831669
Open the URL from a web browser on the workstation where JupyterLab is installed. Verify that you can view the JupyterLab web interface.
To start using JupyterLab, create a notebook with a Python 3 kernel. You can add more kernels such as PHP Hypertext Processor. In the notebook, you can write scripts, run the scripts by using the kernel, and view the result. You can also add texts in a Markdown format.
Using Python Virtual Environments for Jupyter Kernel¶
If you plan to use non-standard libraries such as Requests and Paramiko, set up a Python Virtual Environment where you can conveniently maintain those libraries. The starting point is to create a Python Virtual Environment. Then, in JupyterLab, you create a kernel that uses this virtual environment.
As an example, assume that you created a Python Virtual Environment and logged in to it:
$ python3 -m virtualenv py36_venv
$ source ./py36_venv/bin/active
Continuing with this example, you can now add a kernel with the Python Virtual Environment to your JupyterLab application:
(py36_venv) $ ipython kernel install --user --name=py36_venv
To verify the configuration, you would return to your web browser and ensure that the kernel py36_venv
is available in the kernel list. To see a list of kernels with paths, issue the following command:
$ jupyter kernelspec list
The output is similar to the following example:
jupyter kernelspec list
Available kernels:
py36_venv /home/sarah/.local/share/jupyter/kernels/py36_venv
php /home/sarah/.ipython/kernels/php
ruby /home/sarah/.ipython/kernels/ruby
Collaborating with multiple users in a JupyterLab workspace¶
You can run JupyterLab on a remote server and allow multiple users to access the same workspace. This approach is useful for sharing resources such as JupyterLab notebooks, Python scripts, and virtual environment.
Assume that you want to run JupyterLab on a CentOS Linux server: sarah@10.0.0.110. From your client workstation, establish a Secure Shell (SSH) connection to the server and let localhost use the port 8080 (HTTPS):
$ ssh -N -L 8080:localhost:8080 sarah@10.0.0.110
Then, establish another SSH connection to this server and run JupyterLab with the following commands:
$ ssh sarah@10.0.0.110
$ jupyter lab --no-browser --port 8080 &
From a web browser, open JupyterLab. Ensure that the host name localhost
on port 8080 connects to the remote server.
Invite other users to connect to the remote server and share your resources with them.