Skip to main content

Python Jupyter kernel using project/environment manangers like Rye, Uv, PDM, Poetry, Hatch etc.

Project description

Pyproject Local Jupyter Kernel

Website - PyPI PyPI - Python Version

Separate dependencies for Jupyter notebooks in separate projects.

Use python project managers to define dependencies: use one of Uv, Rye, PDM, Poetry, Hatch (and so on).

Instead of installing a myriad of jupyter kernelspecs, one per project, with this solution there is only one "meta" kernel that enables the environment for the project the notebook file resides in. This approach should be more portable, usable to anyone who checks out your project structure from git, and easier to use.

Pyproject Local supports the following systems, and reads pyproject.toml to figure out which kind of project it is:

Uv
Rye
Poetry
Hatch
PDM

A custom command or direct use of virtual environment can also be configured.

Quick Start (JupyterLab)

  1. Install pyproject-local-kernel in your jupyterlab environment and restart jupyterlab
  2. Create a new directory and notebook
  3. Select the Pyproject Local kernel for the notebook
  4. Run these shell commands in the notebook to setup the new project:

(Example for Uv:)

!uv init && uv add ipykernel

(Example for Rye:)

!rye init --virtual && rye add ipykernel

Now restart the kernel and you are good to go. Use more add commands to add further dependencies.

See the examples directory for how to setup jupyterlab and notebook projects separately. JupyterLab and the notebook are installed in separate environments.

Do you want to use pyproject-local-kernel in other environments, like VSCodium or VS Code, or maybe using Pipenv? See our FAQ for more information.

User Experience

If the Pyproject Local kernel is used in a project where Uv (or the relevant project manager) is not installed, or the project does not have an ipykernel in the environment, then starting the kernel fails.

In that case a fallback kernel is started which that shows a message that it is not setup as expected in this environment. This is a regular ipython kernel which allows you to run shell commands and hopefully fix the configuration of the project.

It will give you some hints in the Jupyter notebook interface about the next steps to get it working. Example below is for Rye.

! Failed to start kernel! The detected project type is: Rye
! Is the virtual environment created, and does it have ipykernel in the project?
!
! Run this:
! !rye add --sync ipykernel
!
! Then restart the kernel to try again.

Configuration

Configuration is optional and is read from pyproject.toml. Only the pyproject.toml closest to the notebook is read. Defaults are based on “sniffing” the pyproject.toml to detect which project manager is in use.

python-cmd

The key tool.pyproject-local-kernel.python-cmd should be a command that runs python from the environment you want to use for the project.

If this is set then it overrides the default command.

Default: Depends on project manager
Type: list[str] | str
Example:

[tool.pyproject-local-kernel]
python-cmd = ["uv", "run", "--with", "ipykernel", "python"]

use-venv

Path to virtual environment that should be used, relative to the pyproject.toml file. Can also be an absolute path.

If this is set then it overrides the default command.

Default: Not set
Type: str
Example:

[tool.pyproject-local-kernel]
use-venv = ".venv"

About Particular Project Managers

The project manager command, be it rye, uv, pdm, etc needs to be available on the path where jupyterlab runs. Either install the project manager in the jupyterlab environment, or install the project manager user-wide (using something like pipx, rye tools, uv tool, brew, or other method to install it.)

Rye

  • Rye is detected if the pyproject.toml contains tool.rye.managed = true which Rye sets by default for its new projects.

Uv

  • Uv is detected if the pyproject.toml contains tool.uv. It is also the default fallback if no project manager is detected from a pyproject file.

  • The command used is uv run --with ipykernel python which means that it ensures ipykernel is used even if it's not already in the project(!). However, note that it uses an ephemeral virtual environment for ipykernel in that case. Add ipykernel to the project to avoid this.

PDM

  • PDM is detected if pyproject.toml contains tool.pdm

Hatch

  • Hatch is detected if pyproject.toml contains tool.hatch.envs

  • By default it calls out to hatch env find, to find the default virtualenv, and runs from there. hatch run should not be used directly because it's not compatible with how kernel interrupts work (as of this writing).

  • It's best to create the hatch project, add ipykernel as dependency and sync dependencies in a terminal before starting (it does not work so well with shell commands in a notebook).

Project Status

Additional interest and maintainer help is welcomed.

Links

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

pyproject_local_kernel-0.9.1.tar.gz (181.5 kB view details)

Uploaded Source

Built Distribution

pyproject_local_kernel-0.9.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file pyproject_local_kernel-0.9.1.tar.gz.

File metadata

  • Download URL: pyproject_local_kernel-0.9.1.tar.gz
  • Upload date:
  • Size: 181.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for pyproject_local_kernel-0.9.1.tar.gz
Algorithm Hash digest
SHA256 7f70c50b5f61ab67b30da7d000a1e900c02e6228d2797a1e8b9d095af7644eb9
MD5 2acbcae16d5942efa796dc5b75f3065a
BLAKE2b-256 d8efc6ec50220063e1b81bebe6251b64f85b1d6a4e647a09414728fe2bd24774

See more details on using hashes here.

File details

Details for the file pyproject_local_kernel-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyproject_local_kernel-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 225a66f8934b54c0c832b599fb3d3897728f8b4cbf189f23ee7e18fbe8c90217
MD5 7bf1510274c13af3aed68b0cbe08d267
BLAKE2b-256 9564b27693a34608da69bbb1b95755ec5ad4b55e83804f5026b913da79bbb5a2

See more details on using hashes here.

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