Skip to main content

vunit-python-bridge

Documentation Repository PyPI Python versions License CI status

A VUnit package making Python callable from VHDL.

Overview

vunit-python-bridge embeds a Python interpreter in the simulator process so that a VHDL testbench can execute Python code and call Python functions — a NumPy reference model, a constraint solver, a plot of what the design just produced — without leaving the simulation. The VHDL API, python_pkg/python_context, is compiled into the python_bridge library and is implemented for the selected simulator by a small C library the package builds itself, called through VHPIDIRECT (NVC, GHDL), the FLI (Questa/ModelSim) or VHPI (Riviera-PRO). Values cross the interface with their VHDL types: integer, real, string, boolean, std_ulogic, unsigned/signed, the vector types, integer_array_t as a NumPy array, and VUnit's dict_t as a Python dict. A python_object_t is an instance of a Python class owned by VHDL, for example the backend of a verification component, with a namespace of its own for every instance.

Installation

pip install vunit-python-bridge

Basic Example

The run script adds the package after the VUnit builtins:

from vunit import VUnit

vu = VUnit.from_argv()
vu.add_vhdl_builtins()
vu.add_package("vunit-python-bridge", allow_setup=True)

lib = vu.add_library("lib")
lib.add_source_files("*.vhd")

vu.main()

allow_setup=True is required because, when added, the package builds its native library and registers simulator options as part of its setup function, which VUnit only runs when the project allows it.

The testbench gets the API from the python_context context of the python_bridge library:

library vunit_lib;
context vunit_lib.vunit_context;

library python_bridge;
context python_bridge.python_context;

...

exec("import numpy as np");
exec("def gain(x): return [2 * v for v in x]");

check_equal(eval_integer("int(np.sum([1, 2, 3]))"), 6);
check_equal(eval_string("'-'.join(['a', 'b'])"), string'("a-b"));
check(call_integer_vector("gain", arg(integer_vector'(1, 2))) = integer_vector'(2, 4));

Supported Simulators

Simulator Interface Status
NVC VHPIDIRECT Tested on Linux, macOS and Windows
GHDL (mcode, llvm-jit, llvm, gcc) VHPIDIRECT Tested on Linux, macOS and Windows
Questa/ModelSim FLI Tested manually on Linux; the Windows build is untested
Riviera-PRO VHPI Tested manually on Linux and Windows

A simulator provided by a VUnit package says how it loads the bridge itself, by two attributes of its simulator interface class: see Simulator packages.

Requirements

  • VUnit 5.0.0.dev15 or later (vunit_hdl on PyPI), which pip installs with the package.
  • VHDL-2008 or later.
  • CPython 3.10 or later, standard (GIL) build, with a shared libpython (--enable-shared), which is what distribution Pythons, actions/setup-python, uv, pyenv and conda-forge provide by default.
  • Linux and macOS: a C compiler (cc, gcc or clang, or CC) and the Python development headers (for example the python3-dev package). The bridge library is compiled on first use and cached.
  • Windows: a 64-bit CPython from python.org (or compatible). The package ships prebuilt DLLs for NVC and GHDL. Questa builds its FLI library, and NVC and GHDL their library when the DLLs are missing, with a MinGW-w64 gcc: CC, the one bundled with the simulator, or gcc on PATH.
  • The bridge library is built or copied to ~/.vunit-python-bridge, not to the VUnit output path. VUNIT_PYTHON_BRIDGE_LIBRARY_DIR selects another directory on every platform.

The simulator runs Python in the same environment as VUnit itself, including an active virtual environment and its installed packages.

Documentation

The documentation is at vunit-python-bridge.readthedocs.io.

License

Mozilla Public License, v. 2.0, like VUnit. See LICENSE.

Metadata

Release files for vunit-python-bridge 0.4.0

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

Built distribution (wheel)

Table of built distributions (wheels) for vunit-python-bridge 0.4.0
File Interpreter ABI Platform Actions
vunit_python_bridge-0.4.0-py3-none-any.whl Python 3 none any Details for vunit_python_bridge-0.4.0-py3-none-any.whl

Release files / vunit_python_bridge-0.4.0-py3-none-any.whl

Download URL vunit_python_bridge-0.4.0-py3-none-any.whl
Size 169.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb514631c4ce70d2d5594360b59d3f9b7d666c58daab7e84a6b2db4e50b88aaf
BLAKE2b-256 checksum
How to use checksums
f1fc1975769e8cbdc5e2d37d147a50dd69aae74c9eeb23a8cadb5aef49e2de78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for vunit-python-bridge 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

1 file in this release has been uploaded with provenance metadata.

Attestation for vunit_python_bridge-0.4.0-py3-none-any.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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