Skip to main content

Launch Jupyter kernels from Conda-Store

Project description

nb_conda_store_kernels

This extension enables a Jupyter Notebook or JupyterLab application to access environments stored in Conda-Store and run kernels for Python, R, and other languages. When a kernel from an external environment is selected, the environment is downloaded, extracted, conda environment is automatically activated, and finally the kernel is launched. This package was heavily inspired by nb_conda_kernels.

Any notebook launched via a nb_conda_store_kernel kernel will have notebook metadata about the environment used. This provides a powerful mechanism for running the notebook later in a reproducible way.

{
    ...,
    "kernelspec": {
        ...,
        "name": "conda-store://<namespace>/<environment_name>:<build-id>",
        ...,
    },
    ...
}

The package works by defining a custom KernelSpecManager that calls the Conda-Store REST API for available conda environments with required packages. It dynamically modifies each KernelSpec so that it can be properly run from the notebook environment. When you create a new notebook, these modified kernels will be made available in the selection list. Additionally without Conda-Pack

Usage

This package does not need pip or conda to run properly but currently only run on Linux. It should be installed in the environment from which you run Jupyter Notebook or JupyterLab. It is recommended for install nb_conda_store_kernsl via Conda due to activation hooks which simplify the installation but there is no strong reason to use conda.

conda install -c conda-forge nb_conda_store_kernels

Alternatively pip works as well but requires one additional step.

pip install nb_conda_store_kernels
python -m nb_conda_store_kernels.install --enable
# python -m nb_conda_store_kernels.install --disable # to disable

python -m nb_conda_store_kernels.install --enable simply modifies a single jupyter setting. If that did not work (it should and is a bug if not) you need to add the following setting to jupyter_config.py.

mkdir ~/.jupyter
echo 'c.JupyterApp.kernel_spec_manager_class = "nb_conda_store_kernels.manager.CondaStoreKernelSpecManager"' > ~/.jupyter/jupyter_conifg.py

In order to nb_conda_store_kernels to connect properly to Conda-Store it needs several environment variables set. Under the covers conda-store the client is being using and has detailed documentation on configuration.

export CONDA_STORE_URL=http(s)://...
export CONDA_STORE_AUTH=none|basic|token
# export CONDA_STORE_USERNAME=... # using basic auth 
# export CONDA_STORE_PASSWORD=... # using basic auth
# export CONDA_STORE_TOKEN=...    # using token auth

Finally launch JupyterLab!

jupyter lab

Connecting to existing conda-store server

Visit conda-store server you are using and get a token for your given user via vising the /user endpoint after you login.

docker run -p 8888:8888 -e CONDA_STORE_TOKEN=... quansight/nb-conda-store-kernels:v0.1.5

Use with nbconvert, voila, papermill,...

Since nb_conda_store_kernels uses the conda-store client under the covers these use cases are supported by the client with proper environment variables being set. There are plans to extend other tools to use Conda-Store.

conda-store run namespace/environment -- python -c "print('Hello, Conda-Store!')"

Development

Start Conda-Store server

docker-compose up --build
jupyter lab

Login to Conda-Store at localhost:5000 and create a new environment.

Copyright 2022 Quansight LLC

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nb_conda_store_kernels-0.1.5.tar.gz (7.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page