Command line¶
svgwriter (also python -m svgwriter) is a click group that runs these commands; svgwriter COMMAND --help lists the
options of each. Errors are one line on stderr; the exit status is 0 on success, 1 when a command
fails (no scene, ffmpeg missing) and 2 for a usage error, an unreadable file or an invalid project.
Command |
What it does |
|---|---|
|
Create a project folder from a preset; in a terminal, what the flags leave out is asked with arrow keys ( |
|
Write the project’s outputs (all of |
|
Serve a live page that redraws as controls move and files change |
|
List project presets |
|
List named canvas sizes ( |
|
List shape presets and element classes |
|
Write a shape preset as SVG |
|
Parse an SVG file and write it back out |
|
Count the elements of an SVG file |
|
Render scenes through ffmpeg |
|
Rasterize scenes or an SVG file to PNG |
|
Write text as glyph outlines |
|
Show what works on this machine, what is missing and how to install it on this OS |
svgwriter doctor¶
svgwriter doctor checks the optional libraries (skia, harfbuzz, lcms2, fontTools, ipywidgets,
matplotlib, …) and external programs (ffmpeg, LaTeX with dvisvgm, the Mermaid CLI, Graphviz, PlantUML,
D2, Inkscape), and prints one line for each: its version when present, otherwise what it is for and the
command that installs it on this OS and Linux distribution (apt, dnf, pacman, zypper, brew or
winget). The last line counts the installed font families and names what sans-serif, serif,
monospace and emoji resolve to; on Linux with few fonts or no emoji font it adds the distribution’s
font packages.
$ svgwriter doctor
svgwriter 2.4.0 on Python 3.13.3, Windows 11 (windows, winget)
ok skia 144.1
ok harfbuzz 0.57.0
...
-- graphviz missing (Graphviz DOT diagrams): winget install Graphviz.Graphviz
fonts: 326 families; sans-serif -> Arial, serif -> Times New Roman, monospace -> Consolas, emoji -> Segoe UI Emoji
--json prints the same report as JSON (python, system, system_packages, capabilities,
fonts). From Python, svg.capabilities() returns the capability part as a read-only mapping of name
to a record with available, version, path, purpose and hint; it is checked once and cached
(svg.capabilities(refresh=True) checks again).
Each program can also be named by an environment variable, SVGWRITER_<NAME> (SVGWRITER_FFMPEG,
SVGWRITER_DOT, SVGWRITER_MMDC, SVGWRITER_LATEX, SVGWRITER_DVISVGM, …), which wins over PATH.
Packages add commands through the svgwriter.command entry-point group, and commands.register(command)
adds one at run time (see Extending svgwriter).
- app[source]¶
a
click.Group;app.add_command(command)adds a command.- Type:
The
svgwriterapplication
- main(argv: Sequence[str] | None = None) int[source]¶
Run the command line.
- Parameters:
argv (sequence of str, optional) – Arguments without the program name. Defaults to
sys.argv[1:].- Returns:
int – The exit status: 0 on success, 1 when a command fails, 2 for a usage error or a file that cannot be read or written; errors are one line on stderr, without a traceback.
Examples
>>> from svgwriter.tools.cli import main >>> main(["draw", "star", "--size", "50", "--compact"]) <?xml ...?> <svg ...</svg>0
- capabilities(refresh: bool = False) Capabilities[source]¶
What this machine can do: optional libraries and external programs, with how to add each.
The checks run on first call and are cached; programs are asked for their version once.
- Parameters:
refresh (bool, optional) – Check again (after installing something). Defaults to False.
- Returns:
Capabilities – A read-only mapping of name to
Capability(available,version,path,purposeand the installhintfor this OS).
See also
svgwriter.tools.cli.appsvgwriter doctorprints the same report.
Examples
>>> import svgwriter as svg >>> found = svg.capabilities() >>> found["harfbuzz"].kind 'python' >>> # found["ffmpeg"].hint -> e.g. 'winget install Gyan.FFmpeg'
- commands: Final[Registry[Command]]¶
commands.register(command), or thesvgwriter.commandentry points.Examples
>>> import click >>> from svgwriter.tools.cli import commands, main >>> @commands.register ... @click.command(help="Say hello.") ... def hello() -> None: ... click.echo("hello") >>> main(["hello"]) hello 0 >>> _ = commands.unregister("hello")
- Type:
Commands beside the built-in ones