2

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 Answers4

0

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.

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • Thank you. I agree with your comment that there is much more support in browser. Thank you also for heads up about Brython, since I haven't heard about it before. I will use these in future. – user3902003 Oct 19 '17 at 23:01
0

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

Bryan Zeng
  • 101
  • 2
  • 16
0

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

-1

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

Chris Johnson
  • 20,650
  • 6
  • 81
  • 80
  • Thank you. I checked the link you sent. Still I couldn't find any python library to deal with all SVG structural data (including transformations). So I am thinking of writing library of my own to deal with all these cases using some functionalities from existing libraries. I hope it won't be a duplicate. – user3902003 Oct 07 '17 at 21:49