nwdiag

raw JSON →
3.0.0 verified Fri May 01 auth: no python

A simple text-to-image diagram generator for network diagrams, part of the blockdiag suite. Current version 3.0.0 supports Python >=3.7. Maintained irregularly.

pip install nwdiag
error ImportError: cannot import name 'nwdiag' from 'nwdiag'
cause Trying to import the submodule as 'from nwdiag import nwdiag' instead of 'import nwdiag'.
fix
Use 'import nwdiag' and then call nwdiag.command() or other functions.
error AttributeError: module 'nwdiag' has no attribute 'command'
cause Installed a different package named nwdiag (e.g., from a third-party) or used an older version where the API was different.
fix
Uninstall any conflicting package and install the official nwdiag: pip install --upgrade nwdiag
error Parse error: syntax error, unexpected 'network'
cause Missing semicolon after closing brace of a network block, or incorrect nesting of networks.
fix
Check that every block ends with a semicolon. Example: 'network dmz { ... };' not 'network dmz { ... }'
gotcha nwdiag command line tool uses a different syntax than the Python API. The Python API expects a list of arguments similar to sys.argv, not the string directly.
fix Use nwdiag.command(['-o', 'out.png', '-']) with stdin pipe, or nwdiag.command(['-o', 'out.png', 'diag.diag'])
deprecated The blockdiag suite is no longer actively maintained; issues and PRs may go unanswered.
fix Consider alternatives like diagrams (https://github.com/mingrammer/diagrams) for active development.
gotcha The .diag file format uses semicolons at the end of definitions; missing semicolons cause parse errors with unhelpful messages.
fix Ensure every bracket block ends with a semicolon, e.g., 'network name { ... };'

Generates a network diagram from a DOT-like text description.

import nwdiag

# Create a simple network diagram
nwdiag.command(['-o', 'output.png', '-']).stdout.write("""
nwdiag {
  network dmz {
    address = "192.168.1.0/24"

    web01 [address = "192.168.1.1"];
    web02 [address = "192.168.1.2"];
  }
  network internal {
    address = "10.0.0.0/8";

    db01 [address = "10.0.0.1"];
    db02 [address = "10.0.0.2"];
  }
}
""")