blockdiag generates block-diagram images from simple text definitions. It is part of the diag suite of tools for various diagrams and is currently at version 3.0.0. Its release cadence is feature-driven, providing updates for new Python versions and enhancements.
pip install blockdiagVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically generate a block diagram. It parses a diagram definition string, then uses `generate_image` to create a PNG image into a BytesIO object, which is then saved to a file.
Upgrade your Python environment to 3.7+ and ensure all dependencies are compatible. For older Python 2 projects, stick to blockdiag 2.x.
Always ensure Pillow is installed alongside blockdiag: `pip install blockdiag Pillow`.
Explicitly specify a font using the `font` argument (programmatic) or `-f` option (CLI) with a path to a universally available font (e.g., DejaVu Sans). On Linux servers, install common font packages (e.g., `fonts-dejavu-core`).
Refer to the official documentation or quickstart examples for correct import paths, typically `from blockdiag.parser import parse_string` and `from blockdiag.command.blockdiag import generate_image`.
The `generate_image` function is located in `blockdiag.command.blockdiag`. Correct imports are `from blockdiag.parser import parse_string` and `from blockdiag.command.blockdiag import generate_image`.
Ensure `blockdiag` is installed in the active virtual environment (`pip install blockdiag`). If using a global install, make sure the Python user scripts directory (e.g., `~/.local/bin` on Linux) is included in your system's PATH.
Verify the font file exists and the path is correct and accessible to the process running blockdiag. For headless servers, ensure necessary font packages (e.g., `fonts-dejavu-core` on Debian/Ubuntu) are installed.
Install or upgrade Pillow to a compatible version: `pip install Pillow>=6.0.0`. If an old `PIL` (Python Imaging Library) is present, uninstall it first (`pip uninstall PIL`).