Drawlib Package Overview
Drawlib is a pure-Python library for Illustration as Code and Illustrated Documentation as Code, exposing 20 lazy-loaded top-level submodules (PEP 562) under import drawlib alongside dedicated drawlib.charts and drawlib.diagrams subpackages. Import domain symbols directly via from drawlib.<module> import ... or access package metadata from drawlib.
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 Colors, Styles
from drawlib.text import text
setup(width=120, height=58, dpi=150)
# Outer package frame
rectangle((60, 29), width=112, height=50, style=Styles.MutedDashed.patch(shape_r=2.5))
phosphor.package((38.0, 48.5), width=4.4, style=Styles.DarkBold)
text(
(63.5, 48.5),
"Drawlib Package Architecture (v0.3.5)",
style=Styles.DarkBold.patch(text_size=12.5),
)
# 1. Core Primitives & Styling
rectangle((23.5, 24), width=31, height=34, style=Styles.Neutral.patch(shape_r=2.0))
phosphor.shapes((12.5, 35.5), width=4.2, style=Styles.DarkBold)
text((25.5, 35.5), "Core Primitives", style=Styles.DarkBold.patch(text_size=11.0))
text(
(23.5, 21.5),
"canvas / shapes\nlines / text / images\nmath / styles / fonts",
style=Styles.Dark.patch(text_size=10.0, text_line_spacing=1.35),
)
line((39.0, 24), (44.0, 24), arrow_head="->", style=Styles.DarkBold)
# 2. High-Level Components (Focal Hero)
rectangle((60, 24), width=32, height=34, style=Styles.PrimaryFlat.patch(shape_r=2.0))
phosphor.graph((48.5, 35.5), width=4.2, style=Styles.WhiteBold)
text((62.0, 35.5), "High-Level API", style=Styles.WhiteBold.patch(text_size=11.5))
text(
(60, 21.5),
"smartarts / charts\ndiagrams / graph\nicons (34 suites)",
style=Styles.White.patch(text_size=10.0, text_color=Colors.White, text_line_spacing=1.35),
)
line((76.0, 24), (81.0, 24), arrow_head="->", style=Styles.DarkBold)
# 3. Docs, Animation & CLI
rectangle((96.5, 24), width=31, height=34, style=Styles.SecondaryNeutral.patch(shape_r=2.0))
phosphor.terminal_window((86.0, 35.5), width=4.2, style=Styles.DarkBold)
text((98.5, 35.5), "Docs & CLI", style=Styles.DarkBold.patch(text_size=11.0))
text(
(96.5, 21.5),
"anim / slide / tools\ndrawlib build & show\nHTML / PDF / PPTX",
style=Styles.Dark.patch(text_size=10.0, text_line_spacing=1.35),
)
save()
Package & Subpackage Re-exports (__all__)#
Drawlib uses lazy module loading (PEP 562) so import drawlib incurs minimal startup overhead while keeping all public submodules discoverable via dir() and static type checkers:
| Package Namespace | Re-exported Submodules (__all__) |
|---|---|
drawlib |
anim, canvas, charts, diagrams, fonts, graph, icons, images, lines, math, preset_colors, preset_styles, shapes, slide, smartarts, styles, text, tools, types, utils |
drawlib.charts |
area, bar, gantt, heatmap, line, pie, radar, scatter (plus shared type DrawDirection) |
drawlib.diagrams |
architecture, class_diagram, er, flow, sequence, state |
Complete API & CLI Reference Directory (29 Pages)#
| Page | Module / Scope | Primary Contents |
|---|---|---|
| 00. Drawlib Package Overview | drawlib, drawlib.utils, drawlib.charts, drawlib.diagrams |
Package constants, lazy submodule index, drawlib.utils, DrawDirection |
| 01. drawlib.canvas | drawlib.canvas |
Cartesian (0, 0) canvas lifecycle (setup, save, clear, show, get_dimage, canvas) |
| 02. drawlib.shapes | drawlib.shapes |
43 geometric, arrow, 3D container, badge, and symbol primitives |
| 03. drawlib.lines & drawlib.text | drawlib.lines, drawlib.text |
Straight, curved, Bézier, arc, and filleted lines; horizontal & vertical text |
| 04. drawlib.images & drawlib.math | drawlib.images, drawlib.math |
image(), immutable Dimage filters, subprocess get_dimage_from_code(), 2D geometry math |
| 05. drawlib.styles & drawlib.types | drawlib.styles, drawlib.types |
Active Styles / Colors proxies, immutable Style & Color models, type aliases |
| 06. drawlib.preset_styles & preset_colors | drawlib.preset_styles, drawlib.preset_colors |
DefaultStyles, GoogleStyles, MonochromeStyles, CssColors, palette presets |
| 07. drawlib.fonts | drawlib.fonts |
Standardized cross-platform font families (Font, CJK/global scripts, FontFile) |
| 08. drawlib.icons | drawlib.icons |
34 vector icon suites (phosphor, gcp, aws, azure, domain & flat suites) |
| 09. drawlib.smartarts (Lists, Cards & Tables) | drawlib.smartarts |
Table, BoxList, CardList, KpiCards, BulletPoints, Panel, SourceCode, GridLayout |
| 10. drawlib.smartarts (Flows, Trees & Maps) | drawlib.smartarts |
ChevronProcess, Cycle, Pyramid, Roadmap, TreeNode, MindMapNode, GeoMap, *Calendar |
| 11. drawlib.charts.bar | drawlib.charts.bar |
Grouped, stacked, horizontal, and annotated BarChart |
| 12. drawlib.charts.line | drawlib.charts.line |
Multi-series LineChart with markers, thresholds, and smooth interpolation |
| 13. drawlib.charts.area | drawlib.charts.area |
Stacked and overlapping AreaChart |
| 14. drawlib.charts.pie | drawlib.charts.pie |
Proportional PieChart and donut ring charts |
| 15. drawlib.charts.radar | drawlib.charts.radar |
Multi-axis spider / polygon RadarChart |
| 16. drawlib.charts.scatter | drawlib.charts.scatter |
2D correlation ScatterChart and variable-radius bubble plots |
| 17. drawlib.charts.gantt | drawlib.charts.gantt |
Project timeline, milestone, and dependency GanttChart |
| 18. drawlib.charts.heatmap | drawlib.charts.heatmap |
Matrix HeatmapChart and spatial HeatmapOverlay |
| 19. drawlib.diagrams.architecture | drawlib.diagrams.architecture |
Cloud & microservice ArchitectureDiagram, groups, nodes, and orthogonal edges |
| 20. drawlib.diagrams.flow | drawlib.diagrams.flow |
Algorithmic FlowDiagram, swimlanes, decisions, and process nodes |
| 21. drawlib.diagrams.sequence | drawlib.diagrams.sequence |
API SequenceDiagram, lifelines, activations, fragments, and notes |
| 22. drawlib.diagrams.class_diagram | drawlib.diagrams.class_diagram |
OOP UML ClassDiagram, attributes, methods, and inheritance/composition links |
| 23. drawlib.diagrams.er | drawlib.diagrams.er |
Database ERDiagram, entity tables, keys, and Crow's Foot cardinalities |
| 24. drawlib.diagrams.state | drawlib.diagrams.state |
Lifecycle StateDiagram, composite states, forks/joins, and transitions |
| 25. drawlib.graph | drawlib.graph |
5 deterministic auto-layout coordinate solvers (get_layout()) |
| 26. drawlib.anim & drawlib.slide | drawlib.anim, drawlib.slide |
Multi-frame WebP Animation builder and 16:9 SlideDeck / .pptx engine |
| 27. drawlib.tools | drawlib.tools |
Programmatic project builders, cache management, server, and agent rule APIs |
| 28. CLI Reference (drawlib) | drawlib._cli |
Command-line interface (init, build, show, serve, cache, rules) |
const__version__#
Standard PEP 396 package version string exposed at drawlib.__version__ (aliased to LIB_VERSION).
from drawlib import __version__
__version__: Final[str] = "0.3.5"
| Attribute | Type | Value | Description |
|---|---|---|---|
__version__ |
Final[str] |
'0.3.5' |
Installed Drawlib semantic version string. |
constLIB_NAME#
Canonical distribution and package identifier constant exposed at drawlib.LIB_NAME.
from drawlib import LIB_NAME
LIB_NAME: Final[str] = "drawlib"
| Attribute | Type | Value | Description |
|---|---|---|---|
LIB_NAME |
Final[str] |
'drawlib' |
Canonical library name used in metadata, caching, and CLI reporting. |
constLIB_VERSION#
Canonical semantic version constant exposed at drawlib.LIB_VERSION.
from drawlib import LIB_VERSION
LIB_VERSION: Final[str] = "0.3.5"
| Attribute | Type | Value | Description |
|---|---|---|---|
LIB_VERSION |
Final[str] |
'0.3.5' |
Semantic version string matching drawlib.__version__. |
typedrawlib.utils#
Dynamic user helper module (import drawlib.utils or from drawlib import utils) automatically populated at build/render time with all top-level functions, classes, and constants defined in your project's utils.py file (or the file passed via drawlib show -u <path> / drawlib build).
# In project utils.py:
# def service_card(xy: tuple[float, float], title: str) -> None: ...
from drawlib import utils
utils.service_card((60, 30), "API Gateway")
| Behavior / Property | Type | Description |
|---|---|---|
drawlib.utils.<name> |
Any |
Resolves any top-level helper function, class, or constant loaded from utils.py. |
| Missing attribute access | AttributeError |
Raises a descriptive AttributeError instructing how to define the symbol in utils.py or pass --utils. |
typedrawlib.charts.DrawDirection#
Shared literal type alias exported from drawlib.charts specifying progressive reveal or orientation direction across chart components (such as BarChart, LineChart, and AreaChart).
from typing import Literal
from drawlib.charts import DrawDirection
DrawDirection = Literal["bottom_to_top", "left_to_right"]
| Allowed Literal | Description |
|---|---|
'bottom_to_top' |
Grows or orientations chart elements vertically from bottom (y0) toward top. |
'left_to_right' |
Grows or orientations chart elements horizontally from left (x0) toward right. |