Skip to main content

svg_writer

The most straightforward way to create SVG files with Python.

Three functions only:

from svg_writer import new_svg_root, write_svg, write_png_from_svg

new_svg_root

x: float,
y: float,
width: float,
height: float,
pad: float = 0
-> etree.Element

Create an svg root element from viewBox style arguments and provide the necessary svg-specific attributes. This is your window onto the scene. The arguments are the same you'd use to create a rect element (plus pad):

  • x: x value in upper-left corner
  • y: y value in upper-left corner
  • width: width of viewBox
  • height: height of viewBox
  • pad: The one small convenience I've provided. Optionally increase viewBox by pad in all directions.

write_svg

filename: str,
xml: etree.Element,
stylesheet: Optional[str] = None,
do_link_css: bool = True,
-> None:

Write an xml element as an svg file. This will link or inline your css code and insert the necessary declaration, doctype, and processing instructions.

  • filename: path to output file (include extension .svg)
  • param xml: root node of your svg geometry (created by new_svg_root)
  • stylesheet: optional path to a css stylesheet
  • do_link_css: link to stylesheet, else write contents of stylesheet into svg (ignored if stylesheet is None)

write_png_from_svg

inkscape_exe: PathType,
svg: str
-> Path

Convert an svg file to a png. Python does not have a library for this. That has an upside, as any library would be one more set of svg implementation idiosyncrasies we'd have to deal with. Inkscape will convert the file. This function provides the necessary command-line arguments.

  • inkscape_exe: path to inkscape.exe
  • svg: path to svg file
  • return: png filename

Full Documentation and Tutorial

Metadata

Release files for svg-writer 0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for svg-writer 0.5
File Size Uploaded
svg_writer-0.5.tar.gz 3.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for svg-writer 0.5
File Interpreter ABI Platform
svg_writer-0.5-py3-none-any.whl Python 3 none any Details

Total release size: 8.0 kB

Release files / svg_writer-0.5.tar.gz

Download URL svg_writer-0.5.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8e1b10254a50950fb03abcd985e49009c5e2bbd1a291028b456fd13309ab9cdf
BLAKE2b-256 checksum
How to use checksums
88eed9e85bb84e6a2838c47b4e9e1ad54c5fc1607feba67f1a134d32b62c0ce6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / svg_writer-0.5-py3-none-any.whl

Download URL svg_writer-0.5-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c17d4886f0be10673c8ff1fa6fc16c39c36b7f74d30098d45212f423073d8f5
BLAKE2b-256 checksum
How to use checksums
e09296d2dfbab9be500d4ce6de7d6d79f6ba077a65f788d6569b4ffc0e7d8e61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.5 This release

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page