Metadata-Version: 2.4
Name: pysvgwriter
Version: 2.24.0
Summary: SVG 1.1 as Python objects: draw, transform, combine, render and convert vector graphics.
Author: Josue N Rivera
License-Expression: MIT
Project-URL: Homepage, https://github.com/wzjoriv/svgwriter
Project-URL: Repository, https://github.com/wzjoriv/svgwriter
Project-URL: Documentation, https://wzjoriv.github.io/svgwriter
Project-URL: Bug Tracker, https://github.com/wzjoriv/svgwriter/issues
Keywords: svg,vector,graphics,drawing,animation
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Multimedia :: Graphics :: Editors :: Vector-Based
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: skia-python>=87
Requires-Dist: numpy>=1.24
Requires-Dist: uharfbuzz>=0.40
Requires-Dist: tomlkit>=0.12
Requires-Dist: click>=8.1
Requires-Dist: python-lcms2>=0.4.5
Provides-Extra: office
Requires-Dist: python-pptx>=1.0; extra == "office"
Requires-Dist: python-docx>=1.1; extra == "office"
Requires-Dist: openpyxl>=3.1; extra == "office"
Requires-Dist: pillow>=10; extra == "office"
Requires-Dist: latex2mathml>=3.75; extra == "office"
Provides-Extra: plot
Requires-Dist: matplotlib>=3.7; extra == "plot"
Requires-Dist: ziaplot>=0.9; extra == "plot"
Provides-Extra: graph
Requires-Dist: networkx>=3.0; extra == "graph"
Requires-Dist: python-igraph>=0.11; extra == "graph"
Requires-Dist: rustworkx>=0.15; extra == "graph"
Provides-Extra: geo
Requires-Dist: shapely>=2.0; extra == "geo"
Provides-Extra: math
Requires-Dist: ziamath>=0.11; extra == "math"
Provides-Extra: fonts
Requires-Dist: fonttools>=4.40; extra == "fonts"
Requires-Dist: brotli>=1.0; extra == "fonts"
Provides-Extra: widget
Requires-Dist: ipywidgets>=8; extra == "widget"
Provides-Extra: cli
Requires-Dist: questionary>=2.0; extra == "cli"
Provides-Extra: notebook
Requires-Dist: nbformat>=5; extra == "notebook"
Requires-Dist: nbclient>=0.7; extra == "notebook"
Requires-Dist: ipykernel>=6; extra == "notebook"
Provides-Extra: test
Requires-Dist: pysvgwriter[cli,geo,graph,math,office,plot,widget]; extra == "test"
Requires-Dist: pytest>=7; extra == "test"
Requires-Dist: ezdxf>=1.0; extra == "test"
Requires-Dist: pillow>=10; extra == "test"
Requires-Dist: fonttools>=4.40; extra == "test"
Provides-Extra: dev
Requires-Dist: pysvgwriter[docs,notebook,test]; extra == "dev"
Requires-Dist: stubpy>=1.5.2; extra == "dev"
Requires-Dist: typer>=0.12; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: pytest-xdist; extra == "dev"
Requires-Dist: ruff>=0.6; extra == "dev"
Requires-Dist: pyright>=1.1.400; extra == "dev"
Requires-Dist: tomli; python_version < "3.11" and extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx>=7.0; extra == "docs"
Requires-Dist: furo>=2024.1.29; extra == "docs"
Requires-Dist: myst-parser>=2.0; extra == "docs"
Requires-Dist: sphinx-copybutton>=0.5; extra == "docs"
Dynamic: license-file

# svgwriter

[![Tests](https://github.com/wzjoriv/svgwriter/actions/workflows/ci.yml/badge.svg)](https://github.com/wzjoriv/svgwriter/actions/workflows/ci.yml)
[![Docs](https://github.com/wzjoriv/svgwriter/actions/workflows/docs.yml/badge.svg)](https://wzjoriv.github.io/svgwriter)
[![PyPI](https://img.shields.io/pypi/v/pysvgwriter)](https://pypi.org/project/pysvgwriter/)
[![Python](https://img.shields.io/pypi/pyversions/pysvgwriter)](https://pypi.org/project/pysvgwriter/)
[![CPython 3.10-3.15](https://img.shields.io/badge/CPython-3.10%E2%80%933.15-blue)](https://github.com/wzjoriv/svgwriter/actions/workflows/ci.yml)
[![Linux · Windows · macOS](https://img.shields.io/badge/OS-Linux%20%C2%B7%20Windows%20%C2%B7%20macOS-blue)](https://github.com/wzjoriv/svgwriter/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://github.com/wzjoriv/svgwriter/blob/main/LICENSE)

Build, edit and render vector graphics in Python with a complete SVG 1.1 object model. Shapes move,
rotate and scale through one transform; geometry has boolean operations and measurement; text, images
and colors are first-class (numpy-backed); documents render with skia and export to PNG, PDF, TikZ, DXF
and more.

## Quick start

`pip install pysvgwriter` (Python 3.10+; brings skia-python, numpy, uharfbuzz and tomlkit), then draw a badge:

```python
import svgwriter as svg

doc = svg.Document()                                    # sized to its content when saved or shown
doc.rect(0, 0, 160, 60, rx=12, fill=svg.LinearGradient.horizontal("gold", "tomato"))
doc.circle(30, 30, 18, fill=(1, 1, 1, 0.8))             # colors: names, CSS, or 0-1 tuples (alpha too)
doc += svg.paths.star(0, 0, 10, points=5, fill="navy").place(30, 30).rotate(15)
title = doc.text("svgwriter", x=104, y=35, font_size=15.3, text_anchor="middle")
title[3:].fill = "navy"                                  # style a character range

doc.save("badge.svg")                                    # also .png .pdf .pptx .tex ...
```

<img src="https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/readme.png" alt="The badge drawn by the code above" width="320">

## Geometry in one minute

SVG coordinates are an element's own geometry and are written exactly as given; everything after that
goes through the transform, so the output stays the SVG a person would write.

```python
import svgwriter as svg

c = svg.circle(50, 50, 10)          # writes cx="50" cy="50" r="10"
c.translate(20, 0).rotate(45)       # parent axes by default; local=True for the shape's own axes
print(c.cx, c.position)             # 50.0 (local geometry) and where its centre is now: (70, 50)
print(c.matrix)                         # shortest equivalent transform text

ring = svg.circle(0, 0, 40) - svg.circle(0, 0, 25)   # boolean difference, a <path>
print(round(ring.length, 1), ring.contains(0, 0))
```

`*` and `@` never bake coordinates: `el * 2` is a scaled copy, `el @ 30` a rotated copy and `M @ el` a
copy with matrix `M` applied. Baking is explicit: `el.to_path()` folds the transform into `d`.

## Demos

[`demos/`](https://github.com/wzjoriv/svgwriter/tree/main/demos) holds complete design projects, each an ordinary `svgwriter new` project that uses several features together; open one and run `svgwriter preview`, or open the notebook in its folder to see it step by step with pictures and live controls (see the [demos page](https://wzjoriv.github.io/svgwriter/dev/demos.html)).

| | | | | | |
|:---:|:---:|:---:|:---:|:---:|:---:|
| [![Animal card](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/demos/animal-card.png)](https://github.com/wzjoriv/svgwriter/blob/main/demos/animal-card/animal-card.ipynb)<br>[Animal card](https://github.com/wzjoriv/svgwriter/blob/main/demos/animal-card/animal-card.ipynb) | [![Keyboard kit](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/demos/keyboard-kit.png)](https://github.com/wzjoriv/svgwriter/blob/main/demos/keyboard-kit/keyboard-kit.ipynb)<br>[Keyboard kit](https://github.com/wzjoriv/svgwriter/blob/main/demos/keyboard-kit/keyboard-kit.ipynb) | [![Game title screen](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/demos/game-title-screen.gif)](https://github.com/wzjoriv/svgwriter/blob/main/demos/game-title-screen/game-title-screen.ipynb)<br>[Game title screen](https://github.com/wzjoriv/svgwriter/blob/main/demos/game-title-screen/game-title-screen.ipynb) | [![Solar System lesson](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/demos/solar-system-lesson.gif)](https://github.com/wzjoriv/svgwriter/blob/main/demos/solar-system-lesson/solar-system-lesson.ipynb)<br>[Solar System lesson](https://github.com/wzjoriv/svgwriter/blob/main/demos/solar-system-lesson/solar-system-lesson.ipynb) | [![Hero banner](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/demos/hero-banner.gif)](https://github.com/wzjoriv/svgwriter/blob/main/demos/hero-banner/hero-banner.ipynb)<br>[Hero banner](https://github.com/wzjoriv/svgwriter/blob/main/demos/hero-banner/hero-banner.ipynb) | [![Beach clean-up poster](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/demos/beach-cleanup-poster.png)](https://github.com/wzjoriv/svgwriter/blob/main/demos/beach-cleanup-poster/beach-cleanup-poster.ipynb)<br>[Beach clean-up poster](https://github.com/wzjoriv/svgwriter/blob/main/demos/beach-cleanup-poster/beach-cleanup-poster.ipynb) |

## Feature overview

| Area | What you get |
| --- | --- |
| Elements | Every static SVG 1.1 element as a class (`svg.Circle` / `svg.circle`), attributes by Python name (`el.stroke_width`) ([Documents](https://wzjoriv.github.io/svgwriter/guides/documents.html)) |
| Placement | One affine `el.matrix`; `translate`, `rotate`, `scale`, `place(x, y)`; edges as attributes (`a.top = b.bottom + 4`); `el * 2`, `el @ 30` ([Geometry](https://wzjoriv.github.io/svgwriter/guides/geometry.html)) |
| Booleans and paths | `a \| b`, `a & b`, `a - b`, `a ^ b` on shapes and text; fluent `svg.path()`, `roughen`, `dash`, `svg.paths.star()`, `length`, `contains` ([Paths](https://wzjoriv.github.io/svgwriter/guides/paths.html)) |
| Text | `text[i]` and `text[a:b]` move or style characters while staying real text; `text.glyphs()` for outlines; custom and icon fonts ([Text](https://wzjoriv.github.io/svgwriter/guides/text.html)) |
| Colors and images | 0-1 `Color` with alpha, OKLCH mixing, `Image(numpy_array)`, Porter-Duff `a \| b`, `a.composite(b, "screen")`, `svg.types` for typed values ([Colors and images](https://wzjoriv.github.io/svgwriter/guides/colors-and-images.html)) |
| Documents and layers | `doc["logo"]`, `doc.layers`, auto-size, `doc.add(fig)` for matplotlib, PIL or anything with `_repr_svg_`; `doc.to("pil")` out, `Document.from_object(x)` in ([Documents](https://wzjoriv.github.io/svgwriter/guides/documents.html#python-objects)) |
| Layout and units | `VStack`, `HStack` and `Grid` that size themselves, shadows counted by `visual_bbox`; real units: `Document(size="a4")`, `svg.mm` ([Layout](https://wzjoriv.github.io/svgwriter/guides/layout.html)) |
| Themes | `svg.Theme` palettes and role styles with `el.as_role("box")`; light, dark, sketch, paper and more built in; TOML theme files ([Themes](https://wzjoriv.github.io/svgwriter/guides/themes.html)) |
| Presets | `svg.patterns.hatch()`, `svg.gradients.sunset()`, `svg.markers.arrow()`, 44 filters (`el.filter = svg.filters.long_shadow()`, chain with `f >> g`) ([Presets](https://wzjoriv.github.io/svgwriter/guides/presets.html)) |
| Effects | `shape.effect("neon")`, `text[4:9].effect("fire")`: glass, sticker, neon, smoke and more; text stays text; animated for GIF and video ([Filters](https://wzjoriv.github.io/svgwriter/guides/filters.html)) |
| Animation | SMIL and `el.animate` presets, `svg.Scene` rendered to SVG, GIF or video, `svg.interpolate(a, b, t)` morphs ([Animation](https://wzjoriv.github.io/svgwriter/guides/animation.html)) |
| Widgets | `svg.explore(fn)` with sliders and toggles in a notebook, `svg.sweep(fn, hue=(0, 360))` bakes them into a GIF or MP4 ([Widgets](https://wzjoriv.github.io/svgwriter/guides/widgets.html)) |
| Formats | `doc.save("x.pdf")`, `Document.open("x.pptx")`: 30+ formats chosen by name or extension, with format detection ([Export](https://wzjoriv.github.io/svgwriter/guides/export.html)) |
| Extending | `svg.registry.<kind>` adds formats, filters, themes, effects and converters with a decorator, or from a package ([Extending](https://wzjoriv.github.io/svgwriter/guides/extending.html)) |
| Previews | Colors, themes, easings, filters and registries all display as pictures in a notebook ([Documents](https://wzjoriv.github.io/svgwriter/guides/documents.html#seeing-objects-in-notebooks)) |
| Projects | `svgwriter new my-poster --preset poster`, then `svgwriter build` and `svgwriter preview`; poster, slides, logo, icons, diagram and chart presets ([Projects](https://wzjoriv.github.io/svgwriter/guides/projects.html)) |

## Examples

[`examples/`](https://github.com/wzjoriv/svgwriter/tree/main/examples) is a 28-step learning path, from a first drawing to paths, paint, formats, animation, themes, PowerPoint, widgets and fonts; each step is a runnable script with a Jupyter notebook next to it that shows the results as pictures (see its [README](https://github.com/wzjoriv/svgwriter/blob/main/examples/README.md)).

| | | | |
|:---:|:---:|:---:|:---:|
| [![Shapes, gradients, text](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/basic_shapes.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/01_first_drawing/first_drawing.ipynb)<br>[Shapes, gradients, text](https://github.com/wzjoriv/svgwriter/blob/main/examples/01_first_drawing/first_drawing.ipynb) | [![Transforms](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/transforms.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/02_transforms/transforms.ipynb)<br>[Transforms](https://github.com/wzjoriv/svgwriter/blob/main/examples/02_transforms/transforms.ipynb) | [![Every built-in theme](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/themes.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/18_themes/themes.ipynb)<br>[Every built-in theme](https://github.com/wzjoriv/svgwriter/blob/main/examples/18_themes/themes.ipynb) | [![Paths and markers](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/paths_and_markers.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/04_paths/paths.ipynb)<br>[Paths and markers](https://github.com/wzjoriv/svgwriter/blob/main/examples/04_paths/paths.ipynb) |
| [![Boolean operations](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/boolean_ops.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/05_booleans/booleans.ipynb)<br>[Boolean operations](https://github.com/wzjoriv/svgwriter/blob/main/examples/05_booleans/booleans.ipynb) | [![Typography](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/typography.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/07_typography/typography.ipynb)<br>[Typography](https://github.com/wzjoriv/svgwriter/blob/main/examples/07_typography/typography.ipynb) | [![Fonts and icon fonts](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/fonts.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/26_fonts/fonts.ipynb)<br>[Fonts and icon fonts](https://github.com/wzjoriv/svgwriter/blob/main/examples/26_fonts/fonts.ipynb) | [![Gradients, patterns, masks, clips](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/paint.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/08_paint/paint.ipynb)<br>[Gradients, patterns, masks, clips](https://github.com/wzjoriv/svgwriter/blob/main/examples/08_paint/paint.ipynb) |
| [![All 44 filters](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/filter_gallery.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/24_presets/presets.ipynb)<br>[All 44 filters](https://github.com/wzjoriv/svgwriter/blob/main/examples/24_presets/presets.ipynb) | [![Effects that keep text as text](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/effect_looks.gif)](https://github.com/wzjoriv/svgwriter/blob/main/examples/25_effects/effects.ipynb)<br>[Effects that keep text as text](https://github.com/wzjoriv/svgwriter/blob/main/examples/25_effects/effects.ipynb) | [![Animation presets](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/animation.gif)](https://github.com/wzjoriv/svgwriter/blob/main/examples/15_animation/animation.ipynb)<br>[Animation presets](https://github.com/wzjoriv/svgwriter/blob/main/examples/15_animation/animation.ipynb) | [![Scenes](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/scenes.gif)](https://github.com/wzjoriv/svgwriter/blob/main/examples/16_scenes/scenes.ipynb)<br>[Scenes](https://github.com/wzjoriv/svgwriter/blob/main/examples/16_scenes/scenes.ipynb) |
| [![Layout that resizes itself](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/layout.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/22_layout/layout.ipynb)<br>[Layout that resizes itself](https://github.com/wzjoriv/svgwriter/blob/main/examples/22_layout/layout.ipynb) | [![LaTeX math](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/math.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/13_math_and_diagrams/math_and_diagrams.ipynb)<br>[LaTeX math](https://github.com/wzjoriv/svgwriter/blob/main/examples/13_math_and_diagrams/math_and_diagrams.ipynb) | [![PowerPoint with an editable equation](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/powerpoint.png)](https://github.com/wzjoriv/svgwriter/blob/main/examples/21_powerpoint/powerpoint.ipynb)<br>[PowerPoint with an editable equation](https://github.com/wzjoriv/svgwriter/blob/main/examples/21_powerpoint/powerpoint.ipynb) | [![Live widgets and sweeps](https://raw.githubusercontent.com/wzjoriv/svgwriter/main/docs/_static/examples/widgets.gif)](https://github.com/wzjoriv/svgwriter/blob/main/examples/23_widgets/widgets.ipynb)<br>[Live widgets and sweeps](https://github.com/wzjoriv/svgwriter/blob/main/examples/23_widgets/widgets.ipynb) |

## Formats

Formats are found by name or file extension: `doc.save("figure.pdf")`, `svg.Document.open("figure.pdf")`,
`doc.export("eps")` for bytes.

- **Both ways:** SVG, SVGZ, PNG, JPEG, WebP, BMP, GIF, APNG, ICO, ICNS, PDF, EPS, TikZ, DXF, HPGL, G-code, Excalidraw, GeoJSON, WKT, HTML, PowerPoint, Word and video frames.
- **Out only:** Excel.
- **In only:** Markdown, plain text, Graphviz DOT, Mermaid, PlantUML, D2 and LaTeX math (`svg.latex(...)`).

```python
doc.save("figure.pdf")                         # vector PDF
doc.save("figure.tex", standalone=True)        # TikZ picture
doc.save("icon.ico", sizes=(16, 32, 48), padding=4)
doc.save("sketch.excalidraw")                  # write one, then read it back
svg.Document.open("sketch.excalidraw").save("sketch.svg")
```

What each format keeps and its options are in the [Export and import guide](https://wzjoriv.github.io/svgwriter/guides/export.html). Office output needs `pip install "pysvgwriter[office]"`.

## Learn more

[Documentation](https://wzjoriv.github.io/svgwriter) · [Guides](https://wzjoriv.github.io/svgwriter/guides/documents.html) · [Contributing](https://wzjoriv.github.io/svgwriter/dev/contributing.html) · [MIT licence](https://github.com/wzjoriv/svgwriter/blob/main/LICENSE)
