{"id":10132,"library":"pyslang","title":"pyslang Python Bindings for Slang SystemVerilog Compiler","description":"pyslang provides Python bindings for the `slang` C++ library, a high-performance compiler for SystemVerilog. It enables Python applications to parse, elaborate, and perform advanced static analysis on SystemVerilog code. The current version is 10.0.0. `slang` has a regular release cadence, with major versions often introducing significant LRM compliance updates and performance improvements.","status":"active","version":"10.0.0","language":"en","source_language":"en","source_url":"https://github.com/MikePopoloski/pyslang","tags":["SystemVerilog","compiler","EDA","hardware","verification","static analysis"],"install":[{"cmd":"pip install pyslang","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The PyPI package `pyslang` exposes its functionality under the module name `slang`.","wrong":"import pyslang","symbol":"slang","correct":"import slang"},{"note":"The PyPI package `pyslang` exposes its functionality under the module name `slang`.","wrong":"from pyslang import Library","symbol":"Library","correct":"from slang import Library"}],"quickstart":{"code":"import slang\n\n# 1. Create a library to manage SystemVerilog source files\nlibrary = slang.Library()\n\n# 2. Add SystemVerilog source text. Multiple calls can add more files.\n#    You can also add files from disk using library.addSourceFile('path/to/file.sv')\nsv_code = \"\"\"\nmodule MySimpleModule;\n  initial begin\n    $display(\"Hello from SystemVerilog in Python!\");\n  end\nendmodule;\n\"\"\"\nlibrary.addSourceText(sv_code, fileName='example.sv')\n\n# 3. Get the compiled representation (perform parsing and elaboration)\ncompilation = library.getCompilation()\n\n# 4. Check for any diagnostics (errors or warnings)\ndiagnostics = compilation.getDiagnostics()\n\nif diagnostics:\n    print(\"Compilation completed with diagnostics:\")\n    for diag in diagnostics:\n        print(diag.toString())\nelse:\n    print(\"Compilation successful with no diagnostics.\")\n    # Further operations (e.g., accessing symbols) would go here.\n    # For instance, finding the 'MySimpleModule' definition:\n    # root = compilation.getRoot()\n    # module = root.lookupName('MySimpleModule')","lang":"python","description":"This quickstart demonstrates how to initialize the `slang` library, add SystemVerilog source code, trigger compilation, and check for any errors or warnings. The `slang` library is primarily a compiler and analysis tool."},"warnings":[{"fix":"Always use `import slang` or `from slang import ...` instead of `import pyslang`.","message":"The PyPI package `pyslang` provides its functionality under the Python module name `slang`. Importing `pyslang` directly will result in a `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the `pyslang` (and underlying `slang` C++ library) release notes for changes related to LRM compliance. Update your SystemVerilog source code to adhere to the latest LRM specifications or downgrade `pyslang` if necessary for legacy code.","message":"Major versions (e.g., v7.0, v9.0, v10.0) frequently introduce stricter compliance with the SystemVerilog Language Reference Manual (LRM). Code that previously compiled silently might now generate errors or warnings due to enhanced LRM enforcement or new static analysis checks.","severity":"breaking","affected_versions":"v7.0 (IEEE 1800-2023), v9.0 (dataflow analysis), v10.0 (assertion locals definite assignment), and subsequent major releases."},{"fix":"After calling `library.getCompilation()`, always retrieve and iterate through `compilation.getDiagnostics()` to properly handle any issues. Explicitly print or log these diagnostics.","message":"Compilation errors and warnings are not raised as Python exceptions but are returned as a list of `Diagnostic` objects via `compilation.getDiagnostics()`. Failing to check this list means you might unknowingly have an invalid design.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the official GitHub repository's release notes for `pyslang` and the `slang` C++ library before upgrading major versions, especially if using advanced features beyond basic compilation.","message":"The underlying `slang` C++ library is actively developed, and while core APIs like `Library()` and `addSourceText()` are stable, more advanced features or introspection APIs might see changes between major `pyslang` versions.","severity":"breaking","affected_versions":"All major version upgrades (e.g., v8.x to v9.x, v9.x to v10.x)"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change your import statement from `import pyslang` to `import slang`.","cause":"You are attempting to import the library using its PyPI package name (`pyslang`) instead of its internal module name (`slang`).","error":"ModuleNotFoundError: No module named 'pyslang'"},{"fix":"Review the release notes for your `pyslang` version (and the underlying `slang` C++ library) to understand specific LRM changes. Modify your SystemVerilog source code to comply with the latest standard.","cause":"`pyslang` has updated its compliance with the SystemVerilog LRM (Language Reference Manual), introducing stricter checks or new interpretations of the standard.","error":"SystemVerilog code that compiled in a previous pyslang version now produces errors or new warnings after upgrading."},{"fix":"First, obtain the `Compilation` object using `compilation = library.getCompilation()`. Then, access methods related to the compiled design (e.g., getting diagnostics or the root symbol) on the `compilation` object.","cause":"You are trying to access methods or properties of the compiled design directly on the `Library` object. The `Library` object manages source files, while the `Compilation` object (returned by `getCompilation()`) holds the elaborated design.","error":"AttributeError: 'Library' object has no attribute 'some_method_for_compiled_design'"},{"fix":"After `compilation = library.getCompilation()`, you *must* check `diagnostics = compilation.getDiagnostics()` and iterate through the `diagnostics` list to print any errors or warnings found during compilation.","cause":"You are not explicitly checking the diagnostics list returned by the compilation process. `pyslang` does not raise Python exceptions for SystemVerilog errors by default.","error":"My SystemVerilog code has syntax errors, but my Python script completes without any visible output or exceptions."}]}