A svgwrite python module is a tool by Manfred Moitzi.
To install this python module uses Python 3.4 version.
Then you need to install svgwrite with pip3.4:
1 2 3 4 | C:\Python34\Scripts>pip3.4.exe install svgwrite Collecting svgwrite Downloading svgwrite-1.1.6.tar.gz (109kB) 100% |################################| 110kB 354kB/s |
This svgwrite is the only module that needs to be imported and then you can deal with this module.
See this simple example:
1 2 3 4 5 6 7 8 9 10 11 12 | import svgwrite from svgwrite import * #this will work with svgwrite svg_doc = svgwrite.Drawing(filename = "test-svgwrite.svg",\ size = ("30px", "30px"))\ svg_doc.add(svg_doc.rect(insert = (0, 0),\ size = ("20px", "20px"),\ stroke_width = "1",\ stroke = "green",\ fill = "rgb(255,255,0)"))\ print(svg_doc.tostring()) svg_doc.save() |
The result of this python script is this SVG file.
If you use the dir() then you can see more about this python module:
1 2 3 4 5 6 7 8 | >>> dir(svgwrite) ['AUTHOR_EMAIL', 'AUTHOR_NAME', 'CYEAR', 'Drawing', 'Hz', 'Unit', 'VERSION', '__ builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__p ackage__', '__path__', '__spec__', 'animate', 'base', 'cm', 'container', 'data', 'deg', 'drawing', 'elementfactory', 'em', 'etree', 'ex', 'filters', 'grad', 'gr adients', 'image', 'inch', 'kHz', 'masking', 'mixins', 'mm', 'params', 'path', ' pattern', 'pc', 'percent', 'pt', 'px', 'rad', 'rgb', 'shapes', 'text', 'utils', 'validator2', 'version'] |
For example you can add some text:
1 2 | svg_doc.add(svg_document.text("This add new svg text",\ insert = (10, 10))) |
This tutorial can also be found at this website: python-catalin.blogspot.ro