CLI Reference Manual

Drawlib provides a unified Command Line Interface (drawlib) for compiling documentation, extracting standalone visual diagrams, managing cache assets, validating links, and inspecting built-in design systems.

cli_reference_1
The Nine Drawlib CLI Subcommands Organized by Workflow Stage
Source Code
from drawlib.canvas import save, setup
from drawlib.icons import phosphor
from drawlib.lines import line
from drawlib.shapes import rectangle
from drawlib.styles import Styles
from drawlib.text import text

setup(width=128, height=58)

# Top Row: Primary 4-Stage Authoring & Publishing Pipeline
stages = [
    (18.5, "1. init", "doc / site / slide", Styles.Neutral, Styles.DarkBold, Styles.Dark, phosphor.rocket_launch, Styles.PrimaryBold),
    (48.8, "2. show", "-g grid / -o export", Styles.PrimaryNeutral, Styles.DarkBold, Styles.Dark, phosphor.grid_four, Styles.PrimaryBold),
    (79.2, "3. build", "html / pdf / office", Styles.PrimaryFlat, Styles.WhiteBold, Styles.White, phosphor.hammer, Styles.WhiteBold),
    (109.5, "4. serve", "--check link audit", Styles.SecondaryNeutral, Styles.DarkBold, Styles.Dark, phosphor.eye, Styles.PrimaryBold),
]
for sx, title, sub, st, tst, sub_st, icon_fn, icon_st in stages:
    rectangle((sx, 42.5), width=26, height=22, style=st.patch(shape_r=2.0))
    icon_fn((sx, 48.2), width=4.8, style=icon_st)
    text((sx, 41.2), title, style=tst.patch(text_size=11.0))
    text((sx, 35.8), sub, style=sub_st.patch(text_size=10.0))

line((31.5, 42.5), (35.8, 42.5), arrow_head="->", style=Styles.DarkBold)
line((61.8, 42.5), (66.2, 42.5), arrow_head="->", style=Styles.DarkBold)
line((92.2, 42.5), (96.5, 42.5), arrow_head="->", style=Styles.DarkBold)

# Bottom Row: Supporting Design Systems, Cache & AI Rules Subcommands
rectangle((64, 14.5), width=117, height=22, style=Styles.MutedDashed.patch(shape_r=2.0))
text((64, 22.8), "Cross-Cutting Design, Asset Cache & AI Knowledge", style=Styles.DarkBold.patch(text_size=11.0))

bottom_cards = [
    (25.5, "colors | styles | css", "Design Palettes", Styles.Neutral, phosphor.palette),
    (64.0, "drawlib cache", "Assets & Browser", Styles.PrimaryNeutral, phosphor.database),
    (102.5, "drawlib rules", "92 AI Manuals", Styles.SecondaryNeutral, phosphor.book_open),
]
for bx, btitle, bsub, bst, bicon in bottom_cards:
    rectangle((bx, 11.8), width=35, height=11.5, style=bst.patch(shape_r=1.5))
    bicon((bx - 12.5, 11.8), width=4.4, style=Styles.PrimaryBold)
    text((bx + 2.5, 13.8), btitle, style=Styles.DarkBold.patch(text_size=10.2))
    text((bx + 2.5, 9.2), bsub, style=Styles.Dark.patch(text_size=10.0))

save()

1. Interactive CLI Workflow Tour

From project bootstrapping (init and rules) to sub-second coordinate grid previews (show -g), multi-format compilation (build), and pre-flight link and asset verification (serve --check and cache), all nine drawlib subcommands work together in one cohesive loop:

cli_reference_2
Drawlib CLI Daily Workflow Tour: Scaffolding & AI Rules, Single-Diagram Grid Preview, 7 Build Targets, and Link Audit & Design Inspectors (APNG Animation)

2. Quick Command Matrix

# Compilation
drawlib build html docs_src/ -o docs_html/                  # Responsive static HTML website
drawlib build markdown docs_src/ -o docs/                  # GitHub-ready Markdown
drawlib build pdf doc_src/ -o manual.pdf --toc              # High-fidelity vector PDF
drawlib build docx doc_src/ -o manual.docx --generate-index # Editable MS Word (.docx) document
drawlib build slide slide_src/ -o slide_html/               # Interactive 16:9 HTML slide deck
drawlib build pptx slide_src/ -o deck.pptx                  # Editable 16:9 MS PowerPoint (.pptx) deck
drawlib build image scripts/ -o assets/ -g                  # Batch Python image rendering

# Scaffolding
drawlib init list                                          # List starter project templates (site, doc, slide, images)
drawlib init doc my_doc                                    # Scaffold linear document project (HTML, PDF, DOCX, MD, images)
drawlib init site my_site                                  # Scaffold documentation site
drawlib init slide my_deck -s google                       # Scaffold 16:9 presentation slide deck
drawlib init images my_images                              # Scaffold standalone images project (alias: image)

# Inspection & Preview
drawlib show doc.md                                        # List all drawlib code blocks in doc.md
drawlib show doc.md arch.png -o .drawlib/scratch/arch.png          # Headless extraction by explicit filename (Recommended)
drawlib show doc.md arch.png -g -o .drawlib/scratch/arch_grid.png  # Export named block with coordinate grid
drawlib show script.py -o .drawlib/scratch/fig.png                 # Export standalone Python script

# Local Server & Verification
drawlib serve docs_html/                                   # Local preview on http://localhost:8000
drawlib serve docs_html/ --check                           # Pre-flight broken link/asset audit

# Design Systems, Cache & AI Rules
drawlib colors list                                        # List color catalogs (default, google, monochrome, css)
drawlib styles list                                        # List style catalogs (default, google, monochrome)
drawlib css list                                           # List CSS presets for HTML and PDF
drawlib cache list                                         # Inspect cached fonts, icons, and maps
drawlib cache download --all                               # Pre-download fonts, icons, maps, and headless Chromium
drawlib rules list                                         # List 92 AI rule instruction manuals

3. Global CLI Options

Global flags apply before any top-level command (drawlib [GLOBAL_OPTIONS] COMMAND ...):

Flag Description
-v, --version Print installed drawlib version and exit with status 0.
-h, --help Show contextual help message and available subcommands.
--quiet Suppress non-critical standard output (emit warnings and errors only).
--verbose / --debug Enable diagnostic logging, timing metrics, and cache hit/miss details.
--developer Enable verbose logging and disable user-friendly error wrapping so full Python stack traces propagate.

(Note: --quiet cannot be combined with --verbose, --debug, or --developer; doing so exits with code 2.)


4. Compilation Subsystem (drawlib build)

cli_reference_3
Interactive Single-Diagram Preview (drawlib show) vs. Full Project Compilation (drawlib build)
Source Code
from drawlib.canvas import save, setup
from drawlib.icons import phosphor
from drawlib.shapes import rectangle
from drawlib.smartarts import ChevronProcess
from drawlib.styles import Styles
from drawlib.text import text

setup(width=126, height=58)

# Top Panel: Fast Interactive Loop (drawlib show)
rectangle((63, 42.5), width=118, height=23, style=Styles.MutedDashed.patch(shape_r=2.0))
phosphor.grid_four((13, 50.2), width=4.4, style=Styles.PrimaryBold)
text(
    (66, 50.2),
    "Fast Interactive Loop: drawlib show (Single-Diagram Preview)",
    style=Styles.DarkBold.patch(text_size=11.0),
)

show_flow = ChevronProcess(
    style=Styles.Neutral,
    text_style=Styles.DarkBold.patch(text_size=10.5),
    description_style=Styles.Dark.patch(text_size=10.0),
    corner_angle=60.0,
    spacing=1.8,
    flat_left_end=True,
)
show_flow.add("1. Source", description="doc.md / .py")
show_flow.add(
    "2. drawlib show",
    description="-g -o preview.png",
    style=Styles.PrimaryFlat,
    text_style=Styles.WhiteBold.patch(text_size=10.5),
    description_style=Styles.White.patch(text_size=10.0),
)
show_flow.add("3. Grid Review", description="Inspect Coords", style=Styles.PrimaryNeutral)
show_flow.draw(xy=(8, 33.0), width=110, height=13.5)

# Bottom Panel: Full Project Compilation (drawlib build)
rectangle((63, 15.0), width=118, height=23, style=Styles.MutedDashed.patch(shape_r=2.0))
phosphor.hammer((13, 22.8), width=4.4, style=Styles.PrimaryBold)
text(
    (66, 22.8),
    "Full Project Compilation: drawlib build (Multi-Target Output)",
    style=Styles.DarkBold.patch(text_size=11.0),
)

build_flow = ChevronProcess(
    style=Styles.Neutral,
    text_style=Styles.DarkBold.patch(text_size=10.5),
    description_style=Styles.Dark.patch(text_size=10.0),
    corner_angle=60.0,
    spacing=1.8,
    flat_left_end=True,
)
build_flow.add("1. Project + Cache", description="docs_src/ & cache.db")
build_flow.add(
    "2. drawlib build",
    description="html | pdf | docx | pptx",
    style=Styles.SecondaryNeutral,
)
build_flow.add("3. Deliverables", description="Web, PDF & Office", style=Styles.PrimaryNeutral)
build_flow.draw(xy=(8, 5.5), width=110, height=13.5)

save()

4.1 drawlib build html

Compiles Markdown documents or directories into a responsive static HTML documentation website (site when navbar.md is present) or merged single-page HTML document (doc when navbar.md is absent).

drawlib build html <INPUT> [OPTIONS]
Option Shorthand Default Description
--output -o <input_dir> or <name>.html Destination directory or HTML file path.
--format -f png Image format for embedded diagrams (png or webp).
--styles -s Auto-resolved styles.py Path to project styles script.
--utils -u Auto-resolved utils.py Path to helper drawing script.
--no-cache False Force clean diagram rendering, ignoring .drawlib/cache.db.

4.2 drawlib build markdown

Compiles source Markdown containing embedded drawlib blocks into standard GitHub-Flavored Markdown. Rendered diagrams are exported to companion image folders (<doc>_images/).

drawlib build markdown docs_src/ -o docs/ [OPTIONS]
  • Supports -o/--output, -f/--format <png|webp>, -s/--styles, -u/--utils, and --no-cache.
  • Overwrite Protection: Refuses to overwrite source files in-place (src_abs == dest_abs). Always compile to a distinct output directory (e.g. docs/ or docs_markdown/).

4.3 drawlib build pdf

Merges Markdown chapters, single Markdown files, or 16:9 slide decks into a high-fidelity vector PDF using headless Chromium via Playwright (chromium-headless-shell is automatically installed on first run, or pre-downloaded via drawlib cache download --browser).

drawlib build pdf doc_src/ -o report.pdf --toc --page-break
Option Shorthand Default Description
--output -o <base>_<lang>.pdf Destination PDF file path (emits <base>_<lang>.pdf per locale for doc / slide directories).
--title Extracted from H1 Overall document title displayed on cover and running headers.
--generate-index --toc False Insert an automated Table of Contents between the 1st (00_cover.md) and 2nd chapter.
--page-break / --no-page-break True Insert CSS page breaks (page-break-before: always) between chapters.
--styles / --utils -s / -u Auto-resolved Path to styles.py and utils.py.
--no-cache False Bypass .drawlib/cache.db and re-render all diagrams.
--timestamp False Include current build timestamp in PDF metadata (omitted by default for deterministic builds).

4.4 drawlib build docx

Compiles a directory of Markdown chapters (doc project) or a single .md file into a native editable MS Word (.docx) document (headings, prose, bullet/numbered lists, tables, blockquotes, syntax-highlighted code blocks, optional cover page, and Table of Contents), rendering drawlib blocks (including SVG, WebP, and animated blocks) as crisp high-DPI static PNGs.

drawlib build docx doc_src/ -o report.docx --generate-index --page-break
Option Shorthand Default Description
--output -o <base>_<lang>.docx Output MS Word (.docx) file path (emits <base>_<lang>.docx per locale for doc directories).
--page-break / --no-page-break True Insert page breaks between merged chapters.
--generate-index / --no-generate-index False Generate an index (Table of Contents) and insert it between the 1st (00_cover.md) and 2nd documents.
--title Extracted from H1 Document title override for the merged Word document.
--dpi 200 Rasterization DPI for embedded drawlib diagrams.
--styles / --utils -s / -u Auto-resolved Path to styles.py and utils.py.
--no-cache False Disable reading and writing .drawlib/cache.db.
--timestamp False Include current build timestamp in Word metadata instead of normalizing it.

4.5 drawlib build slide

Compiles a directory of Markdown slide files (slide_src/) into standalone 16:9 HTML presentation decks (<lang>/index.html + root index.html redirect) with dual-window Presenter View (?presenter=1).

drawlib build slide slide_src/ -o slide_html/ [OPTIONS]
Option Shorthand Default Description
--output -o <dir>_html/ Output directory path for the presentation deck.
--theme -t Auto / default CSS theme preset (google, default, google-dark, default-dark).
--format -f svg Default image format for embedded diagrams (svg, webp, or png).
--styles / --utils -s / -u Auto-resolved Path to styles.py and utils.py.
--no-cache False Disable reading and writing .drawlib/cache.db.

4.6 drawlib build pptx

Compiles a directory of Markdown slide files (slide_src/) into native editable 16:9 (960×540 pt) MS PowerPoint (.pptx) decks per locale by measuring the 1920×1080 slide layout and computed CSS styles via headless Chromium (::: block cards with rgba alpha, text boxes, bullet/numbered lists, tables, inline code, and ::: note speaker notes), embedding drawlib diagrams as high-DPI static PNGs.

drawlib build pptx slide_src/ -o deck.pptx --dpi 240 --anim-frame last
Option Shorthand Default Description
--output -o <base>_<lang>.pptx Output MS PowerPoint (.pptx) file path (emits <base>_<lang>.pptx per locale).
--theme -t Auto / default CSS theme preset (google, default, google-dark, default-dark).
--title Extracted from deck Presentation title override for PowerPoint metadata.
--dpi 240 Rasterization DPI for embedded drawlib diagrams.
--anim-frame last Frame (first or last) extracted from animated diagrams.
--styles / --utils -s / -u Auto-resolved Path to styles.py and utils.py.
--no-cache False Disable reading and writing .drawlib/cache.db.
--timestamp False Include current build timestamp in PowerPoint metadata instead of normalizing it.

4.7 drawlib build image

Batch executes standalone Python illustration scripts (.py) or extracts embedded drawing blocks from Markdown files (.md) to generate image assets.

drawlib build image images_src/ -o images/ --grid
Option Shorthand Default Description
--output, --output-dir -o None Output file path (single script) or destination directory.
--format -f Script setting (png) Global output image format override (png, webp, jpg, pdf).
--styles / --utils -s / -u Auto-resolved Path to styles.py and utils.py.
--grid -g False Save companion *_grid.<ext> images overlaid with coordinate grids.
--disable-auto-clear False Disable automatic canvas.clear() between executed .py files.
--enable-auto-initialize False Enable full canvas re-initialization between executed .py files.
--no-cache False Bypass .drawlib/cache.db.
  • Python Scripts: Redirects save() outputs into -o, mirroring nested subdirectory structures automatically. Performs pre-execution static AST analysis across all scripts and aborts immediately if two scripts would write to the same output file.
  • Markdown Files: Extracts embedded drawlib blocks into <markdown_name>_images/<image_file> subdirectories.

5. Scaffolding Subsystem (drawlib init)

Bootstraps new projects with standardized folder structures, configuration scripts, and build automations:

drawlib init <TYPE> [target] [OPTIONS]
drawlib init list
  • <TYPE>: Subcommand choosing project type: doc, site, slide (all initialized with unified <src_dir>/<lang>/ locale directories and [i18n] in drawlib.toml), images (alias: image), or list.
  • [target]: Base name for the project and source folder (creates <target>_src/). Defaults: doc for doc, docs for site, slide for slide, images for images.
  • -s, --style <theme>: Style preset theme (default, google, monochrome, etc.) synchronously configuring both style.css and styles.py.
  • -l, --lang <code>: Starter content and font configuration language (en, ja, zh-cn, ko, th, hi, etc.; supports comma-separated multi-locale codes such as -l en,ja on doc, site, and slide). Default: en.
  • -f, --force: Overwrite existing files if destination directory already exists.

6. Single Diagram Extraction & Preview (drawlib show)

Lists embedded blocks in a document, previews a diagram in a desktop GUI window, or exports it headlessly to disk when -o is supplied:

# 1. List all drawlib blocks in a Markdown document (when [TARGET] is omitted):
drawlib show docs_src/en/overview.md

# 2. Export block by explicit filename with coordinate grid (Recommended):
drawlib show docs_src/en/overview.md arch.png -g -o .drawlib/scratch/arch_grid.png

# 3. Export block by 1-based index (or -1 for the last block in the file):
drawlib show docs_src/en/overview.md 1 -g -o .drawlib/scratch/fig1.png
drawlib show docs_src/en/overview.md -1 -o .drawlib/scratch/last_fig.png

# 4. Preview standalone Python script in interactive GUI window:
drawlib show my_drawing.py

Supports -o/--output, -g/--grid, -s/--styles, -u/--utils, and --no-cache.


7. Local Server & Pre-Flight Link Checking (drawlib serve)

Starts a zero-dependency local HTTP development server (Cache-Control: no-store) to preview built HTML documentation:

# Start server on default port 8000 (runs link check first and opens browser):
drawlib serve docs_html/

# Custom port without opening browser:
drawlib serve docs_html/ -p 8080 --no-browser

# Pre-flight broken link and missing asset check only (exits 0 if clean, 1 if broken):
drawlib serve docs_html/ --check

# Start server immediately without running pre-flight link scan:
drawlib serve docs_html/ --skip-check

8. Design Systems, Stylesheets & Asset Cache (css, colors, styles, cache)

8.1 CSS Stylesheet Presets (drawlib css)

drawlib css list [html|pdf]                            # List built-in CSS themes and target support
drawlib css show html google                           # Print synthesized Google HTML CSS to terminal
drawlib css show html google -o docs_src/style.css --force  # Export preset to file

8.2 Color & Style Visual Catalogs (drawlib colors & drawlib styles)

# Color palettes (default, google, monochrome, css):
drawlib colors list
drawlib colors show google --sort hsv -g -o .drawlib/scratch/colors_google.png

# Style matrices (default, google, monochrome):
drawlib styles list
drawlib styles show google 1 -o .drawlib/scratch/styles_google_p1.png
drawlib styles show default --all -o .drawlib/scratch/styles_default.png
drawlib styles show default -c blue -o .drawlib/scratch/styles_blue.png

8.3 Cache Management (drawlib cache)

drawlib cache list                  # Inspect font, icon, and map packages and local cache size
drawlib cache download --all        # Pre-download all font, icon, map, and headless Chromium assets
drawlib cache download --fonts      # Pre-download font packages only
drawlib cache download --icons      # Pre-download icon packages only
drawlib cache download --maps       # Pre-download GeoMap packages only
drawlib cache download --browser    # Pre-download headless Chromium browser only
drawlib cache clear --images        # Clear SQLite build & CLI image cache (.drawlib/cache.db)
drawlib cache clear --all           # Clear all caches (fonts, icons, maps, and .drawlib/cache.db)

9. AI Rules Catalog (drawlib rules)

Inspect built-in architectural and library manuals (with on-demand companion illustration rendering into _cached_assets/rules/) from the terminal:

drawlib rules list                            # List all 92 rule topics and cache status
drawlib rules show agent-instruction          # View AI agent bootstrap manual
drawlib rules show overview                   # View Cartesian geometry principles
drawlib rules show style-guide                # View 50%+ neutral baseline & semantic color rules
drawlib rules show review-guide               # View 3-stage multimodal review loop & 720pt font math
drawlib rules show anim-guide                 # View animation idioms across all modules
drawlib rules show project-overview           # View 4 project archetypes & shared architecture
drawlib rules show project-site               # View multi-page website authoring & navbar.md rules
drawlib rules show project-slide              # View 1920x1080 slide authoring & stage rules
drawlib rules show lib-graph-overview         # View declarative graph layout solvers overview
drawlib rules show lib-diagrams-overview --raw # Output raw Markdown without building/checking cache
drawlib rules show lib-shapes-overview --rebuild # Force regenerate companion rule illustrations
drawlib rules build --all                     # Pre-build illustrations for all 92 rule topics
drawlib rules clear                           # Delete cached rule documents and generated images

10. CLI Exit Codes

Exit Code Meaning Common Causes
0 Success Command completed normally (--check passed with 0 broken links).
1 Build / Execution Error Missing mandatory files (index.md, navbar.md), Python exception in a drawlib block, duplicate output collision, or broken links detected by drawlib serve --check.
2 Bad Parameter / Usage Error Conflicting CLI flags (e.g. --quiet with --verbose), unknown subcommand, or missing required argument.