SHDL (Simple Hardware Description Language) is a minimal HDL designed for creating digital circuits and easily simulating them. It compiles directly to C for maximum performance and portability. PySHDL is the Python interface for SHDL.
Project description
SHDL - Simple Hardware Description Language
A lightweight hardware description language and Python driver for digital circuit simulation using exclusively logic gates! SHDL provides an intuitive syntax for defining digital circuits and a clean Python API for interacting with them (PySHDL).
Features
- 🚀 Simple Syntax - Easy-to-learn hardware description language
- 🐍 Python Integration - Seamless Python API for circuit simulation
- ⚡ C Backend - Compiles to optimized C code for fast simulation and portability
- 🔧 Command Line Tools - Built-in compiler and utilities
- 📦 Component Reuse - Import and compose reusable circuit components
- 🔢 Constants Support - Use named constants for parameterizable designs
Installation
We recommend using uv for using PySHDL. If you don't have it installed, you can install it via pip:
pip install PySHDL
Quick Start
1. Define a Circuit (SHDL)
Create a file fullAdder.shdl:
component FullAdder(A, B, Cin) -> (Sum, Cout) {
x1: XOR; a1: AND;
x2: XOR; a2: AND;
o1: OR;
connect {
A -> x1.A; B -> x1.B;
A -> a1.A; B -> a1.B;
x1.O -> x2.A; Cin -> x2.B;
x1.O -> a2.A; Cin -> a2.B;
a1.O -> o1.A; a2.O -> o1.B;
x2.O -> Sum; o1.O -> Cout;
}
}
2. Use in Python
from SHDL import Circuit
# Load and compile the circuit
with Circuit("fullAdder.shdl") as c:
# Set input values
c.poke("A", 1)
c.poke("B", 1)
c.poke("Cin", 1)
# Run simulation
c.step(10)
# Read output
result = c.peek("Sum")
print(f"Result: {result}") # Output: Result: 60
3. Compile from Command Line
# Compile SHDL to C
shdlc adder.shdl -o adder.c
# Compile and build executable
shdlc adder.shdl --optimize 3
CLI Options
shdlc [options] <input.shdl>
Options:
-o, --output FILE Output C file (default: <input>.c)
-I, --include DIR Add directory to component search path
-c, --compile-only Generate C code only, do not compile to binary
-O, --optimize LEVEL GCC optimization level 0-3 (default: 3)
Python API
Circuit Class
Circuit(shdl_file, search_paths=None)
Create a new circuit instance from a SHDL file.
Methods:
poke(port_name, value)- Set an input port valuepeek(port_name)- Read an output port valuestep(cycles)- Advance simulation by N cyclesreset()- Reset circuit to initial state
Examples
See the examples/ directory for more complete examples:
interacting.py- Basic circuit interactionSHDL_components/- Reusable component library
Documentation
For comprehensive documentation, visit our Documentation Site.
GitHub repository: rafa-rrayes/SHDL
Requirements
- Python >= 3.10
- GCC or compatible C compiler (for circuit compilation)
📝 Feedback & Contributions Welcome
SHDL is still early-stage, and real-world feedback is incredibly valuable. If you try the library—whether for a small experiment, a class assignment, or a personal project—I would love to hear how it went.
Please consider sharing: • What worked well • What felt confusing or missing • Any bugs you hit • Feature ideas • Example circuits you built
You can give feedback in any of the following ways: • Open an Issue: 👉 https://github.com/rafa-rrayes/SHDL/issues • Start a Discussion: 👉 https://github.com/rafa-rrayes/SHDL/discussions • Submit a Pull Request: Improvements, examples, docs, and tests are all welcome. • Send me a message! 👉 rafa@rayes.com.br is my email.
Even a short comment like “Tried it — worked for me” helps guide development. Thank you for trying SHDL!
Author
Rafa Rayes
Email: rafa@rayes.com.br
GitHub: rafa-rrayes
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyshdl-0.2.3.tar.gz.
File metadata
- Download URL: pyshdl-0.2.3.tar.gz
- Upload date:
- Size: 508.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7587b164f1ff3495fefd3e81cf86d172e4b96edfc81670d4c227504459d90f05
|
|
| MD5 |
2b0722305c69e0519c632c1e4f5840d3
|
|
| BLAKE2b-256 |
0cefb1635dd3c42aab153cfdf49023deac3a322a52d105dc542429e118df41c9
|
Provenance
The following attestation bundles were made for pyshdl-0.2.3.tar.gz:
Publisher:
publish.yml on rafa-rrayes/SHDL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyshdl-0.2.3.tar.gz -
Subject digest:
7587b164f1ff3495fefd3e81cf86d172e4b96edfc81670d4c227504459d90f05 - Sigstore transparency entry: 760444730
- Sigstore integration time:
-
Permalink:
rafa-rrayes/SHDL@5a749d57463ec31a197f0c8498f5441d1d337e91 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/rafa-rrayes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5a749d57463ec31a197f0c8498f5441d1d337e91 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyshdl-0.2.3-py3-none-any.whl.
File metadata
- Download URL: pyshdl-0.2.3-py3-none-any.whl
- Upload date:
- Size: 116.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb2ab754c72d5d1a0354e2aedb9ccafca6f816ae55459b3016977b89ffe349b1
|
|
| MD5 |
ae58cf5fb7bbe3d4d4cb70dbe6dfe7fe
|
|
| BLAKE2b-256 |
77253ab37d74876526582c082a64b7ca5d3df37f118bcc72f03043c5bf3a4edb
|
Provenance
The following attestation bundles were made for pyshdl-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on rafa-rrayes/SHDL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyshdl-0.2.3-py3-none-any.whl -
Subject digest:
eb2ab754c72d5d1a0354e2aedb9ccafca6f816ae55459b3016977b89ffe349b1 - Sigstore transparency entry: 760444733
- Sigstore integration time:
-
Permalink:
rafa-rrayes/SHDL@5a749d57463ec31a197f0c8498f5441d1d337e91 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/rafa-rrayes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5a749d57463ec31a197f0c8498f5441d1d337e91 -
Trigger Event:
release
-
Statement type: