Skip to main content

cocotb Jupyter Kernel

Binder

This kernel adds support for using cocotb within Jupyter notebooks.

Why is a dedicated kernel needed?

cocotb works in conjunction with an HDL simulator. As such, attempting to import cocotb within a notebook will not work because no simulator is attached. This kernel works by first building the HDL design and launching the simulator using cocotb's runners, then having a cocotb test module launch ipykernel, which will connect to the notebook and execute code cells.

Installation

Prerequisites:

  • Python >=3.11,<3.14 (cocotb 2.0.1 supports up to 3.13)
  • JupyterLab 4+ or Jupyter Notebook 6+
  • An HDL simulator (such as Icarus Verilog, Verilator, or GHDL)

After installing the prerequisites, the kernel can be installed via pip.

pip install cocotb_kernel

To complete the installation of kernel, execute one of the following commands:

# Install to Jupyter's user directory, ~/.local/share/jupyter/kernel
python -m cocotb_kernel.install --user

# or, if using conda / venv
python -m cocotb_kernel.install --sys-prefix

# or, a custom prefix (Warning: kernel might not be detected by Jupyter)
python -m cocotb_kernel.install --prefix PREFIX

# or, install to Jupyter's base directory, /usr/local/share/jupyter (requires root)
sudo python -m cocotb_kernel.install

Usage

Before launching the kernel, create a TOML file named cocotb.toml within the project's root directory (similar to cocotb's Makefile).

The TOML file follows the cocotb runner build() and test() arguments, with a few exceptions, as shown:

# The simulator to build and simulate the HDL design
# https://docs.cocotb.org/en/stable/simulator_support.html
simulator = "icarus"

# The top level HDL module
hdl_toplevel = "foo"

# The language of the top level HDL module
hdl_toplevel_lang = "verilog"

# Optional: Verilog parameters or VHDL generics
[parameters]

# Build options
# https://docs.cocotb.org/en/stable/library_reference.html#cocotb.runner.Simulator.build
[build]
sources = ["hdl/foo.sv", "../hdl/foo.sv", "hdl/*.vhdl", "**/*.vhdl"] # specify sources relative to cocotb.toml

# Optional: Defines to set for building
[build.defines]

# Optional: Test options
# https://docs.cocotb.org/en/stable/library_reference.html#cocotb.runner.Simulator.test
[test]

# Optional: Extra environment variables to set for testing
[test.extra_env]

Once the TOML file is created, navigate to or launch JupyterLab within the project's root directory and create or open a notebook with the cocotb kernel.

Metadata

Release files for cocotb_kernel 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cocotb_kernel 2.0.1
File Size Uploaded
cocotb_kernel-2.0.1.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cocotb_kernel 2.0.1
File Interpreter ABI Platform
cocotb_kernel-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.9 kB

Release files / cocotb_kernel-2.0.1.tar.gz

Download URL cocotb_kernel-2.0.1.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a90fd24209412bbce53ffe2cda713952a709c5a8e19795df530c1849563bd88f
BLAKE2b-256 checksum
How to use checksums
1309569e397fdc28a55bbf761d93859aceaa4ad1fc4bfdbfa7c730823c435b7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.5

Release files / cocotb_kernel-2.0.1-py3-none-any.whl

Download URL cocotb_kernel-2.0.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f11bbc9863aebf8b234774c9f9ab27af8cb4d02d8d7f485de59111ed9570bf6c
BLAKE2b-256 checksum
How to use checksums
1bb563d804b122ee37231b0359b5353ace0e0b841efa79b3938b4957e8411ab2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.5

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page