Processing SVG in Python

Viewed 1304

I am trying to use python and understand SVG drawings. I would like python to behave similar to java script and get information from SVG. I understand that there can be 2 types of information in SVG.

  1. XML based information - such as elementbyID, elementbyTagNames
  2. Structural information - positional information taking transformations in to consideration too - such as getelementfrompoint, getboundingbox

I have searched around and found python libraries such as lxml for xml processing in svg. Also I found libraries such as svgpathtools, svg.path , but as I understand, these deal only with svgpath elements.

So my question is,

  1. Are there any good libraries which support processing svg in python?(similar to java script)
4 Answers

I don't think this is feasible. I was directing you to an answer about rendering SVG with Python - but after that all you have got is pixels.

Extracting positional information from SVG data at arbitrary points between transformations is likely something only implemented in browsers themselves. You will likely have two options: use a headless browser and selenium/splinter to load your SVG data in a real browser and run javascript statements in there, OR make your Python code run in Brython, and run everything inside the browser. From Brython you should be able to use the Javascript calls as methods of the SVG object as it is exposed to Brython itself.

Try to use Pygal. It's used for creating interactive .svg pictures.

Thank you for all the answers and help.

After reading all comments and even more www search, I agree with the idea that there is much more support in Java script supported web browsers for dealing with SVG. So I decided to use JS and to use python only when there is no choice. I will however use python libraries such as(https://pypi.python.org/pypi/svgpathtools/1.0.1) I think. But as of now I handed over all the SVG feature finding to java script

Start your search by visiting www.pypi.org and search for "svg". Review what exists and see what suits your needs.

Related