Extending
Add output formats, layout engines and themes from your own package.
spinagram is built from plug-ins registered through Python entry points, so a separate package can add an output format, a layout engine or a theme.
Backends
A backend is a class with name and render(scenes, out_dir) -> list[Path], registered through the
spinagram.backends entry point:
[project.entry-points."spinagram.backends"]
html = "my_package.backend:HtmlBackend"Backends only read the resolved Scene, in which every colour is hex, fonts are resolved, text is
pre-wrapped and coordinates are absolute. Adding an output format never touches layout or themes.
Layout engines
An engine is a class with name, available() and run(LGraph) -> LResult (see
spinagram.autolayout.graph), registered through the spinagram.layouts entry point:
[project.entry-points."spinagram.layouts"]
mine = "my_package.layout:MyEngine"Themes
A theme package registers its theme directory through the spinagram.themes entry point, as the package itself
(its directory holds theme.yaml) or as module:ATTR, where ATTR is the directory's path. --theme acme and
extends: acme then find it by name. See Themes by name.
[project.entry-points."spinagram.themes"]
acme = "acme_theme"Python API
import spinagram
diagrams = spinagram.load("specs/") # YAML and Python specs
spinagram.render(diagrams, "out/", theme="my-theme", formats=["svg", "pptx"], gallery=True)
scenes = spinagram.scenes(diagrams, theme="my-theme") # resolved scenes, for custom tooling
spinagram.render(diagrams, "out/", backend_options={"svg": {"fonts": "link"}}) # options per backendbackend_options maps a format to the keyword arguments of its backend; the SVG and PNG backends take
fonts="subset" | "embed" | "link" (SVG fonts).