Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Python Bindings of Spike RISC-V ISA Simulator

LIU Yu <liuy@huimtlab.org>
2026/3/1 (v0.0.5)

Introduction

This project provides Python bindings for the Spike RISC-V ISA Simulator. The Pythonic Spike (or PySpike) opens up Spike's C++ internals (such as RISC-V disassembler, processors, controllers, peripherals, etc.) for interoperation with Python scripts. It enables users to write ISA / RoCC extensions and MMIO device models in Python, and plug them into vanilla Spike for (co-)simulating complex hardware systems. Through integrating Spike more seamlessly into the Python ecosystem, PySpike aims to boost the agility of Python-based hardware verification tools and workflows.

PyPI package: spike

Getting Started

PySpike requires: Python 3.8+.

Install the wheel package with pip.

$ pip install --pre spike

PySpike ships the original command-line tool spike, a.k.a vanilla Spike, within its wheel package. You can confirm its availability using,

$ spike --help
Spike RISC-V ISA Simulator 0.0.5...
...

There is also a 100%-compatible command-line wrapper called pyspike, with additional support for Python-based ISA / MMIO / RoCC extensions via --extlib=<name>.

$ pyspike \
    --isa=rv32imc_xmyisa --priv=m \
    --pc=0x90000000 \
    -m0x90000000:0x4000000 \
    --extlib=myisa.py \
    --extlib=mydev.py \
    --device=mydev,0x20000000 \
    tests/data/libc-printf_hello.elf
Hello, World!

Quick ISA Extension

An ISA extension implements one or more custom instructions and / or control-state registers (CSRs) for Spike's RISC-V processor models. With PySpike, an ISA extension is a Python class that inherits riscv.isa.ISA. It should implement a minimum of two methods: get_instructions and get_disasms. The former provides functional models of one or more custom instructions, and the latter provides their disassemblers. Other optional methods include get_csrs and reset, for providing custom CSRs and resetting extension states, respectively. Use decorator @isa.register("myisa") to register the extension under the name myisa.

from typing import List
from riscv import isa
from riscv.csrs import csr_t
from riscv.disasm import disasm_insn_t
from riscv.processor import insn_desc_t, processor_t

@isa.register("myisa")
class MyISA(isa.ISA):
    def __init__(self): ...
    def get_instructions(self, proc: processor_t) -> List[insn_desc_t]: ...
    def get_disasms(self, proc: processor_t) -> List[disasm_insn_t]: ...
    def get_csrs(self, proc: processor_t) -> List[csr_t]: ...
    def reset(self, proc: processor_t) -> None: ...

Quick Device Model

Likewise to the ISA extension, a device model implements a custom memory-mapped input/output (MMIO) peripheral for Spike's simulated system bus. With PySpike, a device model is a Python class that inherits riscv.dev.MMIO. It should implement a minimum of three methods: __init__, load, and store. The former initializes the model, the latter two handle memory read and write operations. Other optional methods include size and tick, for obtaining the size of memory-mapped address space, and shifting device states, respectively. Use decorator @dev.register("mydev") to register the model under the name mydev.

from typing import Optional
from riscv import dev
from riscv.sim import sim_t

@dev.register("mydev")
class MyDEV(dev.MMIO):
    def __init__(self, sim: sim_t, args: Optional[str] = None): ...
    def load(self, addr: int, size: int) -> bytes: ...
    def store(self, addr: int, data: bytes) -> None: ...
    def size(self) -> int: ...
    def tick(self, rtc_ticks: int) -> None:

Development

Getting Source Code

$ git clone --recurse-submodules https://github.com/huimtlab/pyspike
$ cd pyspike

Setting Up Develop Environment

Install with pip in editable mode. This will setup development dependencies as well.

$ python -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -m pip install -e '.[dev]'

Running Tests

Run the built-in test suite with pytest.

(.venv) $ python -m pytest -v

Running Tests with Coverage

To enable coverage report, rebuild the extension module with --cov option, then re-run the test suite also with --cov option. You should see the coverage report by the end of the test output.

Note, if leaving out the first step, the C++ code will not show up in the coverage report.

(.venv) $ python setup.py build_ext --inplace --cov
(.venv) $ python -m pytest -v --cov

Optionally, you can generate HTML coverage report from the lcov data files.

(.venv) $ genhtml -o coverage --substitute "s#^#$PWD/#g" *.lcov

Packaging

(.venv) $ python -m build

Metadata

Release files for spike 0.0.5.dev20

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

Built distributions (wheels)

Table of built distributions (wheels) for spike 0.0.5.dev20
File
spike-0.0.5.dev20-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
spike-0.0.5.dev20-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
spike-0.0.5.dev20-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
spike-0.0.5.dev20-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
spike-0.0.5.dev20-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details

Total release size: 1.0 GB

Release files / spike-0.0.5.dev20-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL spike-0.0.5.dev20-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 208.8 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0378395edde36b4409372ee7b7fb5de567e82fbfc64b6005dde1cc43d0d8057e
BLAKE2b-256 checksum
How to use checksums
72a9a97ff022e03172e5d6a107f0f14075a0ec7799d14ea2d8e6ef25b80518ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / spike-0.0.5.dev20-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL spike-0.0.5.dev20-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 208.8 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4f83f2efbf1c28b751dded81e83189efca86571a61ebefc3ddd5d9471b897bbf
BLAKE2b-256 checksum
How to use checksums
46e26353639d575c56f051198daa5197912c76276928a202ec564308a8171a3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / spike-0.0.5.dev20-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL spike-0.0.5.dev20-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 208.8 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
79296c00ed6707f138b69bc3a8cb5745a4c6d1bd0fd0ca531228f4824e79bdfe
BLAKE2b-256 checksum
How to use checksums
3d0917fcb930e84862c6c8bddfd3c9808c6cc1f53d3278517886f2f40b568e99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / spike-0.0.5.dev20-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL spike-0.0.5.dev20-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 208.8 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
30c8ab9ddd8b2ebfccd2b894a68c6a327bd5a923117a1598629c071b8f4b3ae6
BLAKE2b-256 checksum
How to use checksums
83e7a8e49d2cf929e0c40426b045d8c7f62aabde857a147fc1b9f86c5bfeca54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / spike-0.0.5.dev20-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL spike-0.0.5.dev20-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 208.8 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c3ac9b8f37539ce26fb06a3f662115995f5789bd2b15d24598ad439f39da4778
BLAKE2b-256 checksum
How to use checksums
8ba491adb7565057a2b5a1f3858c4a669f2dbe905b7592ea7b81e9ef5cd0b06d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for spike 0.0.5.dev20

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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