verilog-parser
A pure-Python parser for Verilog cell-library (.v) files — used in EDA
flows to describe the pins and port directions of standard cells.
Related article
Building a Python Verilog Cell Library Parser for EDA Automation — A walkthrough of the design decisions and real-world use cases behind this library.
Features
- Parses
`celldefine/`endcelldefineblocks withmodule,input,output, andinoutdeclarations - Supports mixed and non-mixed mode variants via
`ifdef MIXEDMODE - Zero required dependencies — only the Python standard library
- Optional colored warnings via
termcolor - CLI included:
verilog-parser cells.v --cell INV_X1
Installation
pip install eda-verilog-parser # no extra dependencies
pip install "eda-verilog-parser[color]" # adds termcolor for colored warnings
Or for development:
git clone https://github.com/rohaansch/verilog-parser
cd verilog-parser
pip install -e ".[dev]"
Quick start
from verilog_parser import VerilogParser
parser = VerilogParser()
verilog = parser.read("cells.v")
print(repr(verilog))
# Verilog(cells=4, files=1)
print(verilog.get_pins("INV_X1"))
# ['A', 'ZN']
print(verilog.get_pin_directions("INV_X1"))
# {'input': ['A'], 'output': ['ZN'], 'inout': []}
print(verilog.get_pin_directions("INV_X1", mode="mixed"))
# {'input': ['A'], 'output': [], 'inout': ['ZN']}
Supported Verilog structure
The parser recognises cells defined with `celldefine / `endcelldefine
and `ifdef MIXEDMODE / `else / `endif sections:
`celldefine
`ifdef MIXEDMODE
module INV_X1 (A, ZN);
input A;
inout ZN;
`else
module INV_X1 (A, ZN);
input A;
output ZN;
`endif
`endcelldefine
Modes
| Mode | When used |
|---|---|
"non-mixed" (default) |
Digital-only simulation; outputs declared as output |
"mixed" |
Mixed-signal simulation; outputs declared as inout |
API reference
VerilogParser(path=None)
Create a parser. path sets the default file used by read().
VerilogParser.read(path=None) → Verilog
| Argument | Type | Description |
|---|---|---|
path |
str |
.v file path. Falls back to the constructor path. |
Raises ValueError / FileNotFoundError / IOError on bad input.
VerilogParser.reset()
Clear internal state to reuse the parser for a different file:
v_fast = parser.read("lib_fast.v")
parser.reset()
v_slow = parser.read("lib_slow.v")
Verilog object
| Attribute | Type | Description |
|---|---|---|
header |
str |
Leading comment block from the parsed file |
cells |
dict[str, dict] |
Cell name → mode → pin data |
files |
list[str] |
Absolute paths of files contributing to this object |
Verilog.get_pins(cell_name, mode="non-mixed") → list[str]
Return the ordered list of all pins for the given cell and mode.
Verilog.get_pin_directions(cell_name, mode="non-mixed") → dict
Return a mapping of "input" / "output" / "inout" → pin list.
format_cell(cell) → str
Format a cell's mode data as a human-readable multi-line string:
from verilog_parser import format_cell
print(format_cell(verilog.cells["DFFS_X2"]))
# [mixed]
# pins: D, CK, SN, Q, QN
# input: D, CK, SN
# inout: Q, QN
# [non-mixed]
# pins: D, CK, SN, Q, QN
# input: D, CK, SN
# output: Q, QN
Command-line usage
verilog-parser cells.v
verilog-parser cells.v --cell INV_X1
verilog-parser cells.v --cell INV_X1 --mode mixed
verilog-parser cells.v --header
verilog-parser --version
Or without installing:
python -m verilog_parser cells.v --cell INV_X1
Running the tests
pip install -e ".[dev]"
pytest -v
License
Metadata
Release files for eda-verilog-parser 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| eda_verilog_parser-0.1.1.tar.gz | 9.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| eda_verilog_parser-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.8 kB
Release files / eda_verilog_parser-0.1.1.tar.gz
| Download URL | eda_verilog_parser-0.1.1.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa782c50d2ec7c4a2c4ca108f9d646bde812eba3e8f7fb33fe09d130ba14b424
|
|
BLAKE2b-256 checksum How to use checksums |
18f9fe4a2018a45f7b222e12479eb2a33466dc9f66de41c6786e1152d158c47c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / eda_verilog_parser-0.1.1-py3-none-any.whl
| Download URL | eda_verilog_parser-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b1faa4eaf4bea323bde41041f810bdf8855676fbd40fd8b706d70f11d0d76c3
|
|
BLAKE2b-256 checksum How to use checksums |
bb3e7828ca03b206e6ae9e8c3d81c48ff73191acc95e421edb84cc39f402f743
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for eda-verilog-parser 0.1.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.