Skip to main content

PyRTL

PyPI version Build Status Code Coverage Documentation Status Binder

PyRTL provides a collection of classes for Pythonic register-transfer level design, simulation, tracing, and testing suitable for teaching and research. Simplicity, usability, clarity, and extensibility are overarching goals, rather than performance or optimization. Features include:

  • Elaboration-through-execution, meaning all of Python can be used including introspection.
  • Design, instantiate, and simulate all in one file and without leaving Python.
  • Export to, or import from, common HDLs (BLIF-in, Verilog-out currently supported).
  • Examine execution with waveforms on the terminal or export to .vcd as projects scale.
  • Elaboration, synthesis, and basic optimizations all included.
  • Small and well-defined internal core structure means writing new transforms is easier.
  • Batteries included means many useful components are already available.

What README would be complete without a screenshot? Below you can see the waveform rendered right on the terminal for a small state machine written in PyRTL.

Command-line waveform for PyRTL state machine

Tutorials and Documentation

Package Contents

If you are just getting started with PyRTL, try starting with the examples to get a sense of the "thinking with PyRTLs" required to design hardware in this way. If you are looking for a deeper understanding, dive into the code for the object Block. It is the core data structure at the heart of PyRTL and defines its semantics at a high level -- everything is converted to or from the small, simple set of primitives defined there.

The package contains the following files and directories:

  • pyrtl The module's source code.
  • pyrtl/rtllib/ Finished PyRTL libraries which are hopefully both useful and documented.
  • examples A set of hardware design examples that show the main ideas behind PyRTL.
  • tests A set of unit tests for PyRTL which you can run with pytest.
  • docs Documentation written in Sphinx reStructuredText.

PyRTL Development Environment

All PyRTL developers should use the same tool versions to avoid confusing situations where a test fails only on one person's computer, or the generated documentation looks weird on another person's computer.

PyRTL uses uv to ensure all developers work in the same environment. uv manages the installation and versioning for all other PyRTL developer tools, like pytest and ruff.

To set up a PyRTL development environment, you only need to install uv, by following the uv installation instructions.

After installing uv, you can run all the tests with:

$ uv run just tests

And you can generate the Sphinx documentation with:

$ uv run just docs

uv will download and install Python and any required pip packages as needed. uv caches installed software so future uv invocations will be fast.

Contributing to PyRTL

Picking a first project

  • One of the earliest things you should submit is a unit test that hits some uncovered lines of code in PyRTL. For example, pick a PyrtlError that is not covered and add a unit test in tests that will hit it.
  • After you have that down check PyRTL Issues for a feature that is marked as "beginner friendly".
  • Once you have that down, ask for access to the PyRTL-research repo where we keep experimental features and designs that could use more help!

Coding style

  • All major functionality should have unit tests covering and documenting their use.
  • All public functions and methods should have useful docstrings.
  • All code needs to conform to PEP8 conventions.
  • No new root-level dependencies on external libs, import locally if required for special functions.

Workflow

  • This Git tutorial is a useful reference for working with Git.

  • This blog post covers a useful Git Fork workflow for working on PyRTL.

  • The development branch is the primary stable working branch (everyone is invited to submit pull requests).,

  • Bugs and minor enhancements tracked directly through GitHub Issues.

  • When posting a bug please include a small code sample that triggers the bug, e.g. Issue #56.

  • When pushing a fix to a bug or enhancement please reference the Issue in the commit message, e.g. Fix to Issue #56.

  • Before sending a pull request, please run:

    $ uv run just presubmit
    

    to verify that all tests pass and that all documentation can be generated with your changes.

Documentation

  • All important functionality should have an executable example in examples.

  • All classes should have a docstring that describes the class at a high level.

  • All methods and functions should include a docstring in the following Sphinx-parsable format:

    """One Line Summary (< 88 chars) of the function, followed by period.
    
    A longer description of what this function does and does not do. Describe any
    assumptions or invariants. Provide an example for user-facing functions.
    
    :param param1: Description of this parameter.
    :param param2: Longer parameter descriptions take up a newline with four
        leading spaces like this.
    
    :raises Exception: If this function raises an exception, explain when that
        occurs here.
    
    :return: Description of function's return value.
    """
    
  • Sphinx parses Python type annotations, so put type information into annotations instead of docstrings.

  • The Sphinx-generated documentation is published to https://pyrtl.readthedocs.io/ .

  • PyRTL's Sphinx build process is documented in docs/README.md.

  • PyRTL's release process is documented in docs/release/README.md.

Using PyRTL

We love to hear from users about their projects, and if there are issues we will try our best to push fixes quickly. You can read more about how we have been using it in our research at UCSB both in simulation and on FPGAs in our PyRTL paper at FPL.

Related Projects

It is always important to point out that PyRTL builds on the ideas of several other related projects as we all share the common goal of trying to make hardware design a better experience! You can read more about those relationships on our PyRTL project web page

Download files

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

Source Distribution

pyrtl-1.0.3.tar.gz (793.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrtl-1.0.3-py3-none-any.whl (222.3 kB view details)

Uploaded Python 3

File details

Details for the file pyrtl-1.0.3.tar.gz.

File metadata

  • Download URL: pyrtl-1.0.3.tar.gz
  • Upload date:
  • Size: 793.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyrtl-1.0.3.tar.gz
Algorithm Hash digest
SHA256 9da4fadc52c64a355eb691f5ed82891d9cca65cb6d8ae3a7f322775d13fd0ef6
MD5 923caa10de510822de3eed7b9c2ab77e
BLAKE2b-256 e04dcea0e31b767f3c66e767a6df1854c8d443bc5ddff933b617a1ea887f4674

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrtl-1.0.3.tar.gz:

Publisher: python-release.yml on UCSBarchlab/PyRTL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyrtl-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyrtl-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 222.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pyrtl-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d6ee1da29e0d2e536869ec9c25271738bf772c0b7dc44d212f09706b733da23
MD5 6a81c5c83d78461f138f4a0b30b97c6b
BLAKE2b-256 f3d2f54113695434fe73edcc68d6c64ba90d3118737e5a96c2dde6da8cae50ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyrtl-1.0.3-py3-none-any.whl:

Publisher: python-release.yml on UCSBarchlab/PyRTL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.12

2 files

0.11.3

2 files

0.11.2

2 files

0.11.1

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.0

2 files

0.8.7

1 file

0.8.6

2 files

0.8.5

1 file

0.8.4

2 files

0.8.3

1 file

0.8.2

1 file

0.8.0

1 file

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